mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 18:34:32 +02:00
Treat all attachments without a filepath as external
This commit is contained in:
parent
09a5948149
commit
eea81441fb
1 changed files with 15 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue