src/Domain/Common/EventSubscribers/UnlockConsultationOnNewRequestSubscriber.php line 38

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Common\EventSubscribers;
  4. use App\Domain\Common\Lock\EditionConsultationLockHandler;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  9. class UnlockConsultationOnNewRequestSubscriber implements EventSubscriberInterface
  10. {
  11.     const ROUTES_WITH_LOCK = [
  12.         'consultation_examen',
  13.         'patient_consultation_detail_edition',
  14.         'patient_consultation_detail_edition_json',
  15.         'patient_consultation_detail_edition_part_dto',
  16.         'patient_consultation_detail_edition_fields_update',
  17.         'patient_consultation_detail_editing_by',
  18.         'consultation_check_import_version',
  19.         'interconnexion',
  20.         'interconnexion_launch_import',
  21.         'machine_export_manuel'
  22.     ];
  23.     /**
  24.      * @var EditionConsultationLockHandler
  25.      */
  26.     private EditionConsultationLockHandler $lockHandler;
  27.     public function __construct(
  28.         EditionConsultationLockHandler $lockHandler
  29.     ) {
  30.         $this->lockHandler $lockHandler;
  31.     }
  32.     public function unlockConsultation(ControllerArgumentsEvent $event): void
  33.     {
  34.         if ($event->getRequest()->isXmlHttpRequest()) {
  35.             // pas d'unlock en ajax
  36.             return;
  37.         }
  38.         if (!\in_array($event->getRequest()->get('_route'), self::ROUTES_WITH_LOCKtrue)) {
  39.             try {
  40.                 // si on est pas sur une route concernée par la consultation, on peut considérer qu'on unlock
  41.                 $this->lockHandler->releaseUserLock();
  42.             } catch (AccessDeniedException $e) {
  43.                 //si on est pas connecté, il n'y a rien a faire
  44.             }
  45.         }
  46.     }
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [
  50.             KernelEvents::CONTROLLER_ARGUMENTS => 'unlockConsultation'
  51.         ];
  52.     }
  53. }