1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Loevgaard\SyliusBarcodePlugin\Command; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
8
|
|
|
use Loevgaard\SyliusBarcodePlugin\Message\Command\ProcessBatch; |
9
|
|
|
use Setono\DoctrineORMBatcher\Batch\RangeBatchInterface; |
10
|
|
|
use Setono\DoctrineORMBatcher\Factory\BatcherFactory; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
15
|
|
|
|
16
|
|
|
class CheckBarcodesCommand extends Command |
17
|
|
|
{ |
18
|
|
|
/** @var EntityManagerInterface */ |
19
|
|
|
private $productVariantManager; |
20
|
|
|
|
21
|
|
|
/** @var MessageBusInterface */ |
22
|
|
|
private $commandBus; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $productVariantClass; |
26
|
|
|
|
27
|
|
|
public function __construct( |
28
|
|
|
EntityManagerInterface $productVariantManager, |
29
|
|
|
MessageBusInterface $commandBus, |
30
|
|
|
string $productVariantClass |
31
|
|
|
) { |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->productVariantManager = $productVariantManager; |
35
|
|
|
$this->commandBus = $commandBus; |
36
|
|
|
$this->productVariantClass = $productVariantClass; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function configure(): void |
40
|
|
|
{ |
41
|
|
|
$this |
42
|
|
|
->setName('loevgaard:barcode:check') |
43
|
|
|
->setDescription('Checks barcodes on products') |
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
48
|
|
|
{ |
49
|
|
|
$qb = $this->productVariantManager->createQueryBuilder(); |
50
|
|
|
$qb->select('o') |
51
|
|
|
->from($this->productVariantClass, 'o') |
52
|
|
|
->andWhere('o.barcodeChecked is null') |
53
|
|
|
; |
54
|
|
|
|
55
|
|
|
$factory = new BatcherFactory(); |
56
|
|
|
$bestChoiceIdBatcher = $factory->createBestIdRangeBatcher($qb); |
57
|
|
|
|
58
|
|
|
/** @var RangeBatchInterface[] $batches */ |
59
|
|
|
$batches = $bestChoiceIdBatcher->getBatches(50); |
60
|
|
|
foreach ($batches as $batch) { |
61
|
|
|
$this->commandBus->dispatch(new ProcessBatch($batch)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return 0; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|