|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the DataImporter package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Loïc Sapone <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace IQ2i\DataImporter\Bundle\Command; |
|
15
|
|
|
|
|
16
|
|
|
use IQ2i\DataImporter\Archiver\ArchiverInterface; |
|
17
|
|
|
use IQ2i\DataImporter\Bundle\Exception\ItemHandlingException; |
|
18
|
|
|
use IQ2i\DataImporter\Bundle\Processor\AsyncCliProcessor; |
|
19
|
|
|
use IQ2i\DataImporter\Bundle\Processor\CliProcessor; |
|
20
|
|
|
use IQ2i\DataImporter\DataImporter; |
|
21
|
|
|
use IQ2i\DataImporter\Exchange\Message; |
|
22
|
|
|
use IQ2i\DataImporter\Processor\ProcessorInterface; |
|
23
|
|
|
use IQ2i\DataImporter\Reader\ReaderInterface; |
|
24
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
25
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
26
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
27
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
28
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
29
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
30
|
|
|
use Symfony\Component\Serializer\Serializer; |
|
31
|
|
|
|
|
32
|
|
|
abstract class AbstractImportCommand extends Command |
|
33
|
|
|
{ |
|
34
|
|
|
protected InputInterface $input; |
|
35
|
|
|
|
|
36
|
|
|
protected OutputInterface $output; |
|
37
|
|
|
|
|
38
|
|
|
abstract protected function handleItem(): callable; |
|
39
|
|
|
|
|
40
|
|
|
abstract protected function getReader(?string $filename = null): ReaderInterface; |
|
41
|
|
|
|
|
42
|
2 |
|
protected function configure(): void |
|
43
|
|
|
{ |
|
44
|
2 |
|
$this |
|
45
|
2 |
|
->addArgument('filename', InputArgument::OPTIONAL, 'File to import') |
|
46
|
2 |
|
->addOption('async', null, InputOption::VALUE_NONE, 'Parallelize row process using symfony/messenger') |
|
47
|
2 |
|
->addOption('step', null, InputOption::VALUE_NONE, 'Step through each record one-by-one') |
|
48
|
2 |
|
->addOption('pause-on-error', null, InputOption::VALUE_NONE, 'Pause if an exception is thrown') |
|
49
|
2 |
|
->addOption('batch-size', null, InputOption::VALUE_REQUIRED, 'Batch size', 100) |
|
50
|
2 |
|
; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
54
|
|
|
{ |
|
55
|
2 |
|
$this->input = $input; |
|
56
|
2 |
|
$this->output = $output; |
|
57
|
|
|
|
|
58
|
2 |
|
$io = new SymfonyStyle($input, $output); |
|
59
|
2 |
|
$io->title('Start importing data'); |
|
60
|
|
|
|
|
61
|
|
|
try { |
|
62
|
2 |
|
(new DataImporter( |
|
63
|
2 |
|
$this->getReader($input->getArgument('filename')), |
|
64
|
2 |
|
$this->getProcessor($input, $output), |
|
65
|
2 |
|
$this->getArchiver(), |
|
|
|
|
|
|
66
|
2 |
|
$this->getSerializer() |
|
|
|
|
|
|
67
|
2 |
|
))->execute(); |
|
68
|
|
|
} catch (ItemHandlingException $itemHandlingException) { |
|
69
|
|
|
$io->newLine(2); |
|
70
|
|
|
$io->error($itemHandlingException->getMessage()); |
|
71
|
|
|
|
|
72
|
|
|
return $itemHandlingException->getCode(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
return Command::SUCCESS; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
2 |
|
protected function handleBegin(): callable |
|
79
|
|
|
{ |
|
80
|
2 |
|
return static function (Message $message) { |
|
|
|
|
|
|
81
|
2 |
|
}; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
protected function handleBatch(): callable |
|
85
|
|
|
{ |
|
86
|
2 |
|
return static function (Message $message) { |
|
|
|
|
|
|
87
|
2 |
|
}; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
2 |
|
protected function handleEnd(): callable |
|
91
|
|
|
{ |
|
92
|
2 |
|
return static function (Message $message, array $errors) { |
|
|
|
|
|
|
93
|
2 |
|
}; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
2 |
|
protected function getProcessor(InputInterface $input, OutputInterface $output): ProcessorInterface |
|
97
|
|
|
{ |
|
98
|
2 |
|
return $input->getOption('async') |
|
99
|
|
|
? new AsyncCliProcessor($input, $output, $this->handleBegin(), $this->handleItem(), $this->handleBatch(), $this->handleEnd(), $this->getSerializer()) |
|
|
|
|
|
|
100
|
2 |
|
: new CliProcessor($input, $output, $this->handleBegin(), $this->handleItem(), $this->handleBatch(), $this->handleEnd(), $this->getSerializer()); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
2 |
|
protected function getArchiver(): ?ArchiverInterface |
|
104
|
|
|
{ |
|
105
|
2 |
|
return null; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
2 |
|
protected function getSerializer(): ?Serializer |
|
109
|
|
|
{ |
|
110
|
2 |
|
return null; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths