Source of file ImportCommand.php
Size: 2,539 Bytes - Last Modified: 2023-11-16T22:56:03+01:00
/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/town-bundle/src/Command/ImportCommand.php
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | <?phpnamespace TIC\TownBundle\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use TIC\TownBundle\Service\ImportManager; class ImportCommand extends Command {# protected static $defaultName = 'tic:town:import';private $manager; public function __construct(ImportManager $importManager) { parent::__construct(); $this->manager = $importManager; } protected function configure(): void { $this ->setName('tic:town:import') ->setDescription("Load data from files into database tables...") ->addArgument('entity', InputArgument::OPTIONAL, "type of data [region|departement|commune] (default: all).") ->addArgument('departements', InputArgument::OPTIONAL, "load only for these departements.") ->addOption('test', '-t', InputOption::VALUE_NONE, "test only.") ; } protected function execute(InputInterface $input, OutputInterface $output): int { $entityType = $input->getArgument('entity'); // liste des départements à traiter convertie en tableau $departements = $input->getArgument('departements'); # $dpts = explode(",", $departements);$dpts = preg_split("/[,]+/", $departements, NULL, PREG_SPLIT_NO_EMPTY); if ($entityType === null || $entityType == 'region') { $this->manager->loadInseeR(__DIR__ . '/../../data/cog2021_region.csv.gz', $input->getOption('test')); $this->manager->loadInseeComerR(__DIR__ . '/../../data/cog2023_comer.csv.gz', $input->getOption('test')); } if ($entityType === null || $entityType == 'departement') { $this->manager->loadInseeD(__DIR__ . '/../../data/cog2021_departement.csv.gz', $input->getOption('test')); $this->manager->loadInseeComerD(__DIR__ . '/../../data/cog2023_comer.csv.gz', $input->getOption('test')); } if ($entityType === null || $entityType == 'commune') { $this->manager->loadPosteC(__DIR__ . '/../../data/laposte2021_codespostaux.csv.gz', $dpts, $input->getOption('test')); $this->manager->loadInseeC(__DIR__ . '/../../data/cog2021_commune.csv.gz', $dpts, $input->getOption('test')); $this->manager->loadInseeComerC(__DIR__ . '/../../data/cog2023_commune_comer.csv.gz', $dpts, $input->getOption('test')); } # return Command::INVALID; // = 2 (Sf 5.3)# return Command::FAILURE; // = 1 (Sf 5.1)return Command::SUCCESS; // = 0 (Sf 5.1) } } |