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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlForms;
  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 MoorlForms extends Plugin
  10. {
  11.     public const NAME 'MoorlForms';
  12.     public const DATA_CREATED_AT '2003-03-03 03:02:21.000';
  13.     public const PLUGIN_TABLES = [
  14.         'moorl_fb_form',
  15.         'moorl_fb_form_translation',
  16.         'moorl_fb_element',
  17.         'moorl_fb_element_translation'
  18.     ];
  19.     public const SHOPWARE_TABLES = [
  20.         'media_default_folder',
  21.         'cms_page',
  22.         'cms_page_translation',
  23.         'cms_section',
  24.         'cms_block',
  25.         'category',
  26.         'category_translation',
  27.         'mail_template_type',
  28.         'mail_template_type_translation',
  29.         'mail_template',
  30.         'mail_template_translation',
  31.         'event_action',
  32.         'custom_field_set'
  33.     ];
  34.     public const INHERITANCES = [
  35.         'product' => ['moorl_fb_forms']
  36.     ];
  37.     public const MAIL_TEMPLATE_MAIL_SEND_ACTION 'moorl_fb.action.mail.send';
  38.     public const MSG_CODE 58667;
  39.     public const DANGER 'danger';
  40.     public const SUCCESS 'success';
  41.     public const WARNING 'warning';
  42.     public const REPEATER_INDICATOR '?';
  43.     public const CHECKED_INDICATOR 'x';
  44.     public const FORM_ID_KEY '_fb_form_id';
  45.     public const ENTITY_ID_KEY '_fb_entity_id';
  46.     public const ENTITY_NAME_KEY '_fb_entity_name';
  47.     public const ENTITY_FIELD_KEY '_fb_entity_field';
  48.     public const CUSTOM_FIELD_HTML_KEY '_moorl_fb_html';
  49.     public const CUSTOM_FIELD_PLAIN_KEY '_moorl_fb_plain';
  50.     public const CUSTOM_FIELD_MEDIA_IDS_KEY '_moorl_fb_media_ids';
  51.     public const PAYLOAD_KEY '_moorl_fb';
  52.     public function activate(ActivateContext $activateContext): void
  53.     {
  54.         parent::activate($activateContext);
  55.         /* @var $dataService DataService */
  56.         $dataService $this->container->get(DataService::class);
  57.         $dataService->install(self::NAME);
  58.     }
  59.     public function update(UpdateContext $updateContext): void
  60.     {
  61.         parent::update($updateContext);
  62.         try {
  63.             /* @var $dataService DataService */
  64.             $dataService $this->container->get(DataService::class);
  65.             $dataService->install(self::NAME);
  66.         } catch (\Exception $exception) {
  67.         }
  68.     }
  69.     public function uninstall(UninstallContext $context): void
  70.     {
  71.         parent::uninstall($context);
  72.         if ($context->keepUserData()) {
  73.             return;
  74.         }
  75.         $this->uninstallTrait();
  76.     }
  77.     private function uninstallTrait(): void
  78.     {
  79.         $connection $this->container->get(Connection::class);
  80.         foreach (array_reverse(self::PLUGIN_TABLES) as $table) {
  81.             $sql sprintf('DROP TABLE IF EXISTS `%s`;'$table);
  82.             $connection->executeStatement($sql);
  83.         }
  84.         foreach (array_reverse(self::SHOPWARE_TABLES) as $table) {
  85.             $sql sprintf("DELETE FROM `%s` WHERE `created_at` = '%s';"$tableself::DATA_CREATED_AT);
  86.             try {
  87.                 $connection->executeStatement($sql);
  88.             } catch (\Exception $exception) {
  89.                 continue;
  90.             }
  91.         }
  92.         foreach (self::INHERITANCES as $table => $propertyNames) {
  93.             foreach ($propertyNames as $propertyName) {
  94.                 $sql sprintf("ALTER TABLE `%s` DROP `%s`;"$table$propertyName);
  95.                 try {
  96.                     $connection->executeStatement($sql);
  97.                 } catch (\Exception $exception) {
  98.                     continue;
  99.                 }
  100.             }
  101.         }
  102.         $sql "DELETE FROM `snippet` WHERE `translation_key` LIKE 'customFields.moorl_fb_%';";
  103.         $connection->executeStatement($sql);
  104.     }
  105. }