mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-03 06:54:34 +02:00
Fixed exception when uploading a file.
This commit is contained in:
parent
41df76e8e6
commit
9769915b34
1 changed files with 11 additions and 2 deletions
|
@ -77,12 +77,21 @@ class AttachmentDeleteListener
|
||||||
public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event): void
|
public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event): void
|
||||||
{
|
{
|
||||||
if ($event->hasChangedField('path')) {
|
if ($event->hasChangedField('path')) {
|
||||||
|
$old_path = $event->getOldValue('path');
|
||||||
|
|
||||||
//Dont delete file if the attachment uses a builtin ressource:
|
//Dont delete file if the attachment uses a builtin ressource:
|
||||||
if (Attachment::checkIfBuiltin($event->getOldValue('path'))) {
|
if (Attachment::checkIfBuiltin($old_path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = new SplFileInfo($this->pathResolver->placeholderToRealPath($event->getOldValue('path')));
|
$real_path = $this->pathResolver->placeholderToRealPath($old_path);
|
||||||
|
|
||||||
|
//If the attachment does not point to a valid file, ignore it!
|
||||||
|
if ($real_path === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = new SplFileInfo($real_path);
|
||||||
$this->attachmentReverseSearch->deleteIfNotUsed($file);
|
$this->attachmentReverseSearch->deleteIfNotUsed($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue