custom/plugins/NetiNextAdminTools/src/NetiNextAdminTools.php line 16

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace NetInventors\NetiNextAdminTools;
  3. use Doctrine\DBAL\Connection;
  4. use Doctrine\DBAL\ConnectionException;
  5. use Doctrine\DBAL\Exception as DbalException;
  6. use NetInventors\NetiNextAdminTools\Components\Setup;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use Throwable;
  13. class NetiNextAdminTools extends Plugin
  14. {
  15.     /**
  16.      * @param InstallContext $installContext
  17.      *
  18.      * @throws \Throwable
  19.      */
  20.     public function install(InstallContext $installContext): void
  21.     {
  22.         parent::install($installContext);
  23.         (new Setup($installContext$this->container))->install();
  24.     }
  25.     /**
  26.      * @throws Throwable
  27.      */
  28.     public function update(UpdateContext $updateContext): void
  29.     {
  30.         parent::update($updateContext);
  31.         (new Setup($updateContext$this->container))->update();
  32.     }
  33.     /**
  34.      * @param UninstallContext $uninstallContext
  35.      *
  36.      * @throws ConnectionException|DbalException
  37.      */
  38.     public function uninstall(UninstallContext $uninstallContext): void
  39.     {
  40.         parent::uninstall($uninstallContext);
  41.         if ($uninstallContext->keepUserData()) {
  42.             return;
  43.         }
  44.         (new Setup($uninstallContext$this->container))->uninstall();
  45.         /** @var Connection|null $connection */
  46.         $connection $this->container->get(
  47.             Connection::class,
  48.             ContainerInterface::NULL_ON_INVALID_REFERENCE
  49.         );
  50.         if (null === $connection) {
  51.             return;
  52.         }
  53.         $connection->beginTransaction();
  54.         try {
  55.             $connection->executeStatement('SET FOREIGN_KEY_CHECKS=0');
  56.             $connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter`');
  57.             $connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter_role`');
  58.             $connection->executeStatement('DROP TABLE IF EXISTS `neti_admin_tools_filter_condition`');
  59.             $connection->executeStatement('SET FOREIGN_KEY_CHECKS=1');
  60.             $connection->commit();
  61.         } catch (Throwable $exception) {
  62.             $connection->rollBack();
  63.             throw $exception;
  64.         }
  65.     }
  66. }