custom/plugins/SwagEnterpriseSearchPlatform/src/SwagEnterpriseSearchPlatform.php line 18

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swag\EnterpriseSearch;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Swag\EnterpriseSearch\Boosting\EntityStream\DependencyInjection\CompilerPass\EntityStreamEntityIndexerCompilerPass;
  8. use Swag\EnterpriseSearch\Boosting\EntityStream\DependencyInjection\CompilerPass\EntityStreamTagCompilerPass;
  9. use Swag\EnterpriseSearch\Common\Exception\ElasticSearchNotEnabledException;
  10. use Swag\EnterpriseSearch\Common\VersionHelper;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  15. class SwagEnterpriseSearchPlatform extends Plugin
  16. {
  17.     public static function getDeprecationPath(): string
  18.     {
  19.         return __DIR__ '/deprecated.php';
  20.     }
  21.     public function build(ContainerBuilder $container): void
  22.     {
  23.         parent::build($container);
  24.         $container->setParameter('swag_ses_root_dir'$this->getPath());
  25.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  26.         $loader->load('services.xml');
  27.         $container->addCompilerPass(new EntityStreamTagCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1);
  28.         $container->addCompilerPass(new EntityStreamEntityIndexerCompilerPass());
  29.         $this->loadShopwareVersionServices($container$loader);
  30.     }
  31.     public function uninstall(UninstallContext $uninstallContext): void
  32.     {
  33.         parent::uninstall($uninstallContext);
  34.         if ($uninstallContext->keepUserData()) {
  35.             return;
  36.         }
  37.         /** @var Connection $connection */
  38.         $connection $this->container->get(Connection::class);
  39.         (new TearDown($connection))->dropTables();
  40.     }
  41.     /**
  42.      * @throws ElasticSearchNotEnabledException
  43.      */
  44.     public function activate(ActivateContext $activateContext): void
  45.     {
  46.         (new ActivationValidator($this->container))->validate();
  47.     }
  48.     protected function loadShopwareVersionServices(ContainerBuilder $containerXmlFileLoader $fileLoader): void
  49.     {
  50.         // Checks for version 6.3.1.0 or lower
  51.         if (!class_exists('Shopware\Core\Checkout\Customer\Event\CustomerGroupRegistrationAccepted')) {
  52.             $fileLoader->load('servicesLower631.xml');
  53.         }
  54.         if (!$container->has('Shopware\Core\Checkout\Cart\SalesChannel\CartLoadRoute')) {
  55.             $fileLoader->load('services62.xml');
  56.             return;
  57.         }
  58.         $fileLoader->load('services63.xml');
  59.         if (!VersionHelper::isShopware64X()) {
  60.             return;
  61.         }
  62.         $fileLoader->load('services64.xml');
  63.     }
  64. }
  65. require_once SwagEnterpriseSearchPlatform::getDeprecationPath();