fileManager = $fileManager; $this->fileStorageFactory = $fileStorageFactory; $this->entityManager = $entityManager; } public function run(Data $data): void { $id = $data->getTargetId(); if (!$id) { throw new LogicException(); } /** @var Attachment|null $attachment */ $attachment = $this->entityManager->getEntityById(Attachment::ENTITY_TYPE, $id); if (!$attachment) { return; } if ($attachment->getStorage() === EspoUploadDir::NAME) { return; } $storage = $this->fileStorageFactory->create(EspoUploadDir::NAME); if (!$storage instanceof Local) { throw new LogicException(); } $filePath = $storage->getLocalFilePath( new AttachmentEntityWrapper($attachment) ); if (!$this->fileManager->isFile($filePath)) { return; } $this->fileManager->remove($filePath); } }