vendor/store.shopware.com/moorlcreator/src/MoorlCreator.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlCreator;
  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\UninstallContext;
  8. class MoorlCreator extends Plugin
  9. {
  10.     public const NAME 'MoorlCreator';
  11.     public const CMS_PAGE_CREATOR_DEFAULT_ID 'a054f7fb8664f8f6da162b2387e9c351';
  12.     public const CREATOR_TYPE_DEFAULT_ID 'a054f7fb8664f8f6da222b2387e9c351';
  13.     public const DATA_CREATED_AT '2012-03-26 00:00:00.000';
  14.     public const PLUGIN_TABLES = [
  15.         'moorl_creator_type',
  16.         'moorl_creator_type_translation',
  17.         'moorl_creator',
  18.         'moorl_creator_translation',
  19.         'moorl_creator_customer',
  20.         'moorl_creator_product',
  21.         'moorl_creator_follower'
  22.     ];
  23.     public const SHOPWARE_TABLES = [
  24.         'custom_field_set',
  25.         'unit',
  26.         'shipping_method',
  27.         'shipping_method_translation',
  28.         'cms_page',
  29.         'cms_page_translation',
  30.         'cms_section',
  31.         'cms_block',
  32.         'category',
  33.         'category_translation',
  34.         'product',
  35.         'product_translation',
  36.         'product_category',
  37.         'product_visibility',
  38.         'seo_url_template',
  39.         'media_default_folder',
  40.         'custom_field_set',
  41.         'moorl_sorting'
  42.     ];
  43.     public const INHERITANCES = [
  44.         'product' => ['creators']
  45.     ];
  46.     public function activate(ActivateContext $activateContext): void
  47.     {
  48.         parent::activate($activateContext);
  49.         /* @var $dataService DataService */
  50.         $dataService $this->container->get(DataService::class);
  51.         $dataService->install(self::NAME);
  52.     }
  53.     public function uninstall(UninstallContext $uninstallContext): void
  54.     {
  55.         parent::uninstall($uninstallContext);
  56.         if ($uninstallContext->keepUserData()) {
  57.             return;
  58.         }
  59.         $this->uninstallTrait();
  60.     }
  61.     private function uninstallTrait(): void
  62.     {
  63.         $connection $this->container->get(Connection::class);
  64.         foreach (array_reverse(self::PLUGIN_TABLES) as $table) {
  65.             $sql sprintf('DROP TABLE IF EXISTS `%s`;'$table);
  66.             $connection->executeStatement($sql);
  67.         }
  68.         foreach (self::INHERITANCES as $table => $propertyNames) {
  69.             foreach ($propertyNames as $propertyName) {
  70.                 $sql sprintf("ALTER TABLE `%s` DROP `%s`;"$table$propertyName);
  71.                 try {
  72.                     $connection->executeStatement($sql);
  73.                 } catch (\Exception $exception) {
  74.                     continue;
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }