custom/plugins/MoorlInterrupter/src/MoorlInterrupter.php line 9

Open in your IDE?
  1. <?php
  2. namespace MoorlInterrupter;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  6. class MoorlInterrupter extends Plugin
  7. {
  8.     public const NAME 'MoorlInterrupter';
  9.     public const DATA_CREATED_AT '2021-08-22 00:00:00.000';
  10.     public const PLUGIN_TABLES = [
  11.         'moorl_interrupter',
  12.         'moorl_interrupter_translation',
  13.         'moorl_interrupter_category'
  14.     ];
  15.     public const SHOPWARE_TABLES = [
  16.         'custom_field_set',
  17.         'unit',
  18.         'shipping_method',
  19.         'shipping_method_translation',
  20.         'cms_page',
  21.         'cms_page_translation',
  22.         'cms_section',
  23.         'cms_block',
  24.         'category',
  25.         'category_translation',
  26.         'product',
  27.         'product_translation',
  28.         'product_category',
  29.         'product_visibility',
  30.         'theme',
  31.         'theme_sales_channel',
  32.         'sales_channel'
  33.     ];
  34.     public function uninstall(UninstallContext $uninstallContext): void
  35.     {
  36.         parent::uninstall($uninstallContext);
  37.         if ($uninstallContext->keepUserData()) {
  38.             return;
  39.         }
  40.         $this->removePluginData();
  41.         $this->dropTables();
  42.     }
  43.     private function removePluginData(): void
  44.     {
  45.         $connection $this->container->get(Connection::class);
  46.         foreach (array_reverse(self::SHOPWARE_TABLES) as $table) {
  47.             $sql sprintf("SET FOREIGN_KEY_CHECKS=0; DELETE FROM `%s` WHERE `created_at` = '%s';"$tableself::DATA_CREATED_AT);
  48.             try {
  49.                 $connection->executeStatement($sql);
  50.             } catch (\Exception $exception) {
  51.                 continue;
  52.             }
  53.         }
  54.     }
  55.     private function dropTables(): void
  56.     {
  57.         $connection $this->container->get(Connection::class);
  58.         foreach (self::PLUGIN_TABLES as $table) {
  59.             $sql sprintf('SET FOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS `%s`;'$table);
  60.             $connection->executeStatement($sql);
  61.         }
  62.     }
  63. }