custom/plugins/NetiNextEasyCoupon/src/NetiNextEasyCoupon.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon;
  4. use Doctrine\DBAL\Connection;
  5. use Doctrine\DBAL\DBALException;
  6. use NetInventors\NetiNextEasyCoupon\Components\RuleBasedContainerFile;
  7. use NetInventors\NetiNextEasyCoupon\Components\RuleBasedContainerFileLoader;
  8. use NetInventors\NetiNextEasyCoupon\Components\Setup;
  9. use NetInventors\NetiNextEasyCoupon\Service\VoucherCodeGenerator\ValidatorPass as VoucherCodeGeneratorValidatorPass;
  10. use NetInventors\NetiNextEasyCoupon\Service\VoucherRedemption\ValidatorPass as VoucherRedemptionValidatorPass;
  11. use Shopware\Core\Framework\Plugin;
  12. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. class NetiNextEasyCoupon extends Plugin
  17. {
  18.     public function build(ContainerBuilder $container): void
  19.     {
  20.         parent::build($container);
  21.         $container->addCompilerPass(new VoucherCodeGeneratorValidatorPass());
  22.         $container->addCompilerPass(new VoucherRedemptionValidatorPass());
  23.         $ruleBasedContainerFileLoader = new RuleBasedContainerFileLoader(
  24.             $container,
  25.             $this->getPath()
  26.         );
  27.         $version $container->getParameter('kernel.shopware_version');
  28.         $ruleBasedContainerFileLoader->load(new RuleBasedContainerFile(
  29.             $this->getPath() . '/Resources/config/migrations/6.3.5.0/NEXT-12478-after.xml',
  30.             function () use ($version) {
  31.                 return \version_compare($version'6.3.5.0''>=')
  32.                     && \version_compare($version'6.4.3.0''<');
  33.             }
  34.         ));
  35.         $ruleBasedContainerFileLoader->load(new RuleBasedContainerFile(
  36.             $this->getPath() . '/Resources/config/migrations/6.4.3.0/NEXT-15687.xml',
  37.             function () use ($version) {
  38.                 return \version_compare($version'6.4.3.0''>=');
  39.             }
  40.         ));
  41.     }
  42.     public function install(InstallContext $installContext): void
  43.     {
  44.         parent::install($installContext);
  45.         $setup = new Setup($this->container$installContext);
  46.         $setup->install();
  47.         $setup->installImportExportProfile($installContext->getContext());
  48.     }
  49.     /**
  50.      * @param UninstallContext $uninstallContext
  51.      *
  52.      * @throws DBALException
  53.      */
  54.     public function uninstall(UninstallContext $uninstallContext): void
  55.     {
  56.         parent::uninstall($uninstallContext);
  57.         if (false === $uninstallContext->keepUserData()) {
  58.             $connection $this->container->get(Connection::class);
  59.             if (!$connection instanceof Connection) {
  60.                 return;
  61.             }
  62.             $setup = new Setup($this->container$uninstallContext);
  63.             $setup->uninstall();
  64.             $query = <<<SQL
  65. SET foreign_key_checks=0;
  66. DROP TABLE IF EXISTS `neti_easy_coupon_translation`,
  67. `neti_easy_coupon_product_translation`,
  68. `neti_easy_coupon_product`,
  69. `neti_easy_coupon_transaction`,
  70. `neti_easy_coupon_legacy_setting`,
  71. `neti_easy_coupon_product_for_voucher`,
  72. `neti_easy_coupon`,
  73. `neti_easy_coupon_condition`,
  74. `neti_easy_coupon_product_condition`;
  75. SET foreign_key_checks=1;
  76. SQL;
  77.             $connection->executeQuery($query);
  78.         }
  79.     }
  80.     public function update(UpdateContext $updateContext): void
  81.     {
  82.         $setup = new Setup($this->container$updateContext);
  83.         $setup->installImportExportProfile($updateContext->getContext());
  84.         $setup->update();
  85.     }
  86. }