diff --git a/maintenance/checkSwiftContainers.php b/maintenance/checkSwiftContainers.php index 379cf732..6f110222 100644 --- a/maintenance/checkSwiftContainers.php +++ b/maintenance/checkSwiftContainers.php @@ -40,9 +40,9 @@ public function __construct() { parent::__construct(); $this->addDescription( 'Check for swift containers without matching entries in cw_wikis and optionally delete them.' ); - $this->addOption( 'container', 'Check only certain container types.' ); $this->addOption( 'delete', 'Delete containers without matching entries in cw_wikis.', false, false ); $this->addOption( 'estimate', 'Show the total storage size that would be saved without deleting.', false, false ); + $this->addOption( 'zone', 'Check/delete only a certain zone.' ); $this->requireExtension( 'CreateWiki' ); } @@ -65,12 +65,12 @@ public function execute(): void { $this->output( " - $container\n" ); } - $this->output( "Unique container counts:\n" ); - foreach ( $missingData['uniqueContainerCounts'] as $container => $count ) { - $this->output( "$container: $count\n" ); + $this->output( "Unique zone counts:\n" ); + foreach ( $missingData['uniqueZoneCounts'] as $zone => $count ) { + $this->output( "$zone: $count\n" ); } - $totalContainersCount = array_sum( $missingData['uniqueContainerCounts'] ); + $totalContainersCount = array_sum( $missingData['uniqueZoneCounts'] ); $this->output( "Total containers count: $totalContainersCount\n" ); $totalWikiCount = array_sum( $missingData['uniqueWikiCounts'] ); @@ -140,17 +140,17 @@ private function findUnmatchedContainers( array $containers ): array { $suffix = $this->getConfig()->get( 'CreateWikiDatabaseSuffix' ); - $containerOption = $this->getOption( 'container', false ); + $zoneOption = $this->getOption( 'zone', false ); $missingContainers = []; - $uniqueContainerCounts = []; $uniqueWikiCounts = []; + $uniqueZoneCounts = []; foreach ( $containers as $container ) { if ( preg_match( '/^miraheze-([^-]+' . preg_quote( $suffix ) . ')-(.+)$/', $container, $matches ) ) { - $dbName = $matches[1]; - $containerName = $matches[2]; + $dbname = $matches[1]; + $zoneName = $matches[2]; - if ( $containerOption && $containerName !== $containerOption ) { + if ( $zoneOption && $zoneName !== $zoneOption ) { continue; } @@ -158,7 +158,7 @@ private function findUnmatchedContainers( array $containers ): array { $result = $dbr->newSelectQueryBuilder() ->select( [ 'wiki_dbname' ] ) ->from( 'cw_wikis' ) - ->where( [ 'wiki_dbname' => $dbName ] ) + ->where( [ 'wiki_dbname' => $dbname ] ) ->caller( __METHOD__ ) ->fetchRow(); @@ -166,14 +166,14 @@ private function findUnmatchedContainers( array $containers ): array { if ( !$result ) { $missingContainers[] = $container; - if ( !isset( $uniqueContainerCounts[$containerName] ) ) { - $uniqueContainerCounts[$containerName] = 0; + if ( !isset( $uniqueZoneCounts[$zoneName] ) ) { + $uniqueZoneCounts[$zoneName] = 0; } - $uniqueContainerCounts[$containerName]++; + $uniqueZoneCounts[$zoneName]++; - if ( !isset( $uniqueWikiCounts[$dbName] ) ) { - $uniqueWikiCounts[$dbName] = 1; + if ( !isset( $uniqueWikiCounts[$dbname] ) ) { + $uniqueWikiCounts[$dbname] = 1; } } } @@ -181,8 +181,8 @@ private function findUnmatchedContainers( array $containers ): array { return [ 'containers' => $missingContainers, - 'uniqueContainerCounts' => $uniqueContainerCounts, 'uniqueWikiCounts' => $uniqueWikiCounts, + 'uniqueZoneCounts' => $uniqueZoneCounts, ]; }