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

@ -37,6 +37,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="class_name", type="string")
* @ORM\DiscriminatorMap({"PartDB\Part" = "PartAttachment", "Part" = "PartAttachment"})
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*
*/
abstract class Attachment extends NamedDBElement
@ -124,17 +125,6 @@ abstract class Attachment extends NamedDBElement
return $this->element;
}
/**
* Checks if the file in this attachement is existing. This works for files on the HDD, and for URLs
* (it's not checked if the ressource behind the URL is really existing).
*
* @return bool True if the file is existing.
*/
public function isFileExisting(): bool
{
return file_exists($this->getPath()) || static::isURL($this->getPath());
}
/**
* The URL to the external file.
* Returns null, if the file is not external.
@ -273,11 +263,11 @@ abstract class Attachment extends NamedDBElement
{
//Only set if the URL is not empty
if (!empty($url)) {
$this->path = $url;
}
if (strpos($url, '%BASE%') !== false || strpos($url, '%MEDIA%') !== false) {
throw new \InvalidArgumentException("You can not reference internal files via the url field! But nice try!");
}
if (strpos($url, '%BASE%') !== false || strpos($url, '%MEDIA%') !== false) {
throw new \InvalidArgumentException("You can not reference internal files via the url field! But nice try!");
$this->path = $url;
}
return $this;