custom/plugins/PayonePayment/src/PayonePayment.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PayonePayment;
  4. use Doctrine\DBAL\Connection;
  5. use PayonePayment\Installer\ConfigInstaller;
  6. use PayonePayment\Installer\CustomFieldInstaller;
  7. use PayonePayment\Installer\PaymentMethodInstaller;
  8. use PayonePayment\Installer\RuleInstaller\RuleInstallerSecureInvoice;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\Plugin;
  11. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  12. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  13. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  15. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  16. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  17. use Shopware\Core\System\SystemConfig\SystemConfigService;
  18. use Symfony\Component\Config\FileLocator;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  21. class PayonePayment extends Plugin
  22. {
  23.     public const PLUGIN_NAME 'PayonePayment';
  24.     public function build(ContainerBuilder $container): void
  25.     {
  26.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection'));
  27.         $loader->load('services.xml');
  28.         parent::build($container);
  29.     }
  30.     public function install(InstallContext $context): void
  31.     {
  32.         $this->getConfigInstaller()->install($context);
  33.         $this->getCustomFieldInstaller()->install($context);
  34.         $this->getPaymentMethodInstaller()->install($context);
  35.         $this->getRuleInstallerSecureInvoice()->install($context);
  36.     }
  37.     public function update(UpdateContext $context): void
  38.     {
  39.         $this->getConfigInstaller()->update($context);
  40.         $this->getCustomFieldInstaller()->update($context);
  41.         $this->getPaymentMethodInstaller()->update($context);
  42.         $this->getRuleInstallerSecureInvoice()->update($context);
  43.     }
  44.     public function activate(ActivateContext $context): void
  45.     {
  46.         $this->getConfigInstaller()->activate($context);
  47.         $this->getCustomFieldInstaller()->activate($context);
  48.         $this->getPaymentMethodInstaller()->activate($context);
  49.         $this->getRuleInstallerSecureInvoice()->activate($context);
  50.     }
  51.     public function deactivate(DeactivateContext $context): void
  52.     {
  53.         $this->getConfigInstaller()->deactivate($context);
  54.         $this->getCustomFieldInstaller()->deactivate($context);
  55.         $this->getPaymentMethodInstaller()->deactivate($context);
  56.         $this->getRuleInstallerSecureInvoice()->deactivate($context);
  57.     }
  58.     public function uninstall(UninstallContext $context): void
  59.     {
  60.         $this->getConfigInstaller()->uninstall($context);
  61.         $this->getCustomFieldInstaller()->uninstall($context);
  62.         $this->getPaymentMethodInstaller()->uninstall($context);
  63.         $this->getRuleInstallerSecureInvoice()->uninstall($context);
  64.         if ($context->keepUserData()) {
  65.             return;
  66.         }
  67.         /** @var Connection $connection */
  68.         $connection $this->container->get(Connection::class);
  69.         if (method_exists($connection'executeStatement')) {
  70.             $connection->executeStatement('DROP TABLE payone_payment_card');
  71.             $connection->executeStatement('DROP TABLE payone_payment_redirect');
  72.             $connection->executeStatement('DROP TABLE payone_payment_mandate');
  73.             return;
  74.         }
  75.         if (method_exists($connection'exec')) {
  76.             /** @noinspection PhpDeprecationInspection */
  77.             $connection->exec('DROP TABLE payone_payment_card');
  78.             /** @noinspection PhpDeprecationInspection */
  79.             $connection->exec('DROP TABLE payone_payment_redirect');
  80.             /** @noinspection PhpDeprecationInspection */
  81.             $connection->exec('DROP TABLE payone_payment_mandate');
  82.         }
  83.     }
  84.     private function getRuleInstallerSecureInvoice(): RuleInstallerSecureInvoice
  85.     {
  86.         /** @var EntityRepositoryInterface $ruleRepository */
  87.         $ruleRepository $this->container->get('rule.repository');
  88.         /** @var EntityRepositoryInterface $countryRepository */
  89.         $countryRepository $this->container->get('country.repository');
  90.         /** @var EntityRepositoryInterface $currencyRepository */
  91.         $currencyRepository $this->container->get('currency.repository');
  92.         return new RuleInstallerSecureInvoice(
  93.             $ruleRepository,
  94.             $countryRepository,
  95.             $currencyRepository
  96.         );
  97.     }
  98.     private function getConfigInstaller(): ConfigInstaller
  99.     {
  100.         /** @var SystemConfigService $systemConfigService */
  101.         $systemConfigService $this->container->get(SystemConfigService::class);
  102.         return new ConfigInstaller($systemConfigService);
  103.     }
  104.     private function getPaymentMethodInstaller(): PaymentMethodInstaller
  105.     {
  106.         /** @var PluginIdProvider $pluginIdProvider */
  107.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  108.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  109.         $paymentMethodRepository $this->container->get('payment_method.repository');
  110.         /** @var EntityRepositoryInterface $salesChannelRepository */
  111.         $salesChannelRepository $this->container->get('sales_channel.repository');
  112.         /** @var EntityRepositoryInterface $paymentMethodSalesChannelRepository */
  113.         $paymentMethodSalesChannelRepository $this->container->get('sales_channel_payment_method.repository');
  114.         /** @var Connection $connection */
  115.         $connection $this->container->get(Connection::class);
  116.         return new PaymentMethodInstaller(
  117.             $pluginIdProvider,
  118.             $paymentMethodRepository,
  119.             $salesChannelRepository,
  120.             $paymentMethodSalesChannelRepository,
  121.             $connection
  122.         );
  123.     }
  124.     private function getCustomFieldInstaller(): CustomFieldInstaller
  125.     {
  126.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  127.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  128.         /** @var EntityRepositoryInterface $customFieldRepository */
  129.         $customFieldRepository $this->container->get('custom_field.repository');
  130.         return new CustomFieldInstaller($customFieldSetRepository$customFieldRepository);
  131.     }
  132. }