custom/plugins/SendcloudShipping/src/Controller/API/Frontend/AsyncProcessController.php line 49

Open in your IDE?
  1. <?php
  2. namespace Sendcloud\Shipping\Controller\API\Frontend;
  3. use Sendcloud\Shipping\Core\Infrastructure\Interfaces\Exposed\Runnable;
  4. use Sendcloud\Shipping\Core\Infrastructure\Logger\Logger;
  5. use Sendcloud\Shipping\Entity\Process\ProcessEntityRepository;
  6. use Sendcloud\Shipping\Service\Utility\Initializer;
  7. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * Class AsyncProcessController
  13.  *
  14.  * @package Sendcloud\Shipping\Controller\API\Frontend
  15.  */
  16. class AsyncProcessController extends AbstractController
  17. {
  18.     /**
  19.      * @var ProcessEntityRepository
  20.      */
  21.     private $processRepository;
  22.     /**
  23.      * AsyncProcessController constructor.
  24.      *
  25.      * @param Initializer $initializer
  26.      * @param ProcessEntityRepository $processRepository
  27.      */
  28.     public function __construct(Initializer $initializerProcessEntityRepository $processRepository)
  29.     {
  30.         $initializer->registerServices();
  31.         $this->processRepository $processRepository;
  32.     }
  33.     /**
  34.      * Async process starter endpoint
  35.      *
  36.      * @RouteScope(scopes={"api"})
  37.      * @Route(path="/api/v{version}/sendcloud/async/{guid}", name="api.sendcloud.async", defaults={"auth_required"=false}, methods={"GET", "POST"})
  38.      * @Route(path="/api/sendcloud/async/{guid}", name="api.sendcloud.async.new", defaults={"auth_required"=false}, methods={"GET", "POST"})
  39.      * @param string $guid
  40.      *
  41.      * @return JsonResponse
  42.      */
  43.     public function run(string $guid): JsonResponse
  44.     {
  45.         try {
  46.             $processEntity $this->processRepository->getProcessByGuid($guid);
  47.             if ($processEntity) {
  48.                 /** @var Runnable $runner */
  49.                 $runner =unserialize($processEntity->get('runner'));
  50.                 $runner->run();
  51.             }
  52.             $this->processRepository->deleteByGuid($guid);
  53.         } catch (\Exception $exception) {
  54.             Logger::logError("Ann error occurred when accessing process table: {$exception->getMessage()}");
  55.         }
  56.         return new JsonResponse(['success' => true]);
  57.     }
  58. }