Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate entry for key 'gf_versions_uniq_index' #2720

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
return $versions;
}

// Insert the entry in the DB for the current version.
// Insert or update the entry in the DB for the current version.
$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
Expand Down Expand Up @@ -131,23 +131,36 @@ private function getVersionsForFileFromDB(FileInfo $fileInfo, IUser $user, int $
$folder = $this->appFolder->get((string)$folderId);
$file = $folder->get($fileInfo->getInternalPath());

return array_map(
fn (GroupVersionEntity $versionEntity) => new GroupVersion(
$versionEntity->getTimestamp(),
$versionEntity->getTimestamp(),
$file->getName(),
$versionEntity->getSize(),
$this->mimeTypeLoader->getMimetypeById($versionEntity->getMimetype()),
$mountPoint->getInternalPath($file->getPath()),
$file,
$this,
$user,
$versionEntity->getLabel(),
$file->getMtime() === $versionEntity->getTimestamp() ? $file : $versionsFolder->get((string)$versionEntity->getTimestamp()),
$folderId,
),
$this->groupVersionsMapper->findAllVersionsForFileId($file->getId())
);
$versionEntities = $this->groupVersionsMapper->findAllVersionsForFileId($fileInfo->getId());
$versions = [];

foreach ($versionEntities as $versionEntity) {
try {
/** @var GroupVersionEntity $versionEntity */
$versions[] = new GroupVersion(
$versionEntity->getTimestamp(),
$versionEntity->getTimestamp(),
$file->getName(),
$versionEntity->getSize(),
$this->mimeTypeLoader->getMimetypeById($versionEntity->getMimetype()),
$mountPoint->getInternalPath($file->getPath()),
$file,
$this,
$user,
$versionEntity->getLabel(),
$file->getMtime() === $versionEntity->getTimestamp() ? $file : $versionsFolder->get((string)$versionEntity->getTimestamp()),
$folderId,
);
} catch (NotFoundException $e) {
continue;
}
}

if (!count($versions) && count($versionEntities)) {
throw new NotFoundException();
}

return $versions;
}

/**
Expand Down
Loading