Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckSwiftContainers: rename container option to zone #534

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -141,49 +141,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
Loading