<?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\DataHubFileExportBundle\EventSubscriber;
use Pimcore\Bundle\DataHubBundle\Configuration;
use Pimcore\Bundle\DataHubBundle\Event\ConfigurationEvents;
use Pimcore\Bundle\DataHubFileExportBundle\Exporter\File;
use Symfony\Component\EventDispatcher\EventSubscriberInterface as EventSubscriberInterfaceAlias;
use Symfony\Component\EventDispatcher\GenericEvent;
class ConfigurationEventSubscriber implements EventSubscriberInterfaceAlias
{
/**
* @return string[]
*/
public static function getSubscribedEvents()
{
return [
ConfigurationEvents::CONFIGURATION_POST_DELETE => 'postDelete'
];
}
public function postDelete(GenericEvent $event)
{
/**
* @var Configuration $config
*/
$config = $event->getSubject();
if ($config->getType() === 'fileExport') {
$name = $config->getName();
$downloadFile = PIMCORE_PRIVATE_VAR . '/data-hub/file-export/' . $name . '.out';
if (file_exists($downloadFile)) {
unlink($downloadFile);
}
$exporter = \Pimcore\Bundle\DataHubFileExportBundle\Helper::getExporterService($config);
if ($exporter instanceof File) {
$folder = $exporter->getExporter()->getTmpDir();
if (is_dir($folder)) {
rmdir($folder);
}
}
}
}
}