Delete the file associated with an attachment after an attachment is delted or changed.

This commit is contained in:
Jan Böhmer 2019-08-27 22:24:56 +02:00
parent 87527dfdc6
commit 6b87823d5e
5 changed files with 135 additions and 17 deletions

View file

@ -34,10 +34,8 @@ namespace App\Services;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\PartAttachment;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpKernel\KernelInterface;
@ -71,6 +69,21 @@ class AttachmentHelper
return $this->base_path;
}
/**
* Gets an SPLFileInfo object representing the file associated with the attachment.
* @param Attachment $attachment The attachment for which the file should be generated
* @return \SplFileInfo|null The fileinfo for the attachment file. Null, if the attachment is external or has
* invalid file.
*/
public function attachmentToFile(Attachment $attachment) : ?\SplFileInfo
{
if ($attachment->isExternal() || !$this->isFileExisting($attachment)) {
return null;
}
return new \SplFileInfo($this->toAbsoluteFilePath($attachment));
}
/**
* Converts an relative placeholder filepath (with %MEDIA% or older %BASE%) to an absolute filepath on disk.
* @param string $placeholder_path The filepath with placeholder for which the real path should be determined.