Skip to content

Commit ee683a2

Browse files
solracsfmejo-
authored andcommitted
fix(versions): Add error handling for missing version entity
Handle missing version entity gracefully by creating a new one. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent ea4779c commit ee683a2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Versions/VersionsBackend.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OCA\Files_Versions\Versions\IVersion;
2323
use OCA\Files_Versions\Versions\IVersionBackend;
2424
use OCA\Files_Versions\Versions\IVersionsImporterBackend;
25+
use OCP\AppFramework\Db\DoesNotExistException;
2526
use OCP\Constants;
2627
use OCP\Files\File;
2728
use OCP\Files\FileInfo;
@@ -392,7 +393,15 @@ public function createVersionEntity(File $file): void {
392393
}
393394

394395
public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void {
395-
$versionEntity = $this->collectiveVersionMapper->findVersionForFileId($sourceFile->getId(), $revision);
396+
try {
397+
$versionEntity = $this->collectiveVersionMapper->findVersionForFileId($sourceFile->getId(), $revision);
398+
} catch (DoesNotExistException $e) {
399+
// The version entity can be missing when a file is written immediately
400+
// after being copied (e.g. by the Text app's NodeCopiedListener clearing
401+
// attachment IDs). Fall back to creation to stay consistent.
402+
$this->createVersionEntity($sourceFile);
403+
return;
404+
}
396405

397406
if (isset($properties['timestamp'])) {
398407
$versionEntity->setTimestamp($properties['timestamp']);

0 commit comments

Comments
 (0)