<?php
/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/
namespace Pimcore\Bundle\DataHubSimpleRestBundle\EventSubscriber;
use Pimcore\Bundle\DataHubBundle\Configuration;
use Pimcore\Bundle\DataHubBundle\Event\ConfigurationEvents;
use Pimcore\Bundle\DataHubSimpleRestBundle\Service\IndexService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class ConfigurationEventSubscriber implements EventSubscriberInterface
{
/**
* @var IndexService
*/
protected $indexService;
/**
* @param IndexService $indexService
*/
public function __construct(IndexService $indexService)
{
$this->indexService = $indexService;
}
public static function getSubscribedEvents()
{
return [
ConfigurationEvents::CONFIGURATION_POST_DELETE => 'postDelete'
];
}
/**
* @param GenericEvent $event
*
* @throws \Doctrine\DBAL\DBALException
*/
public function postDelete(GenericEvent $event)
{
/**
* @var $config Configuration
*/
$config = $event->getSubject();
//TODO move this to config once more similar adapters are implemented
if (in_array($config->getType(), ['simpleRest', 'ciHub'])) {
$this->indexService->cleanupIndicesForConfig($config->getName());
}
}
}