<?php declare(strict_types=1);
namespace Shopware\Core\Content\ImportExport\Event\Subscriber;
use Shopware\Core\Content\ImportExport\Aggregate\ImportExportFile\ImportExportFileEntity;
use Shopware\Core\Content\ImportExport\Aggregate\ImportExportFile\ImportExportFileEvents;
use Shopware\Core\Content\ImportExport\Message\DeleteFileMessage;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
class FileDeletedSubscriber implements EventSubscriberInterface
{
/**
* @var MessageBusInterface
*/
private $messageBus;
public function __construct(MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}
public static function getSubscribedEvents()
{
return [ImportExportFileEvents::IMPORT_EXPORT_FILE_DELETED_EVENT => 'onFileDeleted'];
}
public function onFileDeleted(EntityDeletedEvent $event): void
{
$paths = [];
foreach ($event->getIds() as $fileId) {
$paths[] = ImportExportFileEntity::buildPath($fileId);
}
$message = new DeleteFileMessage();
$message->setFiles($paths);
$this->messageBus->dispatch($message);
}
}