src/Cms/CoreBundle/EventSubscriber/OneRoster/OneRosterTidySubscriber.php line 80

Open in your IDE?
  1. <?php
  2. namespace Cms\CoreBundle\EventSubscriber\OneRoster;
  3. use App\Model\Query\ConditionQuery\ConditionConfig;
  4. use Cms\CoreBundle\Entity\OneRosterJob;
  5. use Cms\CoreBundle\Events\OneRosterEvents;
  6. use Cms\CoreBundle\Service\OneRosterService;
  7. use Cms\CoreBundle\Util\Doctrine\EntityManager;
  8. use Exception;
  9. use Platform\QueueBundle\Event\AsyncEvent;
  10. use Platform\QueueBundle\Service\AsyncQueueService;
  11. use Products\NotificationsBundle\Service\Builder\ConditionDictionaryBuilder;
  12. use Products\NotificationsBundle\Service\Notifications\NotificationsConfigService;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. /**
  16.  * Class OneRosterTidySubscriber
  17.  * @package Cms\CoreBundle\EventSubscriber\OneRoster
  18.  */
  19. final class OneRosterTidySubscriber extends AbstractOneRosterSubscriber
  20. {
  21.     /**
  22.      * @var NotificationsConfigService
  23.      */
  24.     private NotificationsConfigService $notificationsConfigService;
  25.     /**
  26.      * @var ConditionDictionaryBuilder
  27.      */
  28.     private ConditionDictionaryBuilder $conditionDictionaryBuilder;
  29.     /**
  30.      * @param EntityManager $em
  31.      * @param AsyncQueueService $async
  32.      * @param OneRosterService $oneroster
  33.      * @param EventDispatcherInterface $dispatcher
  34.      * @param NotificationsConfigService $notificationsConfigService
  35.      * @param ConditionDictionaryBuilder $conditionDictionaryBuilder
  36.      */
  37.     public function __construct(
  38.         EntityManager $em,
  39.         AsyncQueueService $async,
  40.         OneRosterService $oneroster,
  41.         EventDispatcherInterface $dispatcher,
  42.         NotificationsConfigService $notificationsConfigService,
  43.         ConditionDictionaryBuilder $conditionDictionaryBuilder
  44.     ) {
  45.         parent::__construct($em$async$oneroster$dispatcher);
  46.         $this->notificationsConfigService $notificationsConfigService;
  47.         $this->conditionDictionaryBuilder $conditionDictionaryBuilder;
  48.     }
  49.     /**
  50.      * {@inheritDoc}
  51.      */
  52.     public static function getSubscribedEvents(): array
  53.     {
  54.         return [
  55.             OneRosterEvents::EVENT__TIDY => [
  56.                 ['discardableDisable'self::PRIORITY__FIRST],
  57.                 ['phaseStart'self::PRIORITY__FIRST],
  58.                 //['ssoGroupsCleanup', 0],
  59.                 ['phaseFin'self::PRIORITY__LAST],
  60.                 ['phaseTrigger'self::PRIORITY__LAST],
  61.                 ['discardableEnable'self::PRIORITY__LAST],
  62.                 ['syncNotificationDictionaries'0],
  63.             ],
  64.         ];
  65.     }
  66.     /**
  67.      * @param AsyncEvent $event
  68.      * @return void
  69.      * @throws Exception
  70.      */
  71.     public function syncNotificationDictionaries(AsyncEvent $event): void
  72.     {
  73.         $job $this->loadJob($event);
  74.         $event->getOutput()->writeln(
  75.             sprintf(
  76.                 'Notification dictionaries sync #%s loaded',
  77.                 $job->getIdentifier()
  78.             )
  79.         );
  80.         $tenant $job->getTenant();
  81.         $this->notificationsConfigService->saveNotificationsBaseConfig(
  82.             $tenant,
  83.             new ConditionConfig([], $this->conditionDictionaryBuilder->build($tenant)),
  84.         );
  85.     }
  86.     /**
  87.      * {@inheritDoc}
  88.      */
  89.     public function phase(): int
  90.     {
  91.         return OneRosterJob::PHASES__TIDY;
  92.     }
  93.     /**
  94.      * {@inheritDoc}
  95.      */
  96.     public function next(): ?int
  97.     {
  98.         return null;
  99.     }
  100. }