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

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