custom/plugins/UnzerPayment6/src/UnzerPayment6.php line 26

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 Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  15. use UnzerPayment6\Components\UnzerPaymentClassLoader;
  16. use UnzerPayment6\Installer\CustomFieldInstaller;
  17. use UnzerPayment6\Installer\PaymentInstaller;
  18. if (file_exists(__DIR__ '/../vendor/autoload.php')) {
  19.     (new UnzerPaymentClassLoader())->register();
  20. }
  21. class UnzerPayment6 extends Plugin
  22. {
  23.     public const MAX_DECIMAL_PRECISION 4;
  24.     public function build(ContainerBuilder $container): void
  25.     {
  26.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection'));
  27.         $loader->load('container.xml');
  28.         parent::build($container);
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function install(InstallContext $installContext): void
  34.     {
  35.         /** @var EntityRepository $paymentRepository */
  36.         $paymentRepository $this->container->get('payment_method.repository');
  37.         /** @var EntityRepository $customFieldSetRepository */
  38.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  39.         (new PaymentInstaller($paymentRepository))->install($installContext);
  40.         (new CustomFieldInstaller($customFieldSetRepository))->install($installContext);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function update(UpdateContext $updateContext): void
  46.     {
  47.         /** @var EntityRepository $paymentRepository */
  48.         $paymentRepository $this->container->get('payment_method.repository');
  49.         /** @var EntityRepository $customFieldSetRepository */
  50.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  51.         (new PaymentInstaller($paymentRepository))->update($updateContext);
  52.         (new CustomFieldInstaller($customFieldSetRepository))->update($updateContext);
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      */
  57.     public function activate(ActivateContext $activateContext): void
  58.     {
  59.         /** @var EntityRepository $paymentRepository */
  60.         $paymentRepository $this->container->get('payment_method.repository');
  61.         /** @var EntityRepository $customFieldSetRepository */
  62.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  63.         (new PaymentInstaller($paymentRepository))->activate($activateContext);
  64.         (new CustomFieldInstaller($customFieldSetRepository))->activate($activateContext);
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function deactivate(DeactivateContext $deactivateContext): 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.         (new PaymentInstaller($paymentRepository))->deactivate($deactivateContext);
  76.         (new CustomFieldInstaller($customFieldSetRepository))->deactivate($deactivateContext);
  77.     }
  78.     /**
  79.      * {@inheritdoc}
  80.      */
  81.     public function uninstall(UninstallContext $uninstallContext): void
  82.     {
  83.         /** @var EntityRepository $paymentRepository */
  84.         $paymentRepository $this->container->get('payment_method.repository');
  85.         /** @var EntityRepository $customFieldSetRepository */
  86.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  87.         /** @var Connection $connection */
  88.         $connection $this->container->get(Connection::class);
  89.         (new PaymentInstaller($paymentRepository))->uninstall($uninstallContext);
  90.         if (!$uninstallContext->keepUserData()) {
  91.             (new CustomFieldInstaller($customFieldSetRepository))->uninstall($uninstallContext);
  92.             $connection->exec('
  93.                 DROP TABLE IF EXISTS `unzer_payment_transfer_info`;
  94.                 DROP TABLE IF EXISTS `unzer_payment_payment_device`;
  95.             ');
  96.         }
  97.     }
  98. }