mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-08 01:14:34 +02:00
Fix exception if uploading a new file for an already existing attachment
This commit is contained in:
parent
eb30fb6e83
commit
08bd4d54e3
1 changed files with 21 additions and 5 deletions
|
@ -143,19 +143,35 @@ class AttachmentSubmitHandler
|
|||
{
|
||||
$base_path = $secure_upload ? $this->pathResolver->getSecurePath() : $this->pathResolver->getMediaPath();
|
||||
|
||||
//Ensure the given attachment class is known to mapping
|
||||
if (!isset($this->folder_mapping[$attachment::class])) {
|
||||
throw new InvalidArgumentException('The given attachment class is not known! The passed class was: '.$attachment::class);
|
||||
}
|
||||
//Ensure the attachment has an assigned element
|
||||
if (!$attachment->getElement() instanceof AttachmentContainingDBElement) {
|
||||
throw new InvalidArgumentException('The given attachment is not assigned to an element! An element is needed to generate a path!');
|
||||
}
|
||||
|
||||
//Determine the folder prefix for the given attachment class:
|
||||
$prefix = null;
|
||||
//Check if we can use the class name dire
|
||||
if (isset($this->folder_mapping[$attachment::class])) {
|
||||
$prefix = $this->folder_mapping[$attachment::class];
|
||||
} else {
|
||||
//If not, check for instance of:
|
||||
foreach ($this->folder_mapping as $class => $folder) {
|
||||
if ($attachment instanceof $class) {
|
||||
$prefix = $folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Ensure the given attachment class is known to mapping
|
||||
if (!$prefix) {
|
||||
throw new InvalidArgumentException('The given attachment class is not known! The passed class was: '.$attachment::class);
|
||||
}
|
||||
|
||||
//Build path
|
||||
return
|
||||
$base_path.DIRECTORY_SEPARATOR //Base path
|
||||
.$this->folder_mapping[$attachment::class].DIRECTORY_SEPARATOR.$attachment->getElement()->getID();
|
||||
.$prefix.DIRECTORY_SEPARATOR.$attachment->getElement()->getID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue