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 postUpdate(UpdateContext $updateContext): void
  45.     {
  46.         $this->getCustomFieldInstaller()->cleanup($updateContext);
  47.     }
  48.     public function activate(ActivateContext $context): void
  49.     {
  50.         $this->getConfigInstaller()->activate($context);
  51.         $this->getCustomFieldInstaller()->activate($context);
  52.         $this->getPaymentMethodInstaller()->activate($context);
  53.         $this->getRuleInstallerSecureInvoice()->activate($context);
  54.     }
  55.     public function deactivate(DeactivateContext $context): void
  56.     {
  57.         $this->getConfigInstaller()->deactivate($context);
  58.         $this->getCustomFieldInstaller()->deactivate($context);
  59.         $this->getPaymentMethodInstaller()->deactivate($context);
  60.         $this->getRuleInstallerSecureInvoice()->deactivate($context);
  61.     }
  62.     public function uninstall(UninstallContext $context): void
  63.     {
  64.         $this->getConfigInstaller()->uninstall($context);
  65.         $this->getCustomFieldInstaller()->uninstall($context);
  66.         $this->getPaymentMethodInstaller()->uninstall($context);
  67.         $this->getRuleInstallerSecureInvoice()->uninstall($context);
  68.         if ($context->keepUserData()) {
  69.             return;
  70.         }
  71.         /** @var Connection $connection */
  72.         $connection $this->container->get(Connection::class);
  73.         if (method_exists($connection'executeStatement')) {
  74.             $connection->executeStatement('DROP TABLE payone_payment_card');
  75.             $connection->executeStatement('DROP TABLE payone_payment_redirect');
  76.             $connection->executeStatement('DROP TABLE payone_payment_mandate');
  77.             $connection->executeStatement('DROP TABLE payone_payment_notification_forward');
  78.             $connection->executeStatement('DROP TABLE payone_payment_notification_target');
  79.             $connection->executeStatement('DROP TABLE payone_payment_order_transaction_data');
  80.             return;
  81.         }
  82.         if (method_exists($connection'exec')) {
  83.             /** @noinspection PhpDeprecationInspection */
  84.             $connection->exec('DROP TABLE payone_payment_card');
  85.             /** @noinspection PhpDeprecationInspection */
  86.             $connection->exec('DROP TABLE payone_payment_redirect');
  87.             /** @noinspection PhpDeprecationInspection */
  88.             $connection->exec('DROP TABLE payone_payment_mandate');
  89.             /** @noinspection PhpDeprecationInspection */
  90.             $connection->exec('DROP TABLE payone_payment_notification_forward');
  91.             /** @noinspection PhpDeprecationInspection */
  92.             $connection->exec('DROP TABLE payone_payment_notification_target');
  93.             /** @noinspection PhpDeprecationInspection */
  94.             $connection->exec('DROP TABLE payone_payment_order_transaction_data');
  95.         }
  96.     }
  97.     private function getRuleInstallerSecureInvoice(): RuleInstallerSecureInvoice
  98.     {
  99.         /** @var EntityRepositoryInterface $ruleRepository */
  100.         $ruleRepository $this->container->get('rule.repository');
  101.         /** @var EntityRepositoryInterface $countryRepository */
  102.         $countryRepository $this->container->get('country.repository');
  103.         /** @var EntityRepositoryInterface $currencyRepository */
  104.         $currencyRepository $this->container->get('currency.repository');
  105.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  106.         $paymentMethodRepository $this->container->get('payment_method.repository');
  107.         return new RuleInstallerSecureInvoice(
  108.             $ruleRepository,
  109.             $countryRepository,
  110.             $currencyRepository,
  111.             $paymentMethodRepository
  112.         );
  113.     }
  114.     private function getConfigInstaller(): ConfigInstaller
  115.     {
  116.         /** @var SystemConfigService $systemConfigService */
  117.         $systemConfigService $this->container->get(SystemConfigService::class);
  118.         return new ConfigInstaller($systemConfigService);
  119.     }
  120.     private function getPaymentMethodInstaller(): PaymentMethodInstaller
  121.     {
  122.         /** @var PluginIdProvider $pluginIdProvider */
  123.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  124.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  125.         $paymentMethodRepository $this->container->get('payment_method.repository');
  126.         /** @var EntityRepositoryInterface $salesChannelRepository */
  127.         $salesChannelRepository $this->container->get('sales_channel.repository');
  128.         /** @var EntityRepositoryInterface $paymentMethodSalesChannelRepository */
  129.         $paymentMethodSalesChannelRepository $this->container->get('sales_channel_payment_method.repository');
  130.         /** @var Connection $connection */
  131.         $connection $this->container->get(Connection::class);
  132.         return new PaymentMethodInstaller(
  133.             $pluginIdProvider,
  134.             $paymentMethodRepository,
  135.             $salesChannelRepository,
  136.             $paymentMethodSalesChannelRepository,
  137.             $connection
  138.         );
  139.     }
  140.     private function getCustomFieldInstaller(): CustomFieldInstaller
  141.     {
  142.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  143.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  144.         /** @var EntityRepositoryInterface $customFieldRepository */
  145.         $customFieldRepository $this->container->get('custom_field.repository');
  146.         return new CustomFieldInstaller($customFieldSetRepository$customFieldRepository);
  147.     }
  148. }