<?php declare(strict_types=1);
namespace CogiGlossary\Core;
use CogiGlossary\Glossary\GlossaryIndexerEvent;
use Doctrine\DBAL\Connection;
use Shopware\Core\Content\Seo\SeoUrlUpdater;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Unirest\Exception;
class SeoUrlUpdateListener implements EventSubscriberInterface
{
/**
* @var SeoUrlUpdater
*/
private $seoUrlUpdater;
/**
* @var Connection
*/
private $connection;
/**
* @var EntityIndexerRegistry
*/
private $indexerRegistry;
public function __construct(SeoUrlUpdater $seoUrlUpdater, Connection $connection, EntityIndexerRegistry $indexerRegistry)
{
$this->seoUrlUpdater = $seoUrlUpdater;
$this->connection = $connection;
$this->indexerRegistry = $indexerRegistry;
}
public static function getSubscribedEvents()
{
return [
GlossaryIndexerEvent::class => 'updateGlossaryUrls'
];
}
public function updateGlossaryUrls(GlossaryIndexerEvent $event): void
{
$ids = $event->getIds();
$this->seoUrlUpdater->update(GlossaryCharSeoUrlRoute::ROUTE_NAME, $ids);
$this->seoUrlUpdater->update(GlossaryEntrySeoUrlRoute::ROUTE_NAME, $ids);
}
}