vendor/pimcore/portal-engine/src/EventSubscriber/DocumentCacheClearSubscriber.php line 56

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Enum\Document\Editables\PortalConfig;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\Document\LanguageVariantService;
  14. use Pimcore\Db;
  15. use Pimcore\Event\DocumentEvents;
  16. use Pimcore\Event\Model\DocumentEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. /**
  19.  * Class DocumentCacheClearSubscriber
  20.  *
  21.  * @package Pimcore\Bundle\PortalEngineBundle\EventListener
  22.  */
  23. class DocumentCacheClearSubscriber implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @var LanguageVariantService
  27.      */
  28.     protected $languageVariantService;
  29.     /**
  30.      * DocumentCacheClearSubscriber constructor.
  31.      *
  32.      * @param LanguageVariantService $languageVariantService
  33.      */
  34.     public function __construct(LanguageVariantService $languageVariantService)
  35.     {
  36.         $this->languageVariantService $languageVariantService;
  37.     }
  38.     public static function getSubscribedEvents()
  39.     {
  40.         return [
  41.             DocumentEvents::POST_UPDATE => 'onDocumentSave',
  42.         ];
  43.     }
  44.     /**
  45.      * @param DocumentEvent $event
  46.      *
  47.      * @throws \Exception
  48.      */
  49.     public function onDocumentSave(DocumentEvent $event)
  50.     {
  51.         $document $event->getDocument();
  52.         if ($this->languageVariantService->isLanguageVariantDocument($document)) {
  53.             $this->languageVariantService->clearCache();
  54.         }
  55.         $parentLanguageRedirectEnabled = (bool) Db::get()->fetchOne('select data from documents_editables where name = ? and documentId = ? limit 1', [
  56.             PortalConfig::ENABLE_LANGUAGE_REDIRECT,
  57.             $document->getParentId()
  58.         ]);
  59.         if ($parentLanguageRedirectEnabled) {
  60.             $this->languageVariantService->clearCache();
  61.         }
  62.     }
  63. }