| Conditions | 4 |
| Paths | 4 |
| Total Lines | 31 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 24 | { |
||
| 25 | if (!$this->lock($this->getName())) { |
||
| 26 | $output->writeln('The command is already running in another process.'); |
||
| 27 | |||
| 28 | return 0; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** @var EntityManager $em */ |
||
| 32 | $em = $this->getContainer()->get('doctrine')->getManager(); |
||
| 33 | |||
| 34 | $pakkelabels = $this->getContainer()->get('loevgaard_pakkelabels.client'); |
||
| 35 | |||
| 36 | $labels = $em->getRepository('LoevgaardPakkelabelsBundle:Label')->findBy([ |
||
| 37 | 'status' => Label::STATUS_PENDING_CREATION |
||
| 38 | ], null, 20); |
||
| 39 | |||
| 40 | foreach ($labels as $label) { |
||
| 41 | $res = $pakkelabels->doRequest('post', '/shipments', [ |
||
| 42 | 'json' => $label->arrayForApi() |
||
| 43 | ]); |
||
| 44 | |||
| 45 | if(isset($res['error'])) { |
||
| 46 | $label->markAsError($res['error']); |
||
| 47 | } else { |
||
| 48 | $label->markAsSuccess(); |
||
| 49 | } |
||
| 50 | |||
| 51 | $em->flush(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 |