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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFoundation;
  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 MoorlFoundation extends Plugin
  9. {
  10.     public const NAME 'MoorlFoundation';
  11.     public const DATA_CREATED_AT '2001-11-11 11:11:11.111';
  12.     public const SHOPWARE_TABLES = [];
  13.     public const PLUGIN_TABLES = [
  14.         'moorl_cms_element_config',
  15.         'moorl_location',
  16.         'moorl_location_cache',
  17.         'moorl_sorting',
  18.         'moorl_sorting_translation',
  19.         'moorl_marker',
  20.     ];
  21.     public function activate(ActivateContext $activateContext): void
  22.     {
  23.         parent::activate($activateContext);
  24.         /* @var $dataService DataService */
  25.         $dataService $this->container->get(DataService::class);
  26.         $dataService->install(self::NAME);
  27.     }
  28.     public function uninstall(UninstallContext $context): void
  29.     {
  30.         parent::uninstall($context);
  31.         if ($context->keepUserData()) {
  32.             return;
  33.         }
  34.         $this->dropTables();
  35.     }
  36.     private function dropTables(): void
  37.     {
  38.         $connection $this->container->get(Connection::class);
  39.         foreach (self::PLUGIN_TABLES as $table) {
  40.             $sql sprintf('SET FOREIGN_KEY_CHECKS=0; DROP TABLE IF EXISTS `%s`;'$table);
  41.             $connection->executeStatement($sql);
  42.         }
  43.     }
  44. }