custom/plugins/PickwareErpPro/vendor/pickware/shipping-bundle/src/PickwareShippingBundle.php line 34

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\ShippingBundle;
  11. use Doctrine\DBAL\Connection;
  12. use Pickware\BundleInstaller\BundleInstaller;
  13. use Pickware\DalBundle\DalBundle;
  14. use Pickware\DocumentBundle\DocumentBundle;
  15. use Pickware\InstallationLibrary\DependencyAwareTableDropper;
  16. use Pickware\MoneyBundle\MoneyBundle;
  17. use Pickware\ShippingBundle\Carrier\CarrierAdapterRegistryCompilerPass;
  18. use Pickware\ShippingBundle\Installation\PickwareShippingBundleInstaller;
  19. use Pickware\ShopwareExtensionsBundle\PickwareShopwareExtensionsBundle;
  20. use Pickware\ShopwarePlugins\ShopwareIntegrationTestPlugin\ShopwareIntegrationTestPlugin;
  21. use Pickware\ValidationBundle\PickwareValidationBundle;
  22. use Shopware\Core\Framework\Bundle;
  23. use Shopware\Core\Framework\Migration\MigrationSource;
  24. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  25. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  26. use Shopware\Core\Framework\Struct\Collection;
  27. use Symfony\Component\Config\FileLocator;
  28. use Symfony\Component\DependencyInjection\ContainerBuilder;
  29. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  30. class PickwareShippingBundle extends Bundle
  31. {
  32.     /**
  33.      * @var class-string<Bundle>[]
  34.      */
  35.     private const ADDITIONAL_BUNDLES = [
  36.         DalBundle::class,
  37.         DocumentBundle::class,
  38.         MoneyBundle::class,
  39.         PickwareShopwareExtensionsBundle::class,
  40.         PickwareValidationBundle::class,
  41.     ];
  42.     public const DOCUMENT_TYPE_TECHNICAL_NAME_DESCRIPTION_MAPPING = [
  43.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_SHIPPING_LABEL => 'Versandetikett',
  44.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_RETURN_LABEL => 'Retourenetikett',
  45.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_CUSTOMS_DECLARATION_CN23 => 'Zollinhaltserklärung CN23',
  46.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_STAMP => 'Briefmarke',
  47.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_COMMERCIAL_INVOICE => 'Handelsrechnung',
  48.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_WAYBILL => 'Frachtbrief',
  49.         PickwareShippingBundle::DOCUMENT_TYPE_TECHNICAL_NAME_OTHER => 'Sonstige',
  50.     ];
  51.     public const DOCUMENT_TYPE_TECHNICAL_NAME_STAMP 'stamp';
  52.     public const DOCUMENT_TYPE_TECHNICAL_NAME_CUSTOMS_DECLARATION_CN23 'customs_declaration_cn23';
  53.     public const DOCUMENT_TYPE_TECHNICAL_NAME_COMMERCIAL_INVOICE 'commercial_invoice';
  54.     public const DOCUMENT_TYPE_TECHNICAL_NAME_SHIPPING_LABEL 'shipping_label';
  55.     public const DOCUMENT_TYPE_TECHNICAL_NAME_RETURN_LABEL 'return_label';
  56.     public const DOCUMENT_TYPE_TECHNICAL_NAME_WAYBILL 'waybill';
  57.     public const DOCUMENT_TYPE_TECHNICAL_NAME_OTHER 'other';
  58.     private static ?PickwareShippingBundle $instance null;
  59.     private static bool $registered false;
  60.     private static bool $migrationsRegistered false;
  61.     public static function register(Collection $bundleCollection): void
  62.     {
  63.         if (self::$registered) {
  64.             return;
  65.         }
  66.         $bundleCollection->add(self::getInstance());
  67.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  68.             $bundle::register($bundleCollection);
  69.         }
  70.         self::$registered true;
  71.     }
  72.     public static function registerMigrations(MigrationSource $migrationSource): void
  73.     {
  74.         if (self::$migrationsRegistered) {
  75.             return;
  76.         }
  77.         $migrationsPath self::getInstance()->getMigrationPath();
  78.         $migrationNamespace self::getInstance()->getMigrationNamespace();
  79.         $migrationSource->addDirectory($migrationsPath$migrationNamespace);
  80.         self::$migrationsRegistered true;
  81.         foreach (self::ADDITIONAL_BUNDLES as $bundle) {
  82.             $bundle::registerMigrations($migrationSource);
  83.         }
  84.     }
  85.     public static function getInstance(): self
  86.     {
  87.         if (!self::$instance) {
  88.             self::$instance = new self();
  89.         }
  90.         return self::$instance;
  91.     }
  92.     public function build(ContainerBuilder $containerBuilder): void
  93.     {
  94.         parent::build($containerBuilder);
  95.         $loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
  96.         $loader->load('Carrier/DependencyInjection/model.xml');
  97.         $loader->load('Carrier/DependencyInjection/service.xml');
  98.         $loader->load('Carrier/DependencyInjection/subscriber.xml');
  99.         $loader->load('Config/DependencyInjection/command.xml');
  100.         $loader->load('Config/DependencyInjection/model.xml');
  101.         $loader->load('Config/DependencyInjection/service.xml');
  102.         $loader->load('DemodataGeneration/DependencyInjection/command.xml');
  103.         $loader->load('Logging/DependencyInjection/service.xml');
  104.         $loader->load('Mail/DependencyInjection/controller.xml');
  105.         $loader->load('Mail/DependencyInjection/service.xml');
  106.         $loader->load('Notifications/DependencyInjection/service.xml');
  107.         $loader->load('ParcelPacking/DependencyInjection/service.xml');
  108.         $loader->load('ParcelHydration/DependencyInjection/service.xml');
  109.         $loader->load('Shipment/DependencyInjection/controller.xml');
  110.         $loader->load('Shipment/DependencyInjection/model.xml');
  111.         $loader->load('Shipment/DependencyInjection/service.xml');
  112.         $containerBuilder->addCompilerPass(new CarrierAdapterRegistryCompilerPass());
  113.         // Register test services. Should never be loaded in production.
  114.         if (in_array(ShopwareIntegrationTestPlugin::class, $containerBuilder->getParameter('kernel.bundles'), true)) {
  115.             $loader->load('../test/TestEntityCreation/DependencyInjection/service.xml');
  116.         }
  117.     }
  118.     public function shutdown(): void
  119.     {
  120.         parent::shutdown();
  121.         // Shopware may reboot the kernel under certain circumstances (e.g. plugin un-/installation) within a single
  122.         // request. After the kernel was rebooted, our bundles have to be registered again.
  123.         // We reset the registration flag when the kernel is shut down. This will cause the bundles to be registered
  124.         // again in the (re)boot process.
  125.         self::$registered false;
  126.     }
  127.     public function install(InstallContext $installContext): void
  128.     {
  129.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  130.             ->install(self::ADDITIONAL_BUNDLES$installContext);
  131.     }
  132.     public function onAfterActivate(InstallContext $installContext): void
  133.     {
  134.         PickwareShippingBundleInstaller::createFromContainer($this->container)->install();
  135.         BundleInstaller::createForContainerAndClass($this->containerself::class)
  136.             ->onAfterActivate(self::ADDITIONAL_BUNDLES$installContext);
  137.     }
  138.     public function uninstall(UninstallContext $uninstallContext): void
  139.     {
  140.         if ($uninstallContext->keepUserData()) {
  141.             return;
  142.         }
  143.         DependencyAwareTableDropper::createForContainer($this->container)->dropTables([
  144.             'pickware_shipping_carrier',
  145.             'pickware_shipping_document_shipment_mapping',
  146.             'pickware_shipping_document_tracking_code_mapping',
  147.             'pickware_shipping_shipment',
  148.             'pickware_shipping_shipment_order_mapping',
  149.             'pickware_shipping_shipping_method_config',
  150.             'pickware_shipping_tracking_code',
  151.         ]);
  152.         // We need eight backslashes, as we need to match a single one and double the count for each of the following:
  153.         // 1. The PHP parser
  154.         // 2. The MySQL parser
  155.         // 3. The MySQL pattern matcher (only when using LIKE)
  156.         $this->container->get(Connection::class)
  157.             ->executeStatement("DELETE FROM `migration` WHERE `class` LIKE 'Pickware\\\\\\\\ShippingBundle\\\\\\\\%'");
  158.         PickwareShippingBundleInstaller::createFromContainer($this->container)->uninstall();
  159.         BundleInstaller::createForContainerAndClass($this->containerself::class)->uninstall($uninstallContext);
  160.     }
  161. }