1 | <?php |
||
12 | use Symfony\Component\Console\Output\OutputInterface; |
||
13 | |||
14 | class GenerateLabelsCommand extends ContainerAwareCommand |
||
15 | { |
||
16 | use LockableTrait; |
||
17 | |||
18 | protected function configure() |
||
25 | |||
26 | protected function execute(InputInterface $input, OutputInterface $output) |
||
27 | { |
||
28 | if (!$this->lock($this->getName())) { |
||
29 | $output->writeln('The command is already running in another process.'); |
||
30 | |||
31 | return 0; |
||
32 | } |
||
33 | |||
34 | $limit = (int)$input->getOption('limit'); |
||
35 | Assert::that($limit)->integer()->greaterThan(0); |
||
36 | |||
37 | /** @var ObjectManager $manager */ |
||
38 | $manager = $this->getContainer()->get('doctrine')->getManager(); |
||
39 | |||
40 | $pakkelabels = $this->getContainer()->get('loevgaard_pakkelabels.client'); |
||
41 | |||
42 | /** @var Label[] $labels */ |
||
43 | $labels = $manager->getRepository('LoevgaardPakkelabelsBundle:Label')->findBy([ |
||
44 | 'status' => Label::STATUS_PENDING_CREATION |
||
45 | ], null, $limit); |
||
46 | |||
47 | if($output->isVerbose()) { |
||
48 | $output->writeln('Label count: '.count($labels)); |
||
49 | } |
||
50 | |||
51 | foreach ($labels as $label) { |
||
52 | $output->writeln('Creating label id: '.$label->getId().' with order id: '.$label->getOrderId(), OutputInterface::VERBOSITY_VERBOSE); |
||
53 | |||
54 | try { |
||
55 | $res = $pakkelabels->doRequest('post', '/shipments', [ |
||
56 | 'json' => $label->arrayForApi() |
||
90 |