custom/plugins/PickwareDhl/vendor/pickware/document-bundle/src/DocumentBundle.php line 28

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\DocumentBundle;
  11. use Doctrine\DBAL\Connection;
  12. use Pickware\BundleInstaller\BundleInstaller;
  13. use Pickware\DalBundle\DalBundle;
  14. use Pickware\DocumentBundle\Installation\DocumentFileSizeMigrator;
  15. use Pickware\ShopwarePlugins\ShopwareIntegrationTestPlugin\ShopwareIntegrationTestPlugin;
  16. use Shopware\Core\Framework\Bundle;
  17. use Shopware\Core\Framework\Migration\MigrationSource;
  18. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  19. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  20. use Shopware\Core\Framework\Struct\Collection;
  21. use Symfony\Component\Config\FileLocator;
  22. use Symfony\Component\DependencyInjection\ContainerBuilder;
  23. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  24. class DocumentBundle extends Bundle
  25. {
  26.     /**
  27.      * @var class-string<Bundle>[]
  28.      */
  29.     private const ADDITIONAL_BUNDLES = [DalBundle::class];
  30.     private static ?self $instance null;
  31.     private static bool $registered false;
  32.     private static bool $migrationsRegistered false;
  33.     public static function register(Collection $bundleCollection): void
  34.     {
  35.         if (self::$registered) {
  36.             return;
  37.         }
  38.         $bundleCollection->add(self::getInstance());
  39.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  40.             $bundle::register($bundleCollection);
  41.         }
  42.         self::$registered true;
  43.     }
  44.     public static function registerMigrations(MigrationSource $migrationSource): void
  45.     {
  46.         if (self::$migrationsRegistered) {
  47.             return;
  48.         }
  49.         $migrationsPath self::getInstance()->getMigrationPath();
  50.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  51.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  52.         $migrationSource->addDirectory(__DIR__ '/MigrationOldNamespace''Pickware\\ShopwarePlugins\\DocumentBundle\\Migration');
  53.         self::$migrationsRegistered true;
  54.     }
  55.     public function install(InstallContext $installContext): void
  56.     {
  57.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  58.             ->install(self::ADDITIONAL_BUNDLES$installContext);
  59.     }
  60.     public function onAfterActivate(InstallContext $activateContext): void
  61.     {
  62.         $documentFileSizeMigrator $this->container->get(DocumentFileSizeMigrator::class);
  63.         $documentFileSizeMigrator->migrateFileSize();
  64.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  65.             ->onAfterActivate(self::ADDITIONAL_BUNDLES$activateContext);
  66.     }
  67.     public static function getInstance(): self
  68.     {
  69.         if (!self::$instance) {
  70.             self::$instance = new self();
  71.         }
  72.         return self::$instance;
  73.     }
  74.     public function build(ContainerBuilder $containerBuilder): void
  75.     {
  76.         parent::build($containerBuilder);
  77.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  78.         $loader->load('DependencyInjection/controller.xml');
  79.         $loader->load('DependencyInjection/decorator.xml');
  80.         $loader->load('DependencyInjection/model.xml');
  81.         $loader->load('DependencyInjection/service.xml');
  82.         $loader->load('DependencyInjection/subscriber.xml');
  83.         $loader->load('Installation/DependencyInjection/service.xml');
  84.         $loader->load('Renderer/DependencyInjection/service.xml');
  85.         // Register test services. Should never be loaded in production.
  86.         if (in_array(ShopwareIntegrationTestPlugin::class, $containerBuilder->getParameter('kernel.bundles'), true)) {
  87.             $loader->load('../test/TestEntityCreation/DependencyInjection/service.xml');
  88.         }
  89.     }
  90.     public function shutdown(): void
  91.     {
  92.         parent::shutdown();
  93.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  94.         // request. After the kernel was rebooted, our bundles have to be registered again.
  95.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  96.         // again in the (re)boot process.
  97.         self::$registered false;
  98.     }
  99.     public function uninstall(UninstallContext $uninstallContext): void
  100.     {
  101.         if ($uninstallContext->keepUserData()) {
  102.             return;
  103.         }
  104.         $db $this->container->get(Connection::class);
  105.         $db->executeStatement('
  106.             DROP TABLE IF EXISTS `pickware_document`;
  107.             DROP TABLE IF EXISTS `pickware_document_type`;
  108.         ');
  109.         // We need eight backslashes, as we need to match a single one and double the count for each of the following:
  110.         // 1. The PHP parser
  111.         // 2. The MySQL parser
  112.         // 3. The MySQL pattern matcher (only when using LIKE)
  113.         $db->executeStatement("DELETE FROM `migration` WHERE `class` LIKE 'Pickware\\\\\\\\DocumentBundle\\\\\\\\%'");
  114.         $db->executeStatement("DELETE FROM `migration` WHERE `class` LIKE 'Pickware\\\\\\\\ShopwarePlugins\\\\\\\\DocumentBundle\\\\\\\\%'");
  115.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  116.     }
  117. }