custom/plugins/SwagDynamicAccess/src/SwagDynamicAccess.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\DynamicAccess;
  8. use Doctrine\DBAL\Connection;
  9. use Shopware\Core\Framework\Plugin;
  10. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  11. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  12. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  14. use Swag\DynamicAccess\DataAbstractionLayer\CategoryRule\CategoryRuleDefinition;
  15. use Swag\DynamicAccess\DataAbstractionLayer\LandingPageRule\LandingPageRuleDefinition;
  16. use Swag\DynamicAccess\DataAbstractionLayer\ProductRule\ProductRuleDefinition;
  17. class SwagDynamicAccess extends Plugin
  18. {
  19.     public function activate(ActivateContext $activateContext): void
  20.     {
  21.         parent::activate($activateContext);
  22.     }
  23.     public function deactivate(DeactivateContext $deactivateContext): void
  24.     {
  25.         parent::deactivate($deactivateContext);
  26.     }
  27.     public function uninstall(UninstallContext $uninstallContext): void
  28.     {
  29.         if ($uninstallContext->keepUserData()) {
  30.             return;
  31.         }
  32.         $this->removeTables();
  33.     }
  34.     public function update(UpdateContext $updateContext): void
  35.     {
  36.         parent::update($updateContext);
  37.     }
  38.     /**
  39.      * @return array<mixed>
  40.      */
  41.     public function enrichPrivileges(): array
  42.     {
  43.         return [];
  44.     }
  45.     private function removeTables(): void
  46.     {
  47.         $connection $this->container->get(Connection::class);
  48.         $classNames = [
  49.             CategoryRuleDefinition::ENTITY_NAME,
  50.             LandingPageRuleDefinition::ENTITY_NAME,
  51.             ProductRuleDefinition::ENTITY_NAME,
  52.         ];
  53.         foreach ($classNames as $className) {
  54.             $connection->executeStatement(\sprintf('DROP TABLE IF EXISTS `%s`'$className));
  55.         }
  56.     }
  57. }