diff options
author | Julius Knorr <jus@bitgrid.net> | 2024-11-21 08:41:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-21 08:41:11 +0100 |
commit | 37936bc4049912610a99625e0ef2f7d780eaebc0 (patch) | |
tree | 573e549d7270a1577a088a11556ca3607449a010 /apps | |
parent | cbb937fa3260c6a445e5027fee288bd01380ddd1 (diff) | |
parent | b9cc4bab4d6b0729335e21dfaeabba99ebb05638 (diff) | |
download | nextcloud-server-37936bc4049912610a99625e0ef2f7d780eaebc0.tar.gz nextcloud-server-37936bc4049912610a99625e0ef2f7d780eaebc0.zip |
Merge pull request #49408 from nextcloud/refactor/files-cleanup
refactor(files): Use functions for all in `occ files:cleanup`
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/Command/DeleteOrphanedFiles.php | 30 |
1 files 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<int, int[]> $fileIdsByStorage * @return int |