vendor/pimcore/pimcore/bundles/AdminBundle/EventListener/GridConfigListener.php line 74

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace Pimcore\Bundle\AdminBundle\EventListener;
  15. use Pimcore\Db;
  16. use Pimcore\Event\DataObjectClassDefinitionEvents;
  17. use Pimcore\Event\DataObjectEvents;
  18. use Pimcore\Event\Model\DataObject\ClassDefinitionEvent;
  19. use Pimcore\Event\Model\DataObjectEvent;
  20. use Pimcore\Event\Model\UserRoleEvent;
  21. use Pimcore\Event\UserRoleEvents;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. class GridConfigListener implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @inheritDoc
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [
  31.             DataObjectClassDefinitionEvents::POST_DELETE => 'onClassDelete',
  32.             UserRoleEvents::POST_DELETE => 'onUserDelete',
  33.             DataObjectEvents::POST_DELETE => 'onObjectDelete'
  34.         ];
  35.     }
  36.     /**
  37.      * @param DataObjectEvent $event
  38.      */
  39.     public function onObjectDelete($event)
  40.     {
  41.         $object $event->getObject();
  42.         $objectId $object->getId();
  43.         $this->cleanupGridConfigFavourites('objectId = ' $objectId);
  44.     }
  45.     /**
  46.      * @param ClassDefinitionEvent $event
  47.      */
  48.     public function onClassDelete($event)
  49.     {
  50.         $class $event->getClassDefinition();
  51.         $classId $class->getId();
  52.         // collect gridConfigs for that class id
  53.         $db Db::get();
  54.         $gridConfigIds $db->fetchCol('select id from gridconfigs where classId = ?'$classId);
  55.         if ($gridConfigIds) {
  56.             $db->query('delete from gridconfig_shares where gridConfigId in (' implode($gridConfigIds) . ')');
  57.         }
  58.         $this->cleanupGridConfigs('classId = ' $db->quote($classId));
  59.         $this->cleanupGridConfigFavourites('classId = ' $db->quote($classId));
  60.     }
  61.     /**
  62.      * @param UserRoleEvent $event
  63.      */
  64.     public function onUserDelete($event)
  65.     {
  66.         $user $event->getUserRole();
  67.         $userId $user->getId();
  68.         $db Db::get();
  69.         $gridConfigIds $db->fetchCol('select id from gridconfigs where ownerId = ' $userId);
  70.         if ($gridConfigIds) {
  71.             $db->query('delete from gridconfig_shares where gridConfigId in (' implode($gridConfigIds) . ')');
  72.         }
  73.         $this->cleanupGridConfigs('ownerId = ' $userId);
  74.         $this->cleanupGridConfigFavourites('ownerId = ' $userId);
  75.     }
  76.     protected function cleanupGridConfigs($condition)
  77.     {
  78.         $db Db::get();
  79.         $db->query('DELETE FROM gridconfigs where ' $condition);
  80.     }
  81.     protected function cleanupGridConfigFavourites($condition)
  82.     {
  83.         $db Db::get();
  84.         $db->query('DELETE FROM gridconfig_favourites where ' $condition);
  85.     }
  86. }