Skip to content

Commit

Permalink
fix: duplicate entry for key 'gf_versions_uniq_index'
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Jan 5, 2024
1 parent 2fb1bae commit 4bfc96e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Files_Versions\Versions\IVersionBackend;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCA\GroupFolders\Mount\MountProvider;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Constants;
use OCP\Files\File;
Expand Down Expand Up @@ -78,14 +79,22 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
return $versions;
}

// Insert the entry in the DB for the current version.
$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);
// Insert or update the entry in the DB for the current version.
try {
$versionEntity = $this->groupVersionsMapper->findVersionForFileId($file->getId(), $file->getMtime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->update($versionEntity);
} catch (DoesNotExistException) {
$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);
}

// Insert entries in the DB for existing versions.
$versionsOnFS = $versionsFolder->getDirectoryListing();
Expand Down

0 comments on commit 4bfc96e

Please sign in to comment.