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 <[email protected]>
  • Loading branch information
juliusknorr committed Aug 10, 2023
1 parent 5fcb19c commit 26c7cda
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/files_versions/lib/Storage.php
Original file line number Diff line number Diff line change
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 = substr($pathparts['extension'] ?? '', 1);
$version = $versionsMapper->findVersionForFileId($file->getId(), $timestamp);

Check failure on line 925 in apps/files_versions/lib/Storage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/files_versions/lib/Storage.php:925:71: InvalidScalarArgument: Argument 2 of OCA\Files_Versions\Db\VersionsMapper::findVersionForFileId expects int, but string provided (see https://psalm.dev/012)

Check failure

Code scanning / Psalm

InvalidScalarArgument Error

Argument 2 of OCA\Files_Versions\Db\VersionsMapper::findVersionForFileId expects int, but string provided
$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 26c7cda

Please sign in to comment.