<?php
namespace Cms\CoreBundle\EventSubscriber\OneRoster;
use App\Model\Query\ConditionQuery\ConditionConfig;
use Cms\CoreBundle\Entity\OneRosterJob;
use Cms\CoreBundle\Events\OneRosterEvents;
use Cms\CoreBundle\Service\OneRosterService;
use Cms\CoreBundle\Util\Doctrine\EntityManager;
use Exception;
use Platform\QueueBundle\Event\AsyncEvent;
use Platform\QueueBundle\Service\AsyncQueueService;
use Products\NotificationsBundle\Service\Builder\ConditionDictionaryBuilder;
use Products\NotificationsBundle\Service\Notifications\NotificationsConfigService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class OneRosterTidySubscriber
* @package Cms\CoreBundle\EventSubscriber\OneRoster
*/
final class OneRosterTidySubscriber extends AbstractOneRosterSubscriber
{
/**
* @var NotificationsConfigService
*/
private NotificationsConfigService $notificationsConfigService;
/**
* @var ConditionDictionaryBuilder
*/
private ConditionDictionaryBuilder $conditionDictionaryBuilder;
/**
* @param EntityManager $em
* @param AsyncQueueService $async
* @param OneRosterService $oneroster
* @param EventDispatcherInterface $dispatcher
* @param NotificationsConfigService $notificationsConfigService
* @param ConditionDictionaryBuilder $conditionDictionaryBuilder
*/
public function __construct(
EntityManager $em,
AsyncQueueService $async,
OneRosterService $oneroster,
EventDispatcherInterface $dispatcher,
NotificationsConfigService $notificationsConfigService,
ConditionDictionaryBuilder $conditionDictionaryBuilder
) {
parent::__construct($em, $async, $oneroster, $dispatcher);
$this->notificationsConfigService = $notificationsConfigService;
$this->conditionDictionaryBuilder = $conditionDictionaryBuilder;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [
OneRosterEvents::EVENT__TIDY => [
['discardableDisable', self::PRIORITY__FIRST],
['phaseStart', self::PRIORITY__FIRST],
//['ssoGroupsCleanup', 0],
['phaseFin', self::PRIORITY__LAST],
['phaseTrigger', self::PRIORITY__LAST],
['discardableEnable', self::PRIORITY__LAST],
['syncNotificationDictionaries', 0],
],
];
}
/**
* @param AsyncEvent $event
* @return void
* @throws Exception
*/
public function syncNotificationDictionaries(AsyncEvent $event): void
{
$job = $this->loadJob($event);
$event->getOutput()->writeln(
sprintf(
'Notification dictionaries sync #%s loaded',
$job->getIdentifier()
)
);
$tenant = $job->getTenant();
$this->notificationsConfigService->saveNotificationsBaseConfig(
$tenant,
new ConditionConfig([], $this->conditionDictionaryBuilder->build($tenant)),
);
}
/**
* {@inheritDoc}
*/
public function phase(): int
{
return OneRosterJob::PHASES__TIDY;
}
/**
* {@inheritDoc}
*/
public function next(): ?int
{
return null;
}
}