Skip to content

Commit

Permalink
Migrate to use CreateWiki's virtual domains (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Nov 20, 2024
1 parent b62d575 commit 334d0dd
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
5 changes: 2 additions & 3 deletions maintenance/checkSwiftContainers.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ private function getSwiftContainers(): array {
}

private function findUnmatchedContainers( array $containers ): array {
$dbr = $this->getServiceContainer()->getConnectionProvider()->getReplicaDatabase(
$this->getConfig()->get( 'CreateWikiDatabase' )
);
$dbr = $this->getServiceContainer()->getConnectionProvider()
->getReplicaDatabase( 'virtual-createwiki' );

$suffix = $this->getConfig()->get( 'CreateWikiDatabaseSuffix' );

Expand Down
25 changes: 11 additions & 14 deletions maintenance/checkWikiDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ private function getWikiDatabasesFromClusters( array $clusters ): array {
}

private function findMissingDatabases( array $wikiDatabases ): array {
$dbr = $this->getServiceContainer()->getConnectionProvider()->getReplicaDatabase(
$this->getConfig()->get( 'CreateWikiDatabase' )
);
$dbr = $this->getServiceContainer()->getConnectionProvider()
->getReplicaDatabase( 'virtual-createwiki' );

$missingDatabases = [];
foreach ( $wikiDatabases as $dbName => $cluster ) {
Expand All @@ -142,7 +141,7 @@ private function checkGlobalTableEntriesWithoutDatabase( array $wikiDatabases ):
$suffix = $this->getConfig()->get( 'CreateWikiDatabaseSuffix' );

$tablesToCheck = [
'CreateWikiDatabase' => [
'virtual-createwiki' => [
'cw_wikis' => 'wiki_dbname',
'gnf_files' => 'files_dbname',
'localnames' => 'ln_wiki',
Expand All @@ -151,20 +150,19 @@ private function checkGlobalTableEntriesWithoutDatabase( array $wikiDatabases ):
'mw_permissions' => 'perm_dbname',
'mw_settings' => 's_dbname',
],
'EchoSharedTrackingDB' => [
$this->getConfig()->get( 'EchoSharedTrackingDB' ) => [
'echo_unread_wikis' => 'euw_wiki',
],
'GlobalUsageDatabase' => [
$this->getConfig()->get( 'GlobalUsageDatabase' ) => [
'globalimagelinks' => 'gil_wiki',
],
];

$missingInCluster = [];

foreach ( $tablesToCheck as $dbConfigKey => $tables ) {
$dbr = $this->getServiceContainer()->getConnectionProvider()->getReplicaDatabase(
$this->getConfig()->get( $dbConfigKey )
);
foreach ( $tablesToCheck as $database => $tables ) {
$dbr = $this->getServiceContainer()->getConnectionProvider()
->getReplicaDatabase( $database );

foreach ( $tables as $table => $field ) {
$this->output( "Checking table: $table, field: $field...\n" );
Expand Down Expand Up @@ -225,10 +223,9 @@ private function deleteEntries(
): void {
$suffix = $this->getConfig()->get( 'CreateWikiDatabaseSuffix' );

foreach ( $tablesToCheck as $dbConfigKey => $tables ) {
$dbw = $this->getServiceContainer()->getConnectionProvider()->getPrimaryDatabase(
$this->getConfig()->get( $dbConfigKey )
);
foreach ( $tablesToCheck as $database => $tables ) {
$dbw = $this->getServiceContainer()->getConnectionProvider()
->getPrimaryDatabase( $database );

foreach ( $tables as $table => $field ) {
$this->output( "Deleting missing entries from table: $table, field: $field...\n" );
Expand Down
3 changes: 2 additions & 1 deletion maintenance/generateExtensionDatabaseList.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function execute() {
$extArray = $this->getOption( 'extension' );
$directory = $this->getOption( 'directory' );

$dbr = $this->getDB( DB_REPLICA, [], $this->getConfig()->get( 'CreateWikiDatabase' ) );
$connectionProvider = $this->getServiceContainer()->getConnectionProvider();
$dbr = $connectionProvider->getReplicaDatabase( 'virtual-createwiki' );

foreach ( $extArray as $ext ) {
$list = [];
Expand Down
10 changes: 6 additions & 4 deletions maintenance/generateManageWikiBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,25 @@ public function __construct() {

public function execute() {
$dbname = $this->getConfig()->get( MainConfigNames::DBname );
$dbw = $this->getDB( DB_PRIMARY, [], $this->getConfig()->get( 'CreateWikiDatabase' ) );

$connectionProvider = $this->getServiceContainer()->getConnectionProvider();
$dbr = $connectionProvider->getReplicaDatabase( 'virtual-createwiki' );

$buildArray = [];

$nsObjects = $dbw->select(
$nsObjects = $dbr->select(
'mw_namespaces',
'*',
[ 'ns_dbname' => $dbname ]
);

$permObjects = $dbw->select(
$permObjects = $dbr->select(
'mw_permissions',
'*',
[ 'perm_dbname' => $dbname ]
);

$settingsObjects = $dbw->selectRow(
$settingsObjects = $dbr->selectRow(
'mw_settings',
'*',
[ 's_dbname' => $dbname ],
Expand Down
2 changes: 1 addition & 1 deletion maintenance/renameDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function execute(): void {
$this->output( "Renaming database: $oldDatabaseName to $newDatabaseName\n" );

$dbr = $this->getServiceContainer()->getConnectionProvider()
->getReplicaDatabase( $this->getConfig()->get( 'CreateWikiDatabase' ) );
->getReplicaDatabase( 'virtual-createwiki' );

// Fetch the specific cluster from cw_wikis based on the old database name
$cluster = $dbr->newSelectQueryBuilder()
Expand Down
2 changes: 1 addition & 1 deletion maintenance/resetWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function execute(): void {
$this->output( "Resetting database: $databaseName\n" );

$dbr = $this->getServiceContainer()->getConnectionProvider()
->getReplicaDatabase( $this->getConfig()->get( 'CreateWikiDatabase' ) );
->getReplicaDatabase( 'virtual-createwiki' );

// Fetch the original data
$row = $dbr->newSelectQueryBuilder()
Expand Down
3 changes: 2 additions & 1 deletion maintenance/restoreManageWikiBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function execute() {
$this->fatalError( 'Invalid wiki. You can not overwrite default.' );
}

$dbw = $this->getDB( DB_PRIMARY, [], $this->getConfig()->get( 'CreateWikiDatabase' ) );
$connectionProvider = $this->getServiceContainer()->getConnectionProvider();
$dbw = $connectionProvider->getPrimaryDatabase( 'virtual-createwiki' );

$backupFile = $this->getOption( 'filename' );
if ( !file_exists( $backupFile ) ) {
Expand Down

0 comments on commit 334d0dd

Please sign in to comment.