src/EventListener/DatabaseUpdateListener.php line 16

  1. <?php
  2. namespace App\EventListener;
  3. use Doctrine\Persistence\Event\LifecycleEventArgs;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. class DatabaseUpdateListener implements EventSubscriberInterface
  6. {
  7.     public function flushCache(): void
  8.     {
  9.         // @todo: change path/logic
  10.         $command 'php ' $_ENV['TYPO3_PATH'] . 'vendor/bin/typo3cms cache:flush';
  11.         shell_exec($command);
  12.     }
  13.     public function postPersist(LifecycleEventArgs $args): void
  14.     {
  15.         $this->flushCache();
  16.     }
  17.     public function postUpdate(LifecycleEventArgs $args): void
  18.     {
  19.         $this->flushCache();
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             'doctrine.postPersist' => 'postPersist',
  25.             'doctrine.postUpdate' => 'postPersist',
  26.         ];
  27.     }
  28. }