| 1: | <?php |
| 2: | namespace TIC\TownBundle\Command; |
| 3: | |
| 4: | use Symfony\Component\Console\Command\Command; |
| 5: | use Symfony\Component\Console\Input\InputInterface; |
| 6: | use Symfony\Component\Console\Input\InputArgument; |
| 7: | use Symfony\Component\Console\Input\InputOption; |
| 8: | use Symfony\Component\Console\Output\OutputInterface; |
| 9: | |
| 10: | use TIC\TownBundle\Service\ImportManager; |
| 11: | |
| 12: | class ImportCommand extends Command |
| 13: | { |
| 14: | |
| 15: | |
| 16: | private $manager; |
| 17: | |
| 18: | public function __construct(ImportManager $importManager) |
| 19: | { |
| 20: | parent::__construct(); |
| 21: | $this->manager = $importManager; |
| 22: | } |
| 23: | |
| 24: | |
| 25: | protected function configure(): void |
| 26: | { |
| 27: | $this |
| 28: | ->setName('tic:town:import') |
| 29: | ->setDescription("Load data from files into database tables...") |
| 30: | ->addArgument('entity', InputArgument::OPTIONAL, "type of data [region|departement|commune] (default: all).") |
| 31: | ->addArgument('departements', InputArgument::OPTIONAL, "load only for these departements.") |
| 32: | ->addOption('test', '-t', InputOption::VALUE_NONE, "test only.") |
| 33: | ; |
| 34: | } |
| 35: | |
| 36: | |
| 37: | protected function execute(InputInterface $input, OutputInterface $output): int |
| 38: | { |
| 39: | $entityType = $input->getArgument('entity'); |
| 40: | |
| 41: | |
| 42: | $departements = $input->getArgument('departements'); |
| 43: | |
| 44: | $dpts = preg_split("/[,]+/", $departements, NULL, PREG_SPLIT_NO_EMPTY); |
| 45: | |
| 46: | if ($entityType === null || $entityType == 'region') { |
| 47: | $this->manager->loadInseeR(__DIR__ . '/../../data/cog2021_region.csv.gz', $input->getOption('test')); |
| 48: | $this->manager->loadInseeComerR(__DIR__ . '/../../data/cog2023_comer.csv.gz', $input->getOption('test')); |
| 49: | } |
| 50: | if ($entityType === null || $entityType == 'departement') { |
| 51: | $this->manager->loadInseeD(__DIR__ . '/../../data/cog2021_departement.csv.gz', $input->getOption('test')); |
| 52: | $this->manager->loadInseeComerD(__DIR__ . '/../../data/cog2023_comer.csv.gz', $input->getOption('test')); |
| 53: | } |
| 54: | if ($entityType === null || $entityType == 'commune') { |
| 55: | $this->manager->loadPosteC(__DIR__ . '/../../data/laposte2021_codespostaux.csv.gz', $dpts, $input->getOption('test')); |
| 56: | $this->manager->loadInseeC(__DIR__ . '/../../data/cog2021_commune.csv.gz', $dpts, $input->getOption('test')); |
| 57: | $this->manager->loadInseeComerC(__DIR__ . '/../../data/cog2023_commune_comer.csv.gz', $dpts, $input->getOption('test')); |
| 58: | } |
| 59: | |
| 60: | |
| 61: | |
| 62: | return Command::SUCCESS; |
| 63: | } |
| 64: | |
| 65: | } |
| 66: | |