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

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.     /**
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             DocumentEvents::POST_UPDATE => 'onDocumentSave',
  45.         ];
  46.     }
  47.     /**
  48.      * @param DocumentEvent $event
  49.      *
  50.      * @throws \Exception
  51.      */
  52.     public function onDocumentSave(DocumentEvent $event)
  53.     {
  54.         $document $event->getDocument();
  55.         if ($this->languageVariantService->isLanguageVariantDocument($document)) {
  56.             $this->languageVariantService->clearCache();
  57.         }
  58.         $parentLanguageRedirectEnabled = (bool) Db::get()->fetchOne('select data from documents_editables where name = ? and documentId = ? limit 1', [
  59.             PortalConfig::ENABLE_LANGUAGE_REDIRECT,
  60.             $document->getParentId()
  61.         ]);
  62.         if ($parentLanguageRedirectEnabled) {
  63.             $this->languageVariantService->clearCache();
  64.         }
  65.     }
  66. }