src/App/EventListener/Custom/Labas/PostListener.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\EventListener\Custom\Labas;
  3. use App\Entity\Central\Client\Client;
  4. use App\Entity\Client\PointOfSale\PointOfSaleMove;
  5. use App\Entity\Client\Store\StoreHeader;
  6. use App\EventListener\GenericEvent;
  7. use App\Model\ShellExec;
  8. use App\Service\ShellExecManager;
  9. use App\Utils\ClientUtils;
  10. use Eshop\Entity\Customer\CustomerOrder;
  11. class PostListener
  12. {
  13.     private ShellExecManager $shellExecManager;
  14.     public function __construct(ShellExecManager $shellExecManager)
  15.     {
  16.         $this->shellExecManager $shellExecManager;
  17.     }
  18.     public function postStoreHeaderCreate(GenericEvent $genericEvent)
  19.     {
  20.         /** @var StoreHeader $entity */
  21.         $entity $genericEvent->getSubject();
  22.         $this->isClient($genericEvent->getAppManager()->getClient());
  23.         if (!$entity instanceof StoreHeader || $entity->getType() !== StoreHeader::STORE_HEADER_CUSTOMER_RECEIPT) {
  24.             return;
  25.         }
  26.         $this->runCommand('export_paragon'$entity->getId());
  27.     }
  28.     public function postPointOfSaleMoveCreate(GenericEvent $genericEvent)
  29.     {
  30.         /** @var PointOfSaleMove $entity */
  31.         $entity $genericEvent->getSubject();
  32.         $this->isClient($genericEvent->getAppManager()->getClient());
  33.         if (!$entity instanceof PointOfSaleMove) {
  34.             return;
  35.         }
  36.         $this->runCommand('export_point_of_sale_move'$entity->getId());
  37.     }
  38.     public function postEshopCustomerOrder(GenericEvent $genericEvent)
  39.     {
  40.         /** @var CustomerOrder $entity */
  41.         $entity $genericEvent->getSubject();
  42.         $this->isClient($genericEvent->getAppManager()->getClient());
  43.         if (!$entity instanceof CustomerOrder) {
  44.             return;
  45.         }
  46.         if ($entity->getState() !== CustomerOrder::STATE_CONFIRMED || $entity->getFinishedAt() === null) {
  47.             return;
  48.         }
  49.         $this->runCommand('export_eshop_order'$entity->getId());
  50.         $this->runCommand('eshop:email_customer_order'$entity->getId());
  51.     }
  52.     private function isClient($client)
  53.     {
  54.         if (!$client instanceof Client || $client->getCode() !== ClientUtils::LABAS) {
  55.             throw new \Exception('Bad client');
  56.         }
  57.     }
  58.     private function runCommand(string $labasCommandint $entityIdbool $onBackground true)
  59.     {
  60.         $shellExec = new ShellExec('labas:' $labasCommand$entityId ' --kernel=labas');
  61.         $this->shellExecManager->runShellExec($shellExec$onBackground);
  62.     }
  63. }