From 3a45c2600b239fc36f9652d55409007d743c33c2 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 20 Nov 2024 11:00:45 +1100 Subject: [PATCH] Move addWiki.php special case to an installer task Bug: T352113 Depends-On: Ie7c466012d8d5644b1398452e3077416ab0270c5 Change-Id: I752edd8daaebb91a4bd9a7797747ade96d537526 --- extension.json | 7 +++- includes/InstallSchemaTask.php | 60 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 includes/InstallSchemaTask.php diff --git a/extension.json b/extension.json index 232d4f3f8..2709230b7 100644 --- a/extension.json +++ b/extension.json @@ -1165,5 +1165,10 @@ ], "ConfigRegistry": { "Echo": "GlobalVarConfig::newInstance" - } + }, + "InstallerTasks": [ + { + "class": "MediaWiki\\Extension\\Notifications\\InstallSchemaTask" + } + ] } diff --git a/includes/InstallSchemaTask.php b/includes/InstallSchemaTask.php new file mode 100644 index 000000000..b528b7713 --- /dev/null +++ b/includes/InstallSchemaTask.php @@ -0,0 +1,60 @@ +getConfigVar( 'EchoCluster' ); + if ( !$cluster ) { + // This case is adequately handled by LoadExtensionSchemaUpdates + return Status::newGood(); + } + + // Get the load balancer + $lbFactory = $this->getServices()->getDBLoadBalancerFactory(); + $databaseCreator = $this->getDatabaseCreator(); + $domainId = $lbFactory->getLocalDomainID(); + $database = DatabaseDomain::newFromId( $domainId )->getDatabase(); + $echoLB = $lbFactory->getExternalLB( $cluster ); + + // Create database + if ( !$databaseCreator->existsInLoadBalancer( $echoLB, $database ) ) { + $databaseCreator->createInLoadBalancer( $echoLB, $database ); + } + + // Create tables + $dbw = $echoLB->getMaintenanceConnectionRef( DB_PRIMARY ); + $dbw->setSchemaVars( $this->getContext()->getSchemaVars() ); + return $this->applySourceFile( $dbw, 'tables-generated.sql' ); + } + +}