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

Drop need of user folder #2677

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
32 changes: 16 additions & 16 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
/** @var Folder $versionsFolder */
$versionsFolder = $this->getVersionsFolder($mount->getFolderId())->get((string)$file->getId());

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$nodes = $userFolder->getById($file->getId());
$node = array_pop($nodes);

$versions = $this->getVersionsForFileFromDB($file, $user, $folderId);

// Early exit if we find any version in the database.
Expand All @@ -84,10 +80,10 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {

// Insert the entry in the DB for the current version.
$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($node->getId());
$versionEntity->setTimestamp($node->getMTime());
$versionEntity->setSize($node->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype()));
$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);

Expand All @@ -99,25 +95,25 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
}

$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($node->getId());
$versionEntity->setFileId($file->getId());
// HACK: before this commit, versions were created with the current timestamp instead of the version's mtime.
// This means that the name of some versions is the exact mtime of the next version. This behavior is now fixed.
// To prevent occasional conflicts between the last version and the current one, we decrement the last version mtime.
$mtime = (int)$version->getName();
if ($mtime === $node->getMTime()) {
if ($mtime === $file->getMTime()) {
$versionEntity->setTimestamp($mtime - 1);
$version->move($version->getParent()->getPath() . '/' . ($mtime - 1));
} else {
$versionEntity->setTimestamp($mtime);
}
$versionEntity->setSize($version->getSize());
// Use the main file mimetype for this initialization as the original mimetype is unknown.
$versionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype()));
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);
}

return $this->getVersionsForFileFromDB($node, $user, $folderId);
return $this->getVersionsForFileFromDB($file, $user, $folderId);
} catch (NotFoundException $e) {
return [];
}
Expand All @@ -126,10 +122,14 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {
/**
* @return IVersion[]
*/
private function getVersionsForFileFromDB(FileInfo $file, IUser $user, int $folderId): array {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
private function getVersionsForFileFromDB(FileInfo $fileInfo, IUser $user, int $folderId): array {
/** @var GroupMountPoint $versionsFolder */
$mountPoint = $fileInfo->getMountPoint();
/** @var Folder $versionsFolder */
$versionsFolder = $this->getVersionsFolder($folderId)->get((string)$file->getId());
$versionsFolder = $this->getVersionsFolder($folderId)->get((string)$fileInfo->getId());
/** @var Folder */
$folder = $this->appFolder->get((string)$folderId);
$file = $folder->get($fileInfo->getInternalPath());

return array_map(
fn (GroupVersionEntity $versionEntity) => new GroupVersion(
Expand All @@ -138,7 +138,7 @@ private function getVersionsForFileFromDB(FileInfo $file, IUser $user, int $fold
$file->getName(),
$versionEntity->getSize(),
$this->mimeTypeLoader->getMimetypeById($versionEntity->getMimetype()),
$userFolder->getRelativePath($file->getPath()),
$mountPoint->getInternalPath($file->getPath()),
$file,
$this,
$user,
Expand Down
Loading