<?php declare(strict_types=1);
namespace Swag\EnterpriseSearch;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Swag\EnterpriseSearch\Boosting\EntityStream\DependencyInjection\CompilerPass\EntityStreamEntityIndexerCompilerPass;
use Swag\EnterpriseSearch\Boosting\EntityStream\DependencyInjection\CompilerPass\EntityStreamTagCompilerPass;
use Swag\EnterpriseSearch\Common\Exception\ElasticSearchNotEnabledException;
use Swag\EnterpriseSearch\Common\VersionHelper;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
class SwagEnterpriseSearchPlatform extends Plugin
{
public static function getDeprecationPath(): string
{
return __DIR__ . '/deprecated.php';
}
public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->setParameter('swag_ses_root_dir', $this->getPath());
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/DependencyInjection/'));
$loader->load('services.xml');
$container->addCompilerPass(new EntityStreamTagCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
$container->addCompilerPass(new EntityStreamEntityIndexerCompilerPass());
$this->loadShopwareVersionServices($container, $loader);
}
public function uninstall(UninstallContext $uninstallContext): void
{
parent::uninstall($uninstallContext);
if ($uninstallContext->keepUserData()) {
return;
}
/** @var Connection $connection */
$connection = $this->container->get(Connection::class);
(new TearDown($connection))->dropTables();
}
/**
* @throws ElasticSearchNotEnabledException
*/
public function activate(ActivateContext $activateContext): void
{
(new ActivationValidator($this->container))->validate();
}
protected function loadShopwareVersionServices(ContainerBuilder $container, XmlFileLoader $fileLoader): void
{
// Checks for version 6.3.1.0 or lower
if (!class_exists('Shopware\Core\Checkout\Customer\Event\CustomerGroupRegistrationAccepted')) {
$fileLoader->load('servicesLower631.xml');
}
if (!$container->has('Shopware\Core\Checkout\Cart\SalesChannel\CartLoadRoute')) {
$fileLoader->load('services62.xml');
return;
}
$fileLoader->load('services63.xml');
if (!VersionHelper::isShopware64X()) {
return;
}
$fileLoader->load('services64.xml');
}
}
require_once SwagEnterpriseSearchPlatform::getDeprecationPath();