From: Julius Härtl Date: Tue, 13 Jun 2023 20:10:13 +0000 (+0200) Subject: fix: Avoid failing to update the current version entry if there is none X-Git-Tag: v26.0.4rc1~3^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e045faa6a76850940a93459dbc4b6e016ada8629;p=nextcloud-server.git fix: Avoid failing to update the current version entry if there is none Signed-off-by: Julius Härtl --- 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()]);