aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-04-23 16:03:20 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2025-04-24 11:31:13 +0000
commit378eb64d8eab866ebcf96eeafe796ff39f7a4de5 (patch)
tree3475d363888e494f702dd184cdde5ee6d51549a7
parentc05d7b984d40b5baf5b697945af28d4c36e64395 (diff)
downloadnextcloud-server-backport/52373/stable30.tar.gz
nextcloud-server-backport/52373/stable30.zip
fix(files_versions): create version if previous does not existbackport/52373/stable30
This issue happens reproducible if: - Versions is disabled - Upload a file - Enable versions - Upload same file unchanged - Now the error happens. Problem is that the mtime is unchanged so no version will be created on the upload, but it tries to update the last version which does not exists. Instead of "upload same file unchanged" you can also - like in the example stack trace above - use Android with an SD card with invalid mtime -> the mtime will be stripped so its always the same. Instead of disable versions the same also happens if e.g. the versions creation failed due to other issues. The solution now is to catch the exception and create if not exists. A cleaner solution would be to have a method on the versions backend like `hasVersionEntity(File $file, int $revision): bool` but this would be a breaking change or at least a feature that apps need to implement. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php13
1 files changed, 11 insertions, 2 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 49150f4e726..c581c61b4ae 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -196,8 +196,8 @@ class FileEventsListener implements IEventListener {
}
if (
- $writeHookInfo['versionCreated'] &&
- $node->getMTime() !== $writeHookInfo['previousNode']->getMTime()
+ $writeHookInfo['versionCreated']
+ && $node->getMTime() !== $writeHookInfo['previousNode']->getMTime()
) {
// If a new version was created, insert a version in the DB for the current content.
// If both versions have the same mtime, it means the latest version file simply got overrode,
@@ -218,6 +218,15 @@ class FileEventsListener implements IEventListener {
],
);
}
+ } catch (DoesNotExistException $e) {
+ // This happens if the versions app was not enabled while the file was created or updated the last time.
+ // meaning there is no such revision and we need to create this file.
+ if ($writeHookInfo['versionCreated']) {
+ $this->created($node);
+ } else {
+ // Normally this should not happen so we re-throw the exception to not hide any potential issues.
+ throw $e;
+ }
} catch (Exception $e) {
$this->logger->error('Failed to update existing version for ' . $node->getPath(), [
'exception' => $e,