From b9cc4bab4d6b0729335e21dfaeabba99ebb05638 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 20 Nov 2024 13:01:00 -0500 Subject: [PATCH] refactor(files): Use functions for all in `occ files:cleanup` Tidying. Signed-off-by: Josh --- .../files/lib/Command/DeleteOrphanedFiles.php | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/files/lib/Command/DeleteOrphanedFiles.php b/apps/files/lib/Command/DeleteOrphanedFiles.php index 966351e4da0..d07337594a1 100644 --- a/apps/files/lib/Command/DeleteOrphanedFiles.php +++ b/apps/files/lib/Command/DeleteOrphanedFiles.php @@ -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 $fileIdsByStorage * @return int -- 2.39.5