Make Maintenance::finalSetup require a SettingsBuilder

Maintenance::finalSetup should have access to a SettingsBuilder so it
can manipulates config settings without resorting to global variables.
MaintenanceRunner will always provide a SettingsBuilder when calling
this method, so implementations should be able to rely on always getting
one.

The $settings parameter was introduced as optional in order to maintain
backwards compatibility with implementations that did not declare the
parameter. But these should all have been fixed since.

Depends-On: I8a3699b13bfb4dc15f3bed562731ed9d525651cc
Change-Id: I334a103e02fd905faafc43c7c5b95996bc91fd18
This commit is contained in:
daniel 2024-01-02 15:12:21 +01:00 committed by James D. Forrester
parent a58151885b
commit cea8aee05e
14 changed files with 18 additions and 26 deletions

View file

@ -136,6 +136,10 @@ because of Phabricator reports.
and MediaWikiPerformActionHook::onMediaWikiPerformAction changed from
MediaWiki to ActionEntryPoint. Relevant methods are still available on
the object.
* Classes that override Maintenance::finalSetup() must now declare the
$settings parameter and pass it on when calling the parent implementation.
MaintenanceRunner will always provide this parameter when calling
finalSetup().
* MediaWiki's virtualrest internal library has been removed in favor of the
HTTP library like: Guzzle, MultiHttpClient or MwHttpRequest.
* Several deprecated methods have been removed from the Content interface,

View file

@ -116,7 +116,7 @@ abstract class DumpIterator extends Maintenance {
$this->error( "Memory peak usage of " . memory_get_peak_usage() . " bytes\n" );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
parent::finalSetup( $settingsBuilder );
if ( $this->getDbType() == Maintenance::DB_NONE ) {

View file

@ -46,7 +46,7 @@ class FetchText extends Maintenance {
);
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
// This script should always try to run all db queries in the 'dump' group if such
// a group exists, just like the BackupDumper and TextPassDumper modules.
// To account for parts of MediaWiki that get their own db connection outside of

View file

@ -176,7 +176,7 @@ abstract class BackupDumper extends Maintenance {
}
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
parent::finalSetup( $settingsBuilder );
// re-declare the --schema-version option to include the default schema version
// in the description.

View file

@ -875,17 +875,9 @@ abstract class Maintenance {
*
* @stable to override
*
* @param SettingsBuilder|null $settingsBuilder
* @param SettingsBuilder $settingsBuilder
*/
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
if ( !$settingsBuilder ) {
// HACK for backwards compatibility. All subclasses that override
// finalSetup() should be updated to pass $settingsBuilder along.
// XXX: We don't want the parameter to be nullable! How can we make it required
// without breaking backwards compatibility?
$settingsBuilder = $GLOBALS['wgSettings'];
}
public function finalSetup( SettingsBuilder $settingsBuilder ) {
$config = $settingsBuilder->getConfig();
$overrides = [];
$overrides['DBadminuser'] = $config->get( MainConfigNames::DBadminuser );

View file

@ -168,7 +168,7 @@ TEXT
}
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
parent::finalSetup( $settingsBuilder );
SevenZipStream::register();

View file

@ -106,11 +106,7 @@ class CommandLineInstaller extends Maintenance {
return true;
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
if ( !$settingsBuilder ) {
$settingsBuilder = SettingsBuilder::getInstance();
}
public function finalSetup( SettingsBuilder $settingsBuilder ) {
parent::finalSetup( $settingsBuilder );
Installer::overrideConfig( $settingsBuilder );
}

View file

@ -114,7 +114,7 @@ class MergeMessageFileList extends Maintenance {
$this->generateMessageFileList( $setupFiles );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
# This script commonly needs to be run before the l10n cache. But if
# LanguageCode is not 'en', it won't be able to run because there is
# no l10n cache. Break the cycle by forcing the LanguageCode setting to 'en'.

View file

@ -47,7 +47,7 @@ class RebuildFileCache extends Maintenance {
$this->setBatchSize( 100 );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
$this->enabled = $settingsBuilder->getConfig()->get( MainConfigNames::UseFileCache );
// Script will handle capturing output and saving it itself
$settingsBuilder->putConfigValue( MainConfigNames::UseFileCache, false );

View file

@ -84,7 +84,7 @@ class RebuildLocalisationCache extends Maintenance {
);
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
# This script needs to be run to build the initial l10n cache. But if
# LanguageCode is not 'en', it won't be able to run because there is
# no l10n cache. Break the cycle by forcing the LanguageCode setting to 'en'.

View file

@ -44,7 +44,7 @@ class RunJobs extends Maintenance {
$this->addOption( 'wait', 'Wait for new jobs instead of exiting', false, false );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
// So extensions (and other code) can check whether they're running in job mode.
// This is not defined if this script is included from installer/updater or phpunit.
define( 'MEDIAWIKI_JOB_RUNNER', true );

View file

@ -43,7 +43,7 @@ class ParserEditTests extends Maintenance {
$this->addOption( 'session-data', 'internal option, do not use', false, true );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
// Some methods which are discouraged for normal code throw exceptions unless
// we declare this is just a test.
define( 'MW_PARSER_TEST', true );

View file

@ -30,7 +30,7 @@ class ParserFuzzTest extends Maintenance {
$this->addOption( 'seed', 'Start the fuzz test from the specified seed', false, true );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
// Make RequestContext::resetMain() happy
define( 'MW_PARSER_TEST', 1 );

View file

@ -103,7 +103,7 @@ class ParserTestsMaintenance extends Maintenance {
'for finer grained editing of tests.' );
}
public function finalSetup( SettingsBuilder $settingsBuilder = null ) {
public function finalSetup( SettingsBuilder $settingsBuilder ) {
// Some methods which are discouraged for normal code throw exceptions unless
// we declare this is just a test.
define( 'MW_PARSER_TEST', true );