Skip to content

Commit

Permalink
CheckSwiftContainers: rename container option to zone (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Nov 20, 2024
1 parent 18f7459 commit cab2661
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions maintenance/checkSwiftContainers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand All @@ -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'] );
Expand Down Expand Up @@ -140,49 +140,49 @@ 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;
}

// Check if the dbname exists in cw_wikis
$result = $dbr->newSelectQueryBuilder()
->select( [ 'wiki_dbname' ] )
->from( 'cw_wikis' )
->where( [ 'wiki_dbname' => $dbName ] )
->where( [ 'wiki_dbname' => $dbname ] )
->caller( __METHOD__ )
->fetchRow();

// If no matching wiki is found, add to the missing list
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;
}
}
}
}

return [
'containers' => $missingContainers,
'uniqueContainerCounts' => $uniqueContainerCounts,
'uniqueWikiCounts' => $uniqueWikiCounts,
'uniqueZoneCounts' => $uniqueZoneCounts,
];
}

Expand Down

0 comments on commit cab2661

Please sign in to comment.