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' ); + } + +}