Merge pull request #52373 from nextcloud/fix/files-version-creation

fix(files_versions): create version if previous does not exist
pull/51309/head
Ferdinand Thiessen 2025-04-24 13:30:49 +07:00 committed by GitHub
commit 0051db7a43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 2 deletions

@ -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,