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 initialisation of versions in the DB #38469

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ public static function expireOlderThanMaxForUser($uid) {

// Check that the version does not have a label.
$path = $versionsRoot->getRelativePath($info->getPath());
if ($path === null) {
throw new DoesNotExistException('Could not find relative path of (' . $info->getPath() . ')');
}

$node = $userFolder->get(substr($path, 0, -strlen('.v'.$version)));
try {
$versionEntity = $versionsMapper->findVersionForFileId($node->getId(), $version);
Expand Down
31 changes: 27 additions & 4 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,35 @@ public function useBackendForStorage(IStorage $storage): bool {

public function getVersionsForFile(IUser $user, FileInfo $file): array {
$storage = $file->getStorage();

if ($storage->instanceOfStorage(SharedStorage::class)) {
$owner = $storage->getOwner('');
$user = $this->userManager->get($owner);

$fileId = $file->getId();
if ($fileId === null) {
throw new NotFoundException("File not found ($fileId)");
}

if ($user === null) {
throw new NotFoundException("User $owner not found for $fileId");
}

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

$nodes = $userFolder->getById($fileId);
$file = array_pop($nodes);

if (!$file) {
throw new NotFoundException("version file not found for share owner");
}
} else {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
}

$fileId = $file->getId();
if ($fileId === null) {
throw new NotFoundException("File not found ($fileId)");
}
artonge marked this conversation as resolved.
Show resolved Hide resolved

$versions = $this->getVersionsForFileFromDB($file, $user);
Expand All @@ -87,18 +105,23 @@ public function getVersionsForFile(IUser $user, FileInfo $file): array {

// Insert the entry in the DB for the current version.
$versionEntity = new VersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setFileId($fileId);
$versionEntity->setTimestamp($file->getMTime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setMetadata([]);
$this->versionsMapper->insert($versionEntity);

// Insert entries in the DB for existing versions.
$versionsOnFS = Storage::getVersions($user->getUID(), $userFolder->getRelativePath($file->getPath()));
$relativePath = $userFolder->getRelativePath($file->getPath());
if ($relativePath === null) {
throw new NotFoundException("Relative path not found for file $fileId (" . $file->getPath() . ')');
}

$versionsOnFS = Storage::getVersions($user->getUID(), $relativePath);
foreach ($versionsOnFS as $version) {
$versionEntity = new VersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setFileId($fileId);
$versionEntity->setTimestamp((int)$version['version']);
$versionEntity->setSize((int)$version['size']);
$versionEntity->setMimetype($this->mimeTypeLoader->getId($version['mimetype']));
Expand Down