vendor/store.shopware.com/unzerpayment6/src/UnzerPayment6.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace UnzerPayment6;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  8. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  12. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  17. use UnzerPayment6\Components\UnzerPaymentClassLoader;
  18. use UnzerPayment6\Installer\CustomFieldInstaller;
  19. use UnzerPayment6\Installer\PaymentInstaller;
  20. include_once 'Components/BackwardsCompatibility/RouteScope.php';
  21. include_once 'Components/BackwardsCompatibility/InvoiceGenerator.php';
  22. if (file_exists(__DIR__ '/../vendor/autoload.php')) {
  23.     (new UnzerPaymentClassLoader())->register();
  24. }
  25. /**
  26.  * @property ContainerInterface $container
  27.  */
  28. class UnzerPayment6 extends Plugin
  29. {
  30.     public const PLUGIN_NAME 'UnzerPayment6';
  31.     public const MAX_DECIMAL_PRECISION 4;
  32.     public function build(ContainerBuilder $container): void
  33.     {
  34.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection'));
  35.         $loader->load('container.xml');
  36.         parent::build($container);
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function install(InstallContext $installContext): void
  42.     {
  43.         /** @var EntityRepository $paymentRepository */
  44.         $paymentRepository $this->container->get('payment_method.repository');
  45.         /** @var EntityRepository $customFieldSetRepository */
  46.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  47.         /** @var PluginIdProvider $pluginIdProvider */
  48.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  49.         (new PaymentInstaller($paymentRepository$pluginIdProvider))->install($installContext);
  50.         (new CustomFieldInstaller($customFieldSetRepository))->install($installContext);
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      */
  55.     public function update(UpdateContext $updateContext): void
  56.     {
  57.         /** @var EntityRepository $paymentRepository */
  58.         $paymentRepository $this->container->get('payment_method.repository');
  59.         /** @var EntityRepository $customFieldSetRepository */
  60.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  61.         /** @var PluginIdProvider $pluginIdProvider */
  62.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  63.         (new PaymentInstaller($paymentRepository$pluginIdProvider))->update($updateContext);
  64.         (new CustomFieldInstaller($customFieldSetRepository))->update($updateContext);
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function activate(ActivateContext $activateContext): void
  70.     {
  71.         /** @var EntityRepository $paymentRepository */
  72.         $paymentRepository $this->container->get('payment_method.repository');
  73.         /** @var EntityRepository $customFieldSetRepository */
  74.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  75.         /** @var PluginIdProvider $pluginIdProvider */
  76.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  77.         (new PaymentInstaller($paymentRepository$pluginIdProvider))->activate($activateContext);
  78.         (new CustomFieldInstaller($customFieldSetRepository))->activate($activateContext);
  79.     }
  80.     /**
  81.      * {@inheritdoc}
  82.      */
  83.     public function deactivate(DeactivateContext $deactivateContext): void
  84.     {
  85.         /** @var EntityRepository $paymentRepository */
  86.         $paymentRepository $this->container->get('payment_method.repository');
  87.         /** @var EntityRepository $customFieldSetRepository */
  88.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  89.         /** @var PluginIdProvider $pluginIdProvider */
  90.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  91.         (new PaymentInstaller($paymentRepository$pluginIdProvider))->deactivate($deactivateContext);
  92.         (new CustomFieldInstaller($customFieldSetRepository))->deactivate($deactivateContext);
  93.     }
  94.     /**
  95.      * {@inheritdoc}
  96.      */
  97.     public function uninstall(UninstallContext $uninstallContext): void
  98.     {
  99.         /** @var EntityRepository $paymentRepository */
  100.         $paymentRepository $this->container->get('payment_method.repository');
  101.         /** @var EntityRepository $customFieldSetRepository */
  102.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  103.         /** @var Connection $connection */
  104.         $connection $this->container->get(Connection::class);
  105.         /** @var PluginIdProvider $pluginIdProvider */
  106.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  107.         (new PaymentInstaller($paymentRepository$pluginIdProvider))->uninstall($uninstallContext);
  108.         if (!$uninstallContext->keepUserData()) {
  109.             (new CustomFieldInstaller($customFieldSetRepository))->uninstall($uninstallContext);
  110.             $connection->executeStatement('
  111.             DROP TABLE IF EXISTS `unzer_payment_transfer_info`;
  112.             DROP TABLE IF EXISTS `unzer_payment_payment_device`;
  113.         '
  114.             );
  115.         }
  116.     }
  117. }