custom/plugins/SwagAmazonPay/src/SwagAmazonPay.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Swag\AmazonPay;
  9. use Doctrine\DBAL\Connection;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  11. use Shopware\Core\Framework\Plugin;
  12. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  13. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  14. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  15. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  16. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  17. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  18. use Swag\AmazonPay\Installer\CustomFieldsInstaller;
  19. use Swag\AmazonPay\Installer\DatabaseInstaller;
  20. use Swag\AmazonPay\Installer\DefaultSalutationInstaller;
  21. use Swag\AmazonPay\Installer\EventActionInstaller;
  22. use Swag\AmazonPay\Installer\MailTemplateInstaller;
  23. use Swag\AmazonPay\Installer\PaymentMethodInstaller;
  24. use Swag\AmazonPay\Installer\RuleInstaller;
  25. use Swag\AmazonPay\Uninstaller\ConfigurationUninstaller;
  26. use Swag\AmazonPay\Uninstaller\LogUninstaller;
  27. use Swag\AmazonPay\Util\SwagAmazonPayClassLoader;
  28. use Symfony\Component\Config\FileLocator;
  29. use Symfony\Component\DependencyInjection\ContainerBuilder;
  30. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  31. if (\file_exists(__DIR__ '/../vendor/autoload.php')) {
  32.     (new SwagAmazonPayClassLoader())->register();
  33. }
  34. class SwagAmazonPay extends Plugin
  35. {
  36.     public function install(InstallContext $installContext): void
  37.     {
  38.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  39.         $paymentMethodRepository $this->container->get('payment_method.repository');
  40.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  41.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  42.         /** @var EntityRepositoryInterface $salutationRepository */
  43.         $salutationRepository $this->container->get('salutation.repository');
  44.         /** @var EntityRepositoryInterface $ruleRepository */
  45.         $ruleRepository $this->container->get('rule.repository');
  46.         /** @var EntityRepositoryInterface $currencyRepository */
  47.         $currencyRepository $this->container->get('currency.repository');
  48.         /** @var PluginIdProvider $pluginIdProvider */
  49.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  50.         /** @var EntityRepositoryInterface $mailTemplateRepository */
  51.         $mailTemplateRepository $this->container->get('mail_template.repository');
  52.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  53.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  54.         /** @var EntityRepositoryInterface $eventActionRepository */
  55.         $eventActionRepository $this->container->get('event_action.repository');
  56.         (new PaymentMethodInstaller($paymentMethodRepository$pluginIdProvider))->install($installContext);
  57.         (new CustomFieldsInstaller($customFieldSetRepository))->install($installContext);
  58.         (new DefaultSalutationInstaller($salutationRepository))->install($installContext);
  59.         (new RuleInstaller($ruleRepository$currencyRepository$paymentMethodRepository))->install($installContext);
  60.         (new MailTemplateInstaller($mailTemplateRepository$mailTemplateTypeRepository))->install($installContext);
  61.         (new EventActionInstaller($eventActionRepository$mailTemplateRepository))->install($installContext);
  62.     }
  63.     public function update(UpdateContext $updateContext): void
  64.     {
  65.         /** @var EntityRepositoryInterface $ruleRepository */
  66.         $ruleRepository $this->container->get('rule.repository');
  67.         /** @var EntityRepositoryInterface $currencyRepository */
  68.         $currencyRepository $this->container->get('currency.repository');
  69.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  70.         $paymentMethodRepository $this->container->get('payment_method.repository');
  71.         (new RuleInstaller($ruleRepository$currencyRepository$paymentMethodRepository))->update($updateContext);
  72.     }
  73.     public function deactivate(DeactivateContext $deactivateContext): void
  74.     {
  75.         /** @var EntityRepositoryInterface $paymentRepository */
  76.         $paymentRepository $this->container->get('payment_method.repository');
  77.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  78.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  79.         /** @var PluginIdProvider $pluginIdProvider */
  80.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  81.         (new PaymentMethodInstaller($paymentRepository$pluginIdProvider))->deactivate($deactivateContext);
  82.         (new CustomFieldsInstaller($customFieldSetRepository))->deactivate($deactivateContext);
  83.     }
  84.     public function uninstall(UninstallContext $uninstallContext): void
  85.     {
  86.         /** @var EntityRepositoryInterface $paymentMethodRepository */
  87.         $paymentMethodRepository $this->container->get('payment_method.repository');
  88.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  89.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  90.         /** @var PluginIdProvider $pluginIdProvider */
  91.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  92.         /** @var Connection $connection */
  93.         $connection $this->container->get(Connection::class);
  94.         /** @var EntityRepositoryInterface $ruleRepository */
  95.         $ruleRepository $this->container->get('rule.repository');
  96.         /** @var EntityRepositoryInterface $currencyRepository */
  97.         $currencyRepository $this->container->get('currency.repository');
  98.         /** @var EntityRepositoryInterface $mailTemplateRepository */
  99.         $mailTemplateRepository $this->container->get('mail_template.repository');
  100.         /** @var EntityRepositoryInterface $mailTemplateTypeRepository */
  101.         $mailTemplateTypeRepository $this->container->get('mail_template_type.repository');
  102.         /** @var EntityRepositoryInterface $eventActionRepository */
  103.         $eventActionRepository $this->container->get('event_action.repository');
  104.         (new PaymentMethodInstaller($paymentMethodRepository$pluginIdProvider))->uninstall($uninstallContext);
  105.         (new CustomFieldsInstaller($customFieldSetRepository))->uninstall($uninstallContext);
  106.         (new DatabaseInstaller($connection))->uninstall($uninstallContext);
  107.         (new RuleInstaller($ruleRepository$currencyRepository$paymentMethodRepository))->uninstall($uninstallContext);
  108.         (new MailTemplateInstaller($mailTemplateRepository$mailTemplateTypeRepository))->uninstall($uninstallContext);
  109.         (new EventActionInstaller($eventActionRepository$mailTemplateRepository))->uninstall($uninstallContext);
  110.         (new ConfigurationUninstaller($connection))->uninstall($uninstallContext);
  111.         $logsDir $this->container->getParameter('kernel.logs_dir');
  112.         if (!\is_string($logsDir)) {
  113.             return;
  114.         }
  115.         (new LogUninstaller($logsDir))->uninstall($uninstallContext);
  116.     }
  117.     public function activate(ActivateContext $activateContext): void
  118.     {
  119.         /** @var EntityRepositoryInterface $paymentRepository */
  120.         $paymentRepository $this->container->get('payment_method.repository');
  121.         /** @var EntityRepositoryInterface $customFieldSetRepository */
  122.         $customFieldSetRepository $this->container->get('custom_field_set.repository');
  123.         /** @var PluginIdProvider $pluginIdProvider */
  124.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  125.         (new PaymentMethodInstaller($paymentRepository$pluginIdProvider))->activate($activateContext);
  126.         (new CustomFieldsInstaller($customFieldSetRepository))->activate($activateContext);
  127.     }
  128.     public function build(ContainerBuilder $container): void
  129.     {
  130.         parent::build($container);
  131.         $shopwareVersion $container->getParameter('kernel.shopware_version');
  132.         if (!\is_string($shopwareVersion)) {
  133.             throw new \RuntimeException('SwagAmazonPay needs the kernel.shopware_version parameter to determine which services to load.');
  134.         }
  135.         // Shopware version specific service loading
  136.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/Dynamic'));
  137.         if (\version_compare($shopwareVersion'6.4.0''<')) {
  138.             $loader->load('SW6.3.xml');
  139.             return;
  140.         }
  141.         $loader->load('SW6.4.xml');
  142.     }
  143.     public function enrichPrivileges(): array
  144.     {
  145.         return [
  146.             'order.viewer' => [
  147.                 'swag_amazon_pay_payment_notification:read',
  148.             ],
  149.         ];
  150.     }
  151. }