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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFormsClassic;
  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. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. class MoorlFormsClassic extends Plugin
  10. {
  11.     public const NAME 'MoorlFormsClassic';
  12.     public const DATA_CREATED_AT '2003-03-03 03:02:22.000';
  13.     public const PLUGIN_TABLES = [
  14.         'moorl_fb_history',
  15.         'moorl_fb_appointment',
  16.     ];
  17.     public const SHOPWARE_TABLES = [
  18.         'moorl_fb_form',
  19.         'moorl_fb_form_translation',
  20.         'moorl_fb_form_product',
  21.         'moorl_fb_element',
  22.         'moorl_fb_element_translation',
  23.         'cms_page',
  24.         'cms_page_translation',
  25.         'cms_section',
  26.         'cms_block',
  27.         'category',
  28.         'category_translation',
  29.         'mail_template_type',
  30.         'mail_template_type_translation',
  31.         'mail_template',
  32.         'mail_template_translation',
  33.         'event_action',
  34.         'custom_field_set'
  35.     ];
  36.     public const INHERITANCES = [];
  37.     public function activate(ActivateContext $activateContext): void
  38.     {
  39.         parent::activate($activateContext); // TODO: Change the autogenerated stub
  40.         try {
  41.             /* @var $dataService DataService */
  42.             $dataService $this->container->get(DataService::class);
  43.             $dataService->install(self::NAME);
  44.         } catch (\Exception $exception) {
  45.         }
  46.     }
  47.     public function update(UpdateContext $updateContext): void
  48.     {
  49.         parent::update($updateContext); // TODO: Change the autogenerated stub
  50.         try {
  51.             /* @var $dataService DataService */
  52.             $dataService $this->container->get(DataService::class);
  53.             $dataService->install(self::NAME);
  54.         } catch (\Exception $exception) {
  55.         }
  56.     }
  57.     public function uninstall(UninstallContext $context): void
  58.     {
  59.         parent::uninstall($context);
  60.         if ($context->keepUserData()) {
  61.             return;
  62.         }
  63.         $this->uninstallTrait();
  64.     }
  65.     private function uninstallTrait(): void
  66.     {
  67.         $connection $this->container->get(Connection::class);
  68.         foreach (array_reverse(self::PLUGIN_TABLES) as $table) {
  69.             $sql sprintf('DROP TABLE IF EXISTS `%s`;'$table);
  70.             $connection->executeStatement($sql);
  71.         }
  72.         foreach (self::INHERITANCES as $table => $propertyNames) {
  73.             foreach ($propertyNames as $propertyName) {
  74.                 $sql sprintf("ALTER TABLE `%s` DROP `%s`;"$table$propertyName);
  75.                 try {
  76.                     $connection->executeStatement($sql);
  77.                 } catch (\Exception $exception) {
  78.                     continue;
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }