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

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