Skip to content

Commit

Permalink
fix: Also cleanup version metadata if expiring
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Aug 10, 2023
1 parent 5fcb19c commit e3bdb72
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/files_versions/lib/Storage.php
Expand Up @@ -914,7 +914,21 @@ public static function expire($filename, $uid) {

foreach ($toDelete as $key => $path) {
\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);

// Make sure to cleanup version table relations as expire does not pass deleteVersion
try {
/** @var VersionsMapper $versionsMapper */
$versionsMapper = \OC::$server->get(VersionsMapper::class);
$file = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->get($filename);
$pathparts = pathinfo($path);
$timestamp = (int)substr($pathparts['extension'] ?? '', 1);
$version = $versionsMapper->findVersionForFileId($file->getId(), $timestamp);
$versionsMapper->delete($version);
} catch (DoesNotExistException $e) {
}

self::deleteVersion($versionsFileview, $path);

\OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
unset($allVersions[$key]); // update array with the versions we keep
$logger->info('Expire: ' . $path, ['app' => 'files_versions']);
Expand Down

0 comments on commit e3bdb72

Please sign in to comment.