Add removal of mounts without storages to files:cleanup command
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
09b9f94c38
commit
479aa975d3
|
@ -78,6 +78,39 @@ class DeleteOrphanedFiles extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln("$deletedEntries orphaned file cache entries deleted");
|
$output->writeln("$deletedEntries orphaned file cache entries deleted");
|
||||||
|
|
||||||
|
$deletedMounts = $this->cleanupOrphanedMounts();
|
||||||
|
$output->writeln("$deletedMounts orphaned mount entries deleted");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cleanupOrphanedMounts() {
|
||||||
|
$deletedEntries = 0;
|
||||||
|
|
||||||
|
$query = $this->connection->getQueryBuilder();
|
||||||
|
$query->select('m.storage_id')
|
||||||
|
->from('mounts', 'm')
|
||||||
|
->where($query->expr()->isNull('s.numeric_id'))
|
||||||
|
->leftJoin('m', 'storages', 's', $query->expr()->eq('m.storage_id', 's.numeric_id'))
|
||||||
|
->groupBy('storage_id')
|
||||||
|
->setMaxResults(self::CHUNK_SIZE);
|
||||||
|
|
||||||
|
$deleteQuery = $this->connection->getQueryBuilder();
|
||||||
|
$deleteQuery->delete('mounts')
|
||||||
|
->where($deleteQuery->expr()->eq('storage_id', $deleteQuery->createParameter('storageid')));
|
||||||
|
|
||||||
|
$deletedInLastChunk = self::CHUNK_SIZE;
|
||||||
|
while ($deletedInLastChunk === self::CHUNK_SIZE) {
|
||||||
|
$deletedInLastChunk = 0;
|
||||||
|
$result = $query->execute();
|
||||||
|
while ($row = $result->fetch()) {
|
||||||
|
$deletedInLastChunk++;
|
||||||
|
$deletedEntries += $deleteQuery->setParameter('storageid', (int) $row['storage_id'])
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
$result->closeCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $deletedEntries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue