custom/plugins/PickwareErpStarter/vendor/pickware/document-bundle/src/DocumentBundle.php line 29

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