|
3 | 3 | namespace Wikibase\Repo\Maintenance; |
4 | 4 |
|
5 | 5 | use MediaWiki\Maintenance\Maintenance; |
6 | | -use MediaWiki\Registration\ExtensionRegistry; |
7 | | -use MediaWiki\Settings\SettingsBuilder; |
8 | 6 | use Onoi\MessageReporter\ObservableMessageReporter; |
9 | 7 | use Wikibase\DataModel\Services\EntityId\EntityIdPager; |
10 | 8 | use Wikibase\DataModel\Services\Lookup\EntityLookupException; |
11 | 9 | use Wikibase\Lib\Reporting\ExceptionHandler; |
12 | 10 | use Wikibase\Lib\Reporting\ReportingExceptionHandler; |
13 | | -use Wikibase\Lib\WikibaseSettings; |
14 | 11 | use Wikibase\Repo\Dumpers\DumpGenerator; |
15 | 12 | use Wikibase\Repo\IO\EntityIdReader; |
16 | 13 | use Wikibase\Repo\IO\LineReader; |
@@ -170,6 +167,14 @@ private function closeLogFile() { |
170 | 167 | * Do the actual work. All child classes will need to implement this |
171 | 168 | */ |
172 | 169 | public function execute() { |
| 170 | + if ( $this->hasOption( 'dbgroupdefault' ) ) { |
| 171 | + // make sure Maintenance::getLBFactory() (private) applies the dbgroupdefault |
| 172 | + // option to the LBFactory in the service container. |
| 173 | + $this->getReplicaDB(); |
| 174 | + } else { |
| 175 | + $this->getServiceContainer()->getDBLoadBalancerFactory()->setDefaultGroupName( 'dump' ); |
| 176 | + } |
| 177 | + |
173 | 178 | //TODO: more validation for options |
174 | 179 | $shardingFactor = (int)$this->getOption( 'sharding-factor', 1 ); |
175 | 180 | $shard = (int)$this->getOption( 'shard', 0 ); |
@@ -251,38 +256,6 @@ public function execute() { |
251 | 256 | $this->closeLogFile(); |
252 | 257 | } |
253 | 258 |
|
254 | | - /** |
255 | | - * @inheritDoc |
256 | | - */ |
257 | | - public function finalSetup( SettingsBuilder $settingsBuilder ) { |
258 | | - parent::finalSetup( $settingsBuilder ); |
259 | | - |
260 | | - if ( $this->hasOption( 'dbgroupdefault' ) ) { |
261 | | - // A group was set via cli, so no need to set the default here |
262 | | - return; |
263 | | - } |
264 | | - |
265 | | - $settingsBuilder->registerHookHandlers( [ 'MediaWikiServices' => [ function() { |
266 | | - global $wgDBDefaultGroup; |
267 | | - if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseRepository' ) ) { |
268 | | - // Something instantiates the MediaWikiServices before Wikibase |
269 | | - // is loaded, nothing we can do here. |
270 | | - wfWarn( self::class . ': Can not change default DB group.' ); |
271 | | - |
272 | | - return; |
273 | | - } |
274 | | - |
275 | | - // Don't use WikibaseRepo or MediaWikiServices here as this is run very early on, thus |
276 | | - // the bootstrapping code is not ready yet (T202452). |
277 | | - $settings = WikibaseSettings::getRepoSettings(); |
278 | | - $dumpDBDefaultGroup = $settings->getSetting( 'dumpDBDefaultGroup' ); |
279 | | - |
280 | | - if ( $dumpDBDefaultGroup !== null ) { |
281 | | - $wgDBDefaultGroup = $dumpDBDefaultGroup; |
282 | | - } |
283 | | - } ] ] ); |
284 | | - } |
285 | | - |
286 | 259 | /** |
287 | 260 | * @return string[] |
288 | 261 | */ |
|
0 commit comments