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.         $entityIndexerRegistry $this->container->get('pickware.pickware_shopware_extensions.entity_indexer_registry_public');
  48.         $entityIndexerRegistry->sendIndexingMessage([
  49.             OrderConfigurationIndexer::NAME,
  50.         ]);
  51.     }
  52.     public static function getInstance(): self
  53.     {
  54.         if (!self::$instance) {
  55.             self::$instance = new self();
  56.         }
  57.         return self::$instance;
  58.     }
  59.     public function build(ContainerBuilder $containerBuilder): void
  60.     {
  61.         parent::build($containerBuilder);
  62.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  63.         $loader->load('Mail/DependencyInjection/service.xml');
  64.         $loader->load('OrderDelivery/DependencyInjection/controller.xml');
  65.         $loader->load('OrderDelivery/DependencyInjection/service.xml');
  66.         $loader->load('OrderDocument/DependencyInjection/service.xml');
  67.         $loader->load('OrderConfiguration/DependencyInjection/indexer.xml');
  68.         $loader->load('OrderConfiguration/DependencyInjection/model.xml');
  69.         $loader->load('OrderConfiguration/DependencyInjection/model-extension.xml');
  70.         $loader->load('OrderConfiguration/DependencyInjection/service.xml');
  71.         $loader->load('StateTransitioning/DependencyInjection/service.xml');
  72.     }
  73.     public function boot(): void
  74.     {
  75.         parent::boot();
  76.         // Shopware may reboot the kernel under certain circumstances. After the kernel was rebooted, our bundles have
  77.         // to be registered again. Since there does not seem to be a way to detect a reboot, we reset the registration
  78.         // flag immediately after the bundle has been booted. This will cause the bundles to be registered again when
  79.         // the method self::register is called the next time, which will only happen in the case of a kernel reboot.
  80.         self::$registered false;
  81.     }
  82.     public function uninstall(UninstallContext $uninstallContext): void
  83.     {
  84.         if ($uninstallContext->keepUserData()) {
  85.             return;
  86.         }
  87.         $db $this->container->get(Connection::class);
  88.         $db->executeStatement('
  89.             SET FOREIGN_KEY_CHECKS=0;
  90.             -- Migration1657615865AddOrderConfigurationSchema.php
  91.             DROP TABLE IF EXISTS `pickware_shopware_extensions_order_configuration`;
  92.             SET FOREIGN_KEY_CHECKS=1;
  93.         ');
  94.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  95.     }
  96. }