]> source.dussan.org Git - nextcloud-server.git/commitdiff
refactor(files): Use functions for all in `occ files:cleanup` refactor/files-cleanup 49408/head
authorJosh <josh.t.richards@gmail.com>
Wed, 20 Nov 2024 18:01:00 +0000 (13:01 -0500)
committerJosh <josh.t.richards@gmail.com>
Wed, 20 Nov 2024 19:43:20 +0000 (14:43 -0500)
Tidying.

Signed-off-by: Josh <josh.t.richards@gmail.com>
apps/files/lib/Command/DeleteOrphanedFiles.php

index 966351e4da0628fe0af56249cc9327b868c79d8a..d07337594a10aefd57a0c4d98363157ad04207e4 100644 (file)
@@ -34,7 +34,6 @@ class DeleteOrphanedFiles extends Command {
        }
 
        public function execute(InputInterface $input, OutputInterface $output): int {
-               $deletedEntries = 0;
                $fileIdsByStorage = [];
 
                $deletedStorages = array_diff($this->getReferencedStorages(), $this->getExistingStorages());
@@ -44,16 +43,7 @@ class DeleteOrphanedFiles extends Command {
                        $fileIdsByStorage = $this->getFileIdsForStorages($deletedStorages);
                }
 
-               $deleteQuery = $this->connection->getQueryBuilder();
-               $deleteQuery->delete('filecache')
-                       ->where($deleteQuery->expr()->in('storage', $deleteQuery->createParameter('storage_ids')));
-
-               $deletedStorageChunks = array_chunk($deletedStorages, self::CHUNK_SIZE);
-               foreach ($deletedStorageChunks as $deletedStorageChunk) {
-                       $deleteQuery->setParameter('storage_ids', $deletedStorageChunk, IQueryBuilder::PARAM_INT_ARRAY);
-                       $deletedEntries += $deleteQuery->executeStatement();
-               }
-
+               $deletedEntries = $this->cleanupOrphanedFileCache($deletedStorages);
                $output->writeln("$deletedEntries orphaned file cache entries deleted");
 
                if ($deleteExtended) {
@@ -61,9 +51,9 @@ class DeleteOrphanedFiles extends Command {
                        $output->writeln("$deletedFileCacheExtended orphaned file cache extended entries deleted");
                }
 
-
                $deletedMounts = $this->cleanupOrphanedMounts();
                $output->writeln("$deletedMounts orphaned mount entries deleted");
+               
                return self::SUCCESS;
        }
 
@@ -106,6 +96,22 @@ class DeleteOrphanedFiles extends Command {
                return $result;
        }
 
+       private function cleanupOrphanedFileCache(array $deletedStorages): int {
+               $deletedEntries = 0;
+
+               $deleteQuery = $this->connection->getQueryBuilder();
+               $deleteQuery->delete('filecache')
+                       ->where($deleteQuery->expr()->in('storage', $deleteQuery->createParameter('storage_ids')));
+
+               $deletedStorageChunks = array_chunk($deletedStorages, self::CHUNK_SIZE);
+               foreach ($deletedStorageChunks as $deletedStorageChunk) {
+                       $deleteQuery->setParameter('storage_ids', $deletedStorageChunk, IQueryBuilder::PARAM_INT_ARRAY);
+                       $deletedEntries += $deleteQuery->executeStatement();
+               }
+
+               return $deletedEntries;
+       }
+       
        /**
         * @param array<int, int[]> $fileIdsByStorage
         * @return int