vendor/datenwerk/ginger-bundle/EventSubscriber/TopicAttributeEventsLogger.php line 43

Open in your IDE?
  1. <?php
  2. namespace DW\GingerBundle\EventSubscriber;
  3. use DW\GingerBundle\DWGingerEvents;
  4. use DW\GingerBundle\Event\CRUDEvent;
  5. use DW\GingerBundle\Event\TopicIntegrationEvent;
  6. use Psr\Log\LoggerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. readonly class TopicAttributeEventsLogger implements EventSubscriberInterface
  9. {
  10.     public function __construct(
  11.         private LoggerInterface $gingerCoreEventsLogger,
  12.     ) {}
  13.     public function onTopicAttributeUpdate(CRUDEvent $event): void
  14.     {
  15.         $this->gingerCoreEventsLogger->info('TopicAttribute has been updated');
  16.         $this->gingerCoreEventsLogger->debug(
  17.             'Todo: Maybe update the title of a related newsletter list?',
  18.             [
  19.                 'updated_attribute_title' => $event->getObject()->getTitle()
  20.             ]
  21.         );
  22.     }
  23.     public function onTopicAttributeDelete(CRUDEvent $event): void
  24.     {
  25.         $this->gingerCoreEventsLogger->info('TopicAttribute has been deleted');
  26.         $this->gingerCoreEventsLogger->debug(
  27.             'Todo: Maybe delete a related newsletter list?',
  28.             [
  29.                 'some-attribute_props' => [
  30.                     'id' => $event->getObject()->getId(),
  31.                     'title' => $event->getObject()->getTitle(),
  32.                     'type' => $event->getObject()->getType(),
  33.                 ]
  34.             ]
  35.         );
  36.     }
  37.     public function onTopicAttributeIntegrationAdd(TopicIntegrationEvent $event): void
  38.     {
  39.         $this->gingerCoreEventsLogger->info('Integration has been ADDED to a Topic Attribute');
  40.         $this->gingerCoreEventsLogger->debug(
  41.             'Todo: Maybe subscribe related people to a linked newsletter list?',
  42.             [
  43.                 'topic' => [
  44.                     'id' => $event->getTopic()->getId(),
  45.                     'title' => $event->getTopic()->getTitle(),
  46.                 ],
  47.                 'integration' => [
  48.                     'id' => $event->getIntegration()->getId(),
  49.                     'title' => $event->getIntegration()->getTitle(),
  50.                 ]
  51.             ]
  52.         );
  53.     }
  54.     public function onTopicAttributeIntegrationRemove(TopicIntegrationEvent $event): void
  55.     {
  56.         $this->gingerCoreEventsLogger->info('Integration has been REMOVED from a Topic Attribute');
  57.         $this->gingerCoreEventsLogger->debug(
  58.             'Todo: Maybe un-subscribe related people from a linked newsletter list?',
  59.             [
  60.                 'topic' => [
  61.                     'id' => $event->getTopic()->getId(),
  62.                     'title' => $event->getTopic()->getTitle(),
  63.                 ],
  64.                 'integration' => [
  65.                     'id' => $event->getIntegration()->getId(),
  66.                     'title' => $event->getIntegration()->getTitle(),
  67.                 ]
  68.             ]
  69.         );
  70.     }
  71.     public static function getSubscribedEvents(): array
  72.     {
  73.         return [
  74.             DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_UPDATE'] => 'onTopicAttributeUpdate',
  75.             DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_INTEGRATION_ADD'] => 'onTopicAttributeIntegrationAdd',
  76.             DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_INTEGRATION_REMOVE'] => 'onTopicAttributeIntegrationRemove',
  77.             DWGingerEvents::TOPIC_ATTRIBUTE['ON_TOPIC_ATTRIBUTE_DELETE'] => 'onTopicAttributeDelete',
  78.         ];
  79.     }
  80. }