custom/plugins/MoorlSignIn/src/MoorlSignIn.php line 11

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Moorl\SignIn;
  3. use MoorlFoundation\Core\Service\DataService;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  8. class MoorlSignIn extends Plugin
  9. {
  10.     public const NAME 'MoorlSignIn';
  11.     public const DATA_CREATED_AT '2000-09-18 00:00:00.000';
  12.     public const PLUGIN_TABLES = [
  13.         'moorl_si'
  14.     ];
  15.     public const SHOPWARE_TABLES = [
  16.         'mail_template_type',
  17.         'mail_template_type_translation',
  18.         'mail_template',
  19.         'mail_template_translation',
  20.         'event_action',
  21.         'flow',
  22.         'custom_field_set'
  23.     ];
  24.     public const INHERITANCES = [];
  25.     public const MAIL_TEMPLATE_MAIL_SEND_ACTION 'moorl_si.action.mail.send';
  26.     public const EMPTY_TEXT "*****";
  27.     public const EMPTY_ZIPCODE "00000";
  28.     public const SKIP_CHECK_TOKEN "skip-check-token";
  29.     public const LAST_KNOWN_PAGE "last-known-page";
  30.     public function activate(ActivateContext $activateContext): void
  31.     {
  32.         parent::activate($activateContext); // TODO: Change the autogenerated stub
  33.         /* @var $dataService DataService */
  34.         $dataService $this->container->get(DataService::class);
  35.         $dataService->install(self::NAME);
  36.     }
  37.     public function update(UpdateContext $updateContext): void
  38.     {
  39.         parent::update($updateContext); // 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 uninstall(UninstallContext $context): void
  48.     {
  49.         parent::uninstall($context);
  50.         if ($context->keepUserData()) {
  51.             return;
  52.         }
  53.         $this->uninstallTrait();
  54.     }
  55.     private function uninstallTrait(): void
  56.     {
  57.         $connection $this->container->get(Connection::class);
  58.         foreach (array_reverse(self::PLUGIN_TABLES) as $table) {
  59.             $sql sprintf('DROP TABLE IF EXISTS `%s`;'$table);
  60.             $connection->executeStatement($sql);
  61.         }
  62.         foreach (array_reverse(self::SHOPWARE_TABLES) as $table) {
  63.             $sql sprintf("DELETE FROM `%s` WHERE `created_at` = '%s';"$tableself::DATA_CREATED_AT);
  64.             try {
  65.                 $connection->executeStatement($sql);
  66.             } catch (\Exception $exception) {
  67.                 continue;
  68.             }
  69.         }
  70.         $sql "DELETE FROM `snippet` WHERE `translation_key` LIKE 'customFields.moorl_si_%';";
  71.         $connection->executeStatement($sql);
  72.     }
  73. }