custom/plugins/MoorlCmsBrandSlider/src/MoorlCmsBrandSlider.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlCmsBrandSlider;
  3. use Doctrine\DBAL\Connection;
  4. use MoorlFoundation\Core\Service\DataService;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. class MoorlCmsBrandSlider extends Plugin
  10. {
  11.     public const NAME 'MoorlCmsBrandSlider';
  12.     public const DATA_CREATED_AT '2021-11-07 00:00:00.000';
  13.     public const PLUGIN_TABLES = [];
  14.     public const SHOPWARE_TABLES = [
  15.         'cms_page',
  16.         'cms_page_translation',
  17.         'cms_section',
  18.         'cms_block',
  19.         'cms_slot',
  20.         'category',
  21.         'product_manufacturer',
  22.         'moorl_sorting'
  23.     ];
  24.     public function install(InstallContext $context): void
  25.     {
  26.         parent::install($context);
  27.     }
  28.     public function activate(ActivateContext $activateContext): void
  29.     {
  30.         parent::activate($activateContext); // TODO: Change the autogenerated stub
  31.         /* @var $dataService DataService */
  32.         $dataService $this->container->get(DataService::class);
  33.         $dataService->install(self::NAME);
  34.     }
  35.     public function uninstall(UninstallContext $uninstallContext): void
  36.     {
  37.         parent::uninstall($uninstallContext);
  38.         if ($uninstallContext->keepUserData()) {
  39.             return;
  40.         }
  41.         $this->uninstallTrait();
  42.     }
  43.     private function uninstallTrait(): void
  44.     {
  45.         $connection $this->container->get(Connection::class);
  46.         foreach (self::PLUGIN_TABLES as $table) {
  47.             $sql sprintf('SET FOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS `%s`;'$table);
  48.             $connection->executeUpdate($sql);
  49.         }
  50.         foreach (array_reverse(self::SHOPWARE_TABLES) as $table) {
  51.             $sql sprintf("SET FOREIGN_KEY_CHECKS=0; DELETE FROM `%s` WHERE `created_at` = '%s';"$tableself::DATA_CREATED_AT);
  52.             try {
  53.                 $connection->executeUpdate($sql);
  54.             } catch (\Exception $exception) {
  55.                 continue;
  56.             }
  57.         }
  58.     }
  59. }