Start with the basic required arguments.
Leaves room for expansion.
Decided to have:
- 0 arguments = interactive
- 1+ argument results in regular validation messages
- --help outputs help as normal
- interactive mode mentions you might want --help
Bug: T48076
Change-Id: I972bf55f96c9cdf1a5eaf55c0e0117b190420d30
I believe these methods are what should be used in
maintenance scripts, not anything that literally starts with
$this->parameters->…
Change-Id: I5a2d19475834386e03146985ed9e5a5cd4ae1c52
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.
Thoughts on the previously commonly used methods:
- $status->getMessage( false, false, 'en' )->text()
Almost the same as the new output, but it allows on-wiki message
overrides, and if there is more than one error, it prefixes each
line with a '*' (like a wikitext list).
- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
As above, but these forms do not expand parser functions
such as {{GENDER:}}.
- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
These forms output the message keys instead of the message text,
which is not very human-readable.
The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.
Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
This code path used to add a newline too until it was removed in
bb45c5e8a3 (2011). It seems to be an
accidental change, since other changes in that commit carefully kept
the newlines. I guess it's not reached often in practice…
Change-Id: I1f0e9735efed70fc50e6b4592a7b643f6f51ddc6
* Change `$services->getDBLoadBalancerFactory()->waitForReplication()`
to `$this->waitForReplication()`
* Change various complicated expressions to `$this->getReplicaDB()`
and `$this->getPrimaryDB()`
* Remove unused variables
Change-Id: Ia857be54938a32bb6288dcdf695a35cd38761c3c
And start using them instead of wfGetDB(), LB/LBF connection methods or
worse, $this->getDB().
$this->getDB() reuses the database object regardless of whether you're
calling a replica or primary, leading to returning a replica on a
primary and other way around.
Bug: T330641
Change-Id: I9e2cf85ca277022284fc26b9f37db57bd12aaa81
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
The shutdown logic intuitively feels like the job of the runner and
the maintenance script themselves don't need to have knowledge about
this routine.
Maintenance script should really only execute their tasks after being
invoked by the runner and leave the runner to clean the house at the
end of their execution. Hence shifting the logic to the runner class.
Change-Id: I3d6fbf02b5fcd1414fde3a84e98a08e58456d668
The `$this->getServiceContainer()` is already available, let's just
use it instead of repeated calls to ::getInstance() on MediaWikiServices.
Change-Id: Ia9159e02c8ff6df078e0d14c21314fffc16536e7
This patch removes: Maintenance::$mArgList, ::shouldExecute(),
::setAgentAndTriggers(), ::adjustMemoryLimit(), ::globals(),
and ::loadSettings() that are no longer exercise in prod.
Change-Id: If131f14b3774afd8207761d1f27a9146f73fd1a0
This introduces the MW_AUTOLOAD_TEST_CLASSES switch to tell Setup.php
to enable auto-loading for test classes.
This switch can be set in file scope by core maintenance scripts that
need access to test classes. This is consistent with the mechanism used
by maintenance scripts to control other aspects of Setup.php
This is an alternative solution to the fix proposed in I17ff5867c5f57c524.
Change-Id: I2a0000f6a885c1ce1b28b748e8cc762af5584c2c
This adds:
* getArgs() to complement getArg()
* getServiceContainer() to provide access to services.
Change-Id: I507eb83ab2709a98fe583c7be87b4ef449b204ce
Subclasses of Maintenance that can function without database access can
now override canExecuteWithoutLocalSettings to return true.
This is useful for scripts that need to be able to run before or without
installing MediaWiki.
When no config file is present, the storage backend will be disabled.
Any attempt to access the database will result in an error.
NOTE: This makes MediaWikiServices::disableBackendServices() more
comprehensive, to avoid premature failures during service
construction. This change makes it necessary to adjust how the
installer manages service overrides.
The CLI installer is covered by CI, I tested the web installer
manually.
Change-Id: Ie84010c80f32cbdfd34aff9dde1bfde1ed531793
Add suppor for documenting multi-value positional args.
Also fixes an issue with errors about missing args being shown even when
--help is given.
Change-Id: I6e07115aaa0f557614979adcd3f0423dd37fe8bc
Refer to "options" consistently, instead of sometimes using the term
"parameters".
Only list required options synopsis, and include option value placeholders.
The synopsis will now look simething lieke this:
USAGE: php foo [OPTION]... --param <PARAM> --something <SOMETHING> <X> [y]
Change-Id: Idb2f309ee442f0e5f597e0fc15537f90944f28b0
The Maintenance base class has been triggering deprecation warnings
when generating the standard help message, because the output()
method accesses MediaWikiServices, which is not initialized at the time
the help output happens.
These deprecation warnings are generally invisible on the command line,
but they should be avoided nontheless.
Change-Id: I0d457621fdd569bb413f84d56dd2e272f48ffbd5
Maintenance scripts can now be run like this:
maintenance/run.php <class>
NOTE: This introduces a new callback into Setup.php,
MW_FINAL_SETUP_CALLBACK. In contrast to MW_SETUP_CALLBACK, it is
called after extensions have been initialized.
Bug: T99268
Change-Id: Ia221f72d6b7d23df74623d60ade7fe3e5d913074
Previously, SettingsBuilder would allow configuration to be loaded
and modified until it was "finalized", at which point configuration
became read only. This patch introduces an intermediate stage where
registration dynamic manipulation of config values can be performed,
after all extensions have been loaded and all config schemas are known.
Motivation:
Extension registration callbacks are typically used to dynamically set
config variables, often based on other configuration. This should be
done using SettingsBuilder rather than global variables. But previously,
we could only be sure that all extensions are known after SettingsBuilder
was "finalized", at which point it would be impossible to change config
values.
Change-Id: I6f8f9f3f7252f0024282d7b005671f28a5b3acc3
This introduces $wgLBFactoryConf['configCallback'] which can be set to a
function that returns updates to be applied to $wgLBFactoryConf. The new
method LBFactory::autoreConfigure() can be called to check the callabck
and, if the config changed, reconfigure all existing LoadBalancers.
Reconfiguring the LoadBalancers causes all open connections to be
invalidated; however, any DBConnRef instances will remain valid and will
acquire a fresh connection from the LoadBalancer automatically when
appropriate.
As a proof of concept, this patch adds support for config reloding
into WikiExporter.
Bug: T298485
Change-Id: I6c3ffde62f6e038730736abe980befd90ec43e1a
Some maintenance scripts, notably addWiki, directly write into mOptions
of child scripts. This was broken by Ib67667fead835. This patch turns
mOptions and mArgs into references to the corresponding fields in the
MaintenanceParameters object. It also introduces setters that should be
used instead of writing directly into the array.
Bug: T313302
Change-Id: Iad6df29777cd3ad3bfa940cea62196d9a94a0910
This moves the handling for the following parameters fully into the
MaintenanceRunner class:
--conf, --wiki, --globlas, --memory-limit, --server, --profiler
Change-Id: I63624ba1fcbcf446630eba1b81b2c84b1a943932
We will need parameter handling in the runner as well as in the actual
maintenance script. So pull it out, so we can re-use it.
Change-Id: Ib67667fead8350e0a539323fb05b160f4c2d882e
The global variable $IP has been replaced by the MW_INSTALL_PATH
constant. Clarify the continued use of $IP on Setup.php.
Change-Id: I157abfd9049fb8382da53005a084ab86f47e8d8a
Added support for an easy to configure multi-tenant ("wiki farm") mode:
Settings for each site can be placed in a directory specified by
$wgWikiFarmSettingsDirectory. Site detection is controlled by
$wgWikiFarmSiteDetector and defaults to the requested host name.
Instructions for manual testing: https://etherpad.wikimedia.org/p/T221535
Bug: T221535
Change-Id: I7581921b7d99ba1fe7e25523fde691d76b67a99c
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together
Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
Make phan stricter about scalar types by setting scalar_implicit_cast to
false (the default in mediawiki-phan-config)
Bug: T242536
Bug: T301991
Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts
Found by phan strict checks
Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
Some function already document "False on failure", but does not document
it on the used type
Found by phan strict checks
Change-Id: I12eb8bbc99179833ee3e42c1a7d1dc1443682ca6
Connection loss with a failure to reconnect led to a variety of failure
modes, such as an assertion from getBindingHandle() when addQuotes() is
next called. And Maintenance::shutdown() was calling
commitPrimaryChanges() three times, each call leading to an assertion
due to the round stage being broken.
So, try to exit promptly if a DBConnectionError is caught, by
introducing a new "reached" category for fatal exceptions. Guard the
calls to commitPrimaryChanges(), and skip the call prior to shutdown()
since shutdown() calls it already.
Change-Id: I81ee9017a58adac674a9495802f6bd4bcc22ee61
This allows a file other than LocalSettings.php to be used as the primary
settings file by setting the MW_CONFIG_FILE environment variable.
This also allows the primary settings file to use YAML or JSON format.
Using static configuration files should be the default in the future.
However, YAML files in the document root could easily be exposed to the
public. Better not to encourage that, and require them to be enabled
explicitly and loaded from a different place.
Bug: T294750
Change-Id: I7747f83481cb05a6d05f819be652259951183819