setName(self::COMMAND_NAME) ->addOption('--id', '-i', InputOption::VALUE_OPTIONAL, 'Specific ID to import. Defaults to next in the queue.', false) ->addOption('--limit', '-l', InputOption::VALUE_OPTIONAL, 'Maximum number of records to import for this script execution.', 0) ->setHelp( <<<'EOT' The %command.name% command starts to import CSV files when some are created. php %command.full_name% EOT ); } protected function execute(InputInterface $input, OutputInterface $output): int { $start = microtime(true); $progress = new Progress($output); $id = (int) $input->getOption('id'); $limit = (int) $input->getOption('limit'); $this->processSignalService->registerSignalHandler(fn (int $signal) => $output->writeln(sprintf('Signal %d caught.', $signal))); if ($id) { $import = $this->importModel->getEntity($id); // This specific import was not found if (!$import) { $output->writeln(''.$this->translator->trans('mautic.core.error.notfound', [], 'flashes').''); return Command::FAILURE; } } else { $import = $this->importModel->getImportToProcess(); // No import waiting in the queue. Finish silently. if (null === $import) { return Command::SUCCESS; } } $this->userTokenSetter->setUser($import->getCreatedBy()); $output->writeln(''.$this->translator->trans( 'mautic.lead.import.is.starting', [ '%id%' => $import->getId(), '%lines%' => $import->getLineCount(), ] ).''); try { $this->importModel->beginImport($import, $progress, $limit); } catch (ImportFailedException) { $output->writeln(''.$this->translator->trans( 'mautic.lead.import.failed', [ '%reason%' => $import->getStatusInfo(), ] ).''); return Command::FAILURE; } catch (ImportDelayedException) { $output->writeln(''.$this->translator->trans( 'mautic.lead.import.delayed', [ '%reason%' => $import->getStatusInfo(), ] ).''); return Command::FAILURE; } // Success $output->writeln(''.$this->translator->trans( 'mautic.lead.import.result', [ '%lines%' => $import->getProcessedRows(), '%created%' => $import->getInsertedCount(), '%updated%' => $import->getUpdatedCount(), '%ignored%' => $import->getIgnoredCount(), '%time%' => round(microtime(true) - $start, 2), ] ).''); return Command::SUCCESS; } protected static $defaultDescription = 'Imports data to Mautic'; }