vendor/shopware/core/Content/ImportExport/Event/Subscriber/FileDeletedSubscriber.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\ImportExport\Event\Subscriber;
  3. use Shopware\Core\Content\ImportExport\Aggregate\ImportExportFile\ImportExportFileEntity;
  4. use Shopware\Core\Content\ImportExport\Aggregate\ImportExportFile\ImportExportFileEvents;
  5. use Shopware\Core\Content\ImportExport\Aggregate\ImportExportLog\ImportExportLogEntity;
  6. use Shopware\Core\Content\ImportExport\Message\DeleteFileMessage;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
  8. use Shopware\Core\Framework\Log\Package;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\Messenger\MessageBusInterface;
  11. /**
  12.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  13.  */
  14. #[Package('system-settings')]
  15. class FileDeletedSubscriber implements EventSubscriberInterface
  16. {
  17.     private MessageBusInterface $messageBus;
  18.     /**
  19.      * @internal
  20.      */
  21.     public function __construct(MessageBusInterface $messageBus)
  22.     {
  23.         $this->messageBus $messageBus;
  24.     }
  25.     /**
  26.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  27.      */
  28.     public static function getSubscribedEvents()
  29.     {
  30.         return [ImportExportFileEvents::IMPORT_EXPORT_FILE_DELETED_EVENT => 'onFileDeleted'];
  31.     }
  32.     public function onFileDeleted(EntityDeletedEvent $event): void
  33.     {
  34.         $paths = [];
  35.         $activities = [
  36.             ImportExportLogEntity::ACTIVITY_IMPORT,
  37.             ImportExportLogEntity::ACTIVITY_DRYRUN,
  38.             ImportExportLogEntity::ACTIVITY_EXPORT,
  39.         ];
  40.         foreach ($event->getIds() as $fileId) {
  41.             $path ImportExportFileEntity::buildPath($fileId);
  42.             // since the file could be stored in any one directory of the available activities
  43.             foreach ($activities as $activitiy) {
  44.                 $paths[] = $activitiy '/' $path;
  45.                 // if file is not of an export there might be a log of invalid records
  46.                 if ($activitiy !== ImportExportLogEntity::ACTIVITY_EXPORT) {
  47.                     $paths[] = $activitiy '/' $path '_invalid';
  48.                 }
  49.             }
  50.         }
  51.         $message = new DeleteFileMessage();
  52.         $message->setFiles($paths);
  53.         $this->messageBus->dispatch($message);
  54.     }
  55. }