Merge pull request #52806 from nextcloud/backport/52694/stable31

pull/52815/head
Louis 2025-05-16 16:23:53 +07:00 committed by GitHub
commit 84c528f64b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

@ -367,16 +367,20 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
* @inheritdoc
*/
public function clearVersionsForFile(IUser $user, Node $source, Node $target): void {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$userId = $user->getUID();
$userFolder = $this->rootFolder->getUserFolder($userId);
$relativePath = $userFolder->getRelativePath($source->getPath());
if ($relativePath === null) {
throw new Exception('Relative path not found for node with path: ' . $source->getPath());
}
$versions = Storage::getVersions($user->getUID(), $relativePath);
/** @var Folder versionFolder */
$versionFolder = $this->rootFolder->get('admin/files_versions');
$versionFolder = $this->rootFolder->get($userId . '/files_versions');
if (!$versionFolder instanceof Folder) {
throw new Exception('User versions folder does not exist');
}
$versions = Storage::getVersions($userId, $relativePath);
foreach ($versions as $version) {
$versionFolder->get($version['path'] . '.v' . (int)$version['version'])->delete();
}