custom/plugins/GbmedEnev/src/GbmedEnev.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedEnev
  12.  * @copyright      Copyright (c) 2019, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\Enev;
  18. use Gbmed\Enev\Core\Content\Enev\EnevDefinition;
  19. use Gbmed\Enev\Core\Content\Enev\Aggregate\EnevTranslation\EnevTranslationDefinition;
  20. use Shopware\Core\Framework\Plugin;
  21. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  22. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  23. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  24. use Doctrine\DBAL\Connection;
  25. class GbmedEnev extends Plugin
  26. {
  27.     /**
  28.      * changing the storefront script path
  29.      *
  30.      * @return string
  31.      */
  32.     public function getStorefrontScriptPath(): string
  33.     {
  34.         return 'Resources/dist/storefront/js';
  35.     }
  36.     public function activate(ActivateContext $context): void
  37.     {
  38.         parent::activate($context);
  39.         $connection $this->getConnection();
  40.         $connection->executeStatement('UPDATE `product_sorting` SET `active`=1 WHERE url_key LIKE "gbmed-enev-%"');
  41.     }
  42.     public function deactivate(DeactivateContext $context): void
  43.     {
  44.         parent::deactivate($context);
  45.         $connection $this->getConnection();
  46.         $connection->executeStatement('UPDATE `product_sorting` SET `active`=0 WHERE url_key LIKE "gbmed-enev-%"');
  47.     }
  48.     /**
  49.      * removing the plugin data
  50.      *
  51.      * @param UninstallContext $context
  52.      *
  53.      * @throws \Doctrine\DBAL\DBALException
  54.      */
  55.     public function uninstall(UninstallContext $context): void
  56.     {
  57.         parent::uninstall($context);
  58.         if ($context->keepUserData()) {
  59.             return;
  60.         }
  61.         $connection $this->getConnection();
  62.         $connection->executeStatement('DROP TABLE IF EXISTS `' EnevTranslationDefinition::ENTITY_NAME '`');
  63.         $connection->executeStatement('DROP TABLE IF EXISTS `' EnevDefinition::ENTITY_NAME '`');
  64.         $connection->executeStatement('DELETE FROM `product_sorting` WHERE url_key LIKE "gbmed-enev-%"');
  65.         $connection->executeStatement('DELETE FROM `import_export_profile` WHERE source_entity LIKE "gbmed_enev"');
  66.     }
  67.     private function getConnection()
  68.     {
  69.         return $this->container->get(Connection::class);
  70.     }
  71. }