aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-06-13 22:10:13 +0200
committerJulius Härtl <jus@bitgrid.net>2023-06-13 22:10:13 +0200
commite76c96be5c480dd730d8c9a7e7bf772517591779 (patch)
tree3af0d4cd57f240be2704b2c8bee65d2a2acbb1e3 /apps/files_versions/lib
parent69f6585e3604792587ae917d78a7bcec9e05f61b (diff)
downloadnextcloud-server-e76c96be5c480dd730d8c9a7e7bf772517591779.tar.gz
nextcloud-server-e76c96be5c480dd730d8c9a7e7bf772517591779.zip
fix: Avoid failing to update the current version entry if there is none
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files_versions/lib')
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php17
1 files 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()]);