]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Also cleanup version metadata if expiring 39874/head
authorJulius Härtl <jus@bitgrid.net>
Thu, 10 Aug 2023 07:26:12 +0000 (09:26 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 14 Aug 2023 21:07:35 +0000 (21:07 +0000)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/files_versions/lib/Storage.php

index 676d94d2fb72a94cf4e54bad7c1580f68f7750db..426d5931ba9d5d4cff201d95740a2ecd267d9bd9 100644 (file)
@@ -913,6 +913,21 @@ class Storage {
                        }
 
                        foreach ($toDelete as $key => $path) {
+                               // 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);
+                                       $versionEntity = $versionsMapper->findVersionForFileId($file->getId(), $timestamp);
+                                       if ($versionEntity->getLabel() !== '') {
+                                               continue;
+                                       }
+                                       $versionsMapper->delete($versionEntity);
+                               } catch (DoesNotExistException $e) {
+                               }
+
                                \OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
                                self::deleteVersion($versionsFileview, $path);
                                \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);