vendor/pimcore/pimcore/bundles/AdminBundle/EventListener/ImportConfigListener.php line 58

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\Model\DataObject\ClassDefinitionEvent;
  18. use Pimcore\Event\Model\UserRoleEvent;
  19. use Pimcore\Event\UserRoleEvents;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. class ImportConfigListener implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @inheritDoc
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             DataObjectClassDefinitionEvents::POST_DELETE => 'onClassDelete',
  30.             UserRoleEvents::POST_DELETE => 'onUserDelete'
  31.         ];
  32.     }
  33.     /**
  34.      * @param ClassDefinitionEvent $event
  35.      */
  36.     public function onClassDelete($event)
  37.     {
  38.         $class $event->getClassDefinition();
  39.         $classId $class->getId();
  40.         // collect gridConfigs for that class id
  41.         $db Db::get();
  42.         $importConfigIds $db->fetchCol('select id from importconfigs where classId = ?'$classId);
  43.         if ($importConfigIds) {
  44.             $db->query('delete from importconfig_shares where importConfigId in (' implode($importConfigIds) . ')');
  45.         }
  46.         $this->cleanupImportConfigs('classId = ' $db->quote($classId));
  47.     }
  48.     /**
  49.      * @param UserRoleEvent $event
  50.      */
  51.     public function onUserDelete($event)
  52.     {
  53.         $user $event->getUserRole();
  54.         $userId $user->getId();
  55.         $db Db::get();
  56.         $importConfigIds $db->fetchCol('select id from importconfigs where ownerId = ' $userId);
  57.         if ($importConfigIds) {
  58.             $db->query('delete from importconfig_shares where importConfigId in (' implode($importConfigIds) . ')');
  59.         }
  60.         $this->cleanupImportConfigs('ownerId = ' $userId);
  61.     }
  62.     protected function cleanupImportConfigs($condition)
  63.     {
  64.         $db Db::get();
  65.         $db->query('DELETE FROM importconfigs where ' $condition);
  66.     }
  67. }