custom/plugins/PickwareErpStarter/vendor/pickware/shopware-extensions-bundle/src/PickwareShopwareExtensionsBundle.php line 26

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\ShopwareExtensionsBundle;
  11. use Doctrine\DBAL\Connection;
  12. use Pickware\BundleInstaller\BundleInstaller;
  13. use Pickware\ShopwareExtensionsBundle\OrderConfiguration\OrderConfigurationIndexer;
  14. use Shopware\Core\Framework\Bundle;
  15. use Shopware\Core\Framework\Migration\MigrationSource;
  16. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  17. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  18. use Shopware\Core\Framework\Struct\Collection;
  19. use Symfony\Component\Config\FileLocator;
  20. use Symfony\Component\DependencyInjection\ContainerBuilder;
  21. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  22. class PickwareShopwareExtensionsBundle extends Bundle
  23. {
  24.     private static ?self $instance null;
  25.     private static bool $registered false;
  26.     private static bool $migrationsRegistered false;
  27.     public static function register(Collection $bundleCollection): void
  28.     {
  29.         if (self::$registered) {
  30.             return;
  31.         }
  32.         $bundleCollection->add(self::getInstance());
  33.         self::$registered true;
  34.     }
  35.     public static function registerMigrations(MigrationSource $migrationSource): void
  36.     {
  37.         if (self::$migrationsRegistered) {
  38.             return;
  39.         }
  40.         $migrationsPath self::getInstance()->getMigrationPath();
  41.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  42.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  43.         self::$migrationsRegistered true;
  44.     }
  45.     public function onAfterActivate(InstallContext $installContext): void
  46.     {
  47.         /** @deprecated next-major OrderConfigurationIndexer will be removed */
  48.         $entityIndexerRegistry $this->container->get('pickware.pickware_shopware_extensions.entity_indexer_registry_public');
  49.         $entityIndexerRegistry->sendIndexingMessage([
  50.             OrderConfigurationIndexer::NAME,
  51.         ]);
  52.     }
  53.     public static function getInstance(): self
  54.     {
  55.         if (!self::$instance) {
  56.             self::$instance = new self();
  57.         }
  58.         return self::$instance;
  59.     }
  60.     public function build(ContainerBuilder $containerBuilder): void
  61.     {
  62.         parent::build($containerBuilder);
  63.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  64.         $loader->load('Mail/DependencyInjection/service.xml');
  65.         $loader->load('OrderDelivery/DependencyInjection/controller.xml');
  66.         $loader->load('OrderDelivery/DependencyInjection/service.xml');
  67.         $loader->load('OrderDocument/DependencyInjection/service.xml');
  68.         $loader->load('OrderConfiguration/DependencyInjection/indexer.xml');
  69.         $loader->load('OrderConfiguration/DependencyInjection/model.xml');
  70.         $loader->load('OrderConfiguration/DependencyInjection/model-extension.xml');
  71.         $loader->load('OrderConfiguration/DependencyInjection/service.xml');
  72.         $loader->load('StateTransitioning/DependencyInjection/service.xml');
  73.     }
  74.     public function shutdown(): void
  75.     {
  76.         parent::shutdown();
  77.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  78.         // request. After the kernel was rebooted, our bundles have to be registered again.
  79.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  80.         // again in the (re)boot process.
  81.         self::$registered false;
  82.     }
  83.     public function uninstall(UninstallContext $uninstallContext): void
  84.     {
  85.         if ($uninstallContext->keepUserData()) {
  86.             return;
  87.         }
  88.         $db $this->container->get(Connection::class);
  89.         $db->executeStatement('
  90.             -- Migration1657615865AddOrderConfigurationSchema.php
  91.             DROP TABLE IF EXISTS `pickware_shopware_extensions_order_configuration`;
  92.         ');
  93.         // We need eight backslashes, as we need to match a single one and double the count for each of the following:
  94.         // 1. The PHP parser
  95.         // 2. The MySQL parser
  96.         // 3. The MySQL pattern matcher (only when using LIKE)
  97.         $db->executeStatement("DELETE FROM `migration` WHERE `class` LIKE 'Pickware\\\\\\\\ShopwareExtensionsBundle\\\\\\\\%'");
  98.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  99.     }
  100. }