diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-07-30 17:09:10 +0200 |
---|---|---|
committer | Andy Scherzinger <info@andy-scherzinger.de> | 2025-06-18 21:09:25 +0200 |
commit | 114eeec1de278ef3b8caaae3dc818d82c9c49b9c (patch) | |
tree | 89e9ef69d989cf9125fd7618e2d61c2ee0fbadbc | |
parent | 247a1e7e4ceb80a615b792818907f987c1c865c6 (diff) | |
download | nextcloud-server-backport/46887/stable29.tar.gz nextcloud-server-backport/46887/stable29.zip |
fix(files_versions): Catch constraint error on version insertionbackport/46887/stable29
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/files_versions/lib/Versions/LegacyVersionsBackend.php | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php index deb8833c87b..95a3063dc73 100644 --- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php +++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php @@ -246,7 +246,27 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend $versionEntity->setSize($file->getSize()); $versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype())); $versionEntity->setMetadata([]); - $this->versionsMapper->insert($versionEntity); + + $tries = 1; + while ($tries < 5) { + try { + $this->versionsMapper->insert($versionEntity); + /* No errors, get out of the method */ + return; + } catch (\OCP\DB\Exception $e) { + if (!in_array($e->getReason(), [ + \OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION, + \OCP\DB\Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION, + ]) + ) { + throw $e; + } + /* Conflict with another version, increase mtime and try again */ + $versionEntity->setTimestamp($versionEntity->getTimestamp() + 1); + $tries++; + $this->logger->warning('Constraint violation while inserting version, retrying with increased timestamp', ['exception' => $e]); + } + } } public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void { |