Skip to content

Commit 37936bc

Browse files
authored
Merge pull request #49408 from nextcloud/refactor/files-cleanup
refactor(files): Use functions for all in `occ files:cleanup`
2 parents cbb937f + b9cc4ba commit 37936bc

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

apps/files/lib/Command/DeleteOrphanedFiles.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ protected function configure(): void {
3434
}
3535

3636
public function execute(InputInterface $input, OutputInterface $output): int {
37-
$deletedEntries = 0;
3837
$fileIdsByStorage = [];
3938

4039
$deletedStorages = array_diff($this->getReferencedStorages(), $this->getExistingStorages());
@@ -44,26 +43,17 @@ public function execute(InputInterface $input, OutputInterface $output): int {
4443
$fileIdsByStorage = $this->getFileIdsForStorages($deletedStorages);
4544
}
4645

47-
$deleteQuery = $this->connection->getQueryBuilder();
48-
$deleteQuery->delete('filecache')
49-
->where($deleteQuery->expr()->in('storage', $deleteQuery->createParameter('storage_ids')));
50-
51-
$deletedStorageChunks = array_chunk($deletedStorages, self::CHUNK_SIZE);
52-
foreach ($deletedStorageChunks as $deletedStorageChunk) {
53-
$deleteQuery->setParameter('storage_ids', $deletedStorageChunk, IQueryBuilder::PARAM_INT_ARRAY);
54-
$deletedEntries += $deleteQuery->executeStatement();
55-
}
56-
46+
$deletedEntries = $this->cleanupOrphanedFileCache($deletedStorages);
5747
$output->writeln("$deletedEntries orphaned file cache entries deleted");
5848

5949
if ($deleteExtended) {
6050
$deletedFileCacheExtended = $this->cleanupOrphanedFileCacheExtended($fileIdsByStorage);
6151
$output->writeln("$deletedFileCacheExtended orphaned file cache extended entries deleted");
6252
}
6353

64-
6554
$deletedMounts = $this->cleanupOrphanedMounts();
6655
$output->writeln("$deletedMounts orphaned mount entries deleted");
56+
6757
return self::SUCCESS;
6858
}
6959

@@ -106,6 +96,22 @@ private function getFileIdsForStorages(array $storageIds): array {
10696
return $result;
10797
}
10898

99+
private function cleanupOrphanedFileCache(array $deletedStorages): int {
100+
$deletedEntries = 0;
101+
102+
$deleteQuery = $this->connection->getQueryBuilder();
103+
$deleteQuery->delete('filecache')
104+
->where($deleteQuery->expr()->in('storage', $deleteQuery->createParameter('storage_ids')));
105+
106+
$deletedStorageChunks = array_chunk($deletedStorages, self::CHUNK_SIZE);
107+
foreach ($deletedStorageChunks as $deletedStorageChunk) {
108+
$deleteQuery->setParameter('storage_ids', $deletedStorageChunk, IQueryBuilder::PARAM_INT_ARRAY);
109+
$deletedEntries += $deleteQuery->executeStatement();
110+
}
111+
112+
return $deletedEntries;
113+
}
114+
109115
/**
110116
* @param array<int, int[]> $fileIdsByStorage
111117
* @return int

0 commit comments

Comments
 (0)