custom/plugins/CrswCleverReachOfficial/src/Components/StateTransition/QueueItemFinishedListener.php line 30

Open in your IDE?
  1. <?php
  2. namespace Crsw\CleverReachOfficial\Components\StateTransition;
  3. use Crsw\CleverReachOfficial\Components\Entities\StateTransitionRecord;
  4. use Crsw\CleverReachOfficial\Core\BusinessLogic\InitialSynchronization\Tasks\Composite\InitialSyncTask;
  5. use Crsw\CleverReachOfficial\Core\BusinessLogic\TaskExecution\Events\QueueItemFinishedEvent;
  6. use Crsw\CleverReachOfficial\Core\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException;
  7. use Crsw\CleverReachOfficial\Core\Infrastructure\TaskExecution\Exceptions\QueueItemDeserializationException;
  8. use Crsw\CleverReachOfficial\Core\Infrastructure\TaskExecution\QueueItem;
  9. use JsonException;
  10. /**
  11.  * Class QueueItemFinishedListener
  12.  *
  13.  * @package Crsw\CleverReachOfficial\Components\StateTransition
  14.  */
  15. class QueueItemFinishedListener extends QueueItemListener
  16. {
  17.     /**
  18.      * Handles queue item finished event.
  19.      *
  20.      * @param QueueItemFinishedEvent $event
  21.      *
  22.      * @throws QueryFilterInvalidParamException
  23.      * @throws QueueItemDeserializationException
  24.      * @throws JsonException
  25.      */
  26.     public static function handle(QueueItemFinishedEvent $event): void
  27.     {
  28.         $queueItem $event->getQueueItem();
  29.         $taskType $queueItem->getTaskType();
  30.         if ($taskType === InitialSyncTask::getClassName()) {
  31.             $entity = new StateTransitionRecord();
  32.             $entity->setStatus(QueueItem::COMPLETED);
  33.             $entity->setTaskType($taskType);
  34.             $entity->setResolved(false);
  35.             $entity->setQueueItem($queueItem);
  36.             $existingRecord self::getExistingRecord($taskType);
  37.             self::updateOrCreateStateTransitionRecord($entity$existingRecord);
  38.         }
  39.     }
  40. }