]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Avoid failing to update the current version entry if there is none
authorJulius Härtl <jus@bitgrid.net>
Tue, 13 Jun 2023 20:10:13 +0000 (22:10 +0200)
committerJulius Härtl <jus@bitgrid.net>
Tue, 13 Jun 2023 20:10:13 +0000 (22:10 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/files_versions/lib/Listener/FileEventsListener.php

index 76590733e26833478bdb3e2a6dbdcd8ac73bac30..082c88295cb4369fddf07068cb9a2ec7dfbd3fe2 100644 (file)
@@ -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()]);