mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-04 23:44:33 +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
|
||||
{
|
||||
if ($event->hasChangedField('path')) {
|
||||
$old_path = $event->getOldValue('path');
|
||||
|
||||
//Dont delete file if the attachment uses a builtin ressource:
|
||||
if (Attachment::checkIfBuiltin($event->getOldValue('path'))) {
|
||||
if (Attachment::checkIfBuiltin($old_path)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue