From eea81441fb9602d5c1b70a21b3ef89a9942cc9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 27 Aug 2019 13:15:18 +0200 Subject: [PATCH] Treat all attachments without a filepath as external --- src/Entity/Attachments/Attachment.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index ca88642b..d3508c35 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -27,6 +27,7 @@ use App\Entity\Base\DBElement; use App\Entity\Base\NamedDBElement; use App\Validator\Constraints\Selectable; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * Class Attachment. @@ -91,7 +92,10 @@ abstract class Attachment extends NamedDBElement */ public function isExternal() : bool { - return static::isUrl($this->getPath()); + //return static::isUrl($this->getPath()); + //Treat all pathes without a filepath as external + return (strpos($this->getPath(), "%MEDIA%") === false) + && (strpos($this->getPath(), "%BASE") === false); } /******************************************************************************** @@ -259,6 +263,12 @@ abstract class Attachment extends NamedDBElement return $this; } + /** + * Sets the url associated with this attachment. + * If the url is empty nothing is changed, to not override the file path. + * @param string|null $url + * @return Attachment + */ public function setURL(?string $url) : Attachment { //Only set if the URL is not empty @@ -266,6 +276,10 @@ abstract class Attachment extends NamedDBElement $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!"); + } + return $this; }