From e045faa6a76850940a93459dbc4b6e016ada8629 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Tue, 13 Jun 2023 22:10:13 +0200 Subject: [PATCH] fix: Avoid failing to update the current version entry if there is none MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/Listener/FileEventsListener.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php index 76590733e26..082c88295cb 100644 --- a/apps/files_versions/lib/Listener/FileEventsListener.php +++ b/apps/files_versions/lib/Listener/FileEventsListener.php @@ -239,11 +239,18 @@ class FileEventsListener implements IEventListener { } else { // If no new version was stored in the FS, no new version should be added in the DB. // So we simply update the associated version. - $currentVersionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $writeHookInfo['previousNode']->getMtime()); - $currentVersionEntity->setTimestamp($node->getMTime()); - $currentVersionEntity->setSize($node->getSize()); - $currentVersionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype())); - $this->versionsMapper->update($currentVersionEntity); + try { + $currentVersionEntity = $this->versionsMapper->findVersionForFileId($node->getId(), $writeHookInfo['previousNode']->getMtime()); + $currentVersionEntity->setTimestamp($node->getMTime()); + $currentVersionEntity->setSize($node->getSize()); + $currentVersionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype())); + $this->versionsMapper->update($currentVersionEntity); + } catch (DoesNotExistException) { + // There might be cases where the current version entry doesn't exist, + // e.g. if none was written due to an empty file or from before the versions table was introduced + // We just create the initial version entry then for the current entity + $this->created($node); + } } unset($this->writeHookInfo[$node->getId()]); -- 2.39.5