Why:
* Maintenance scripts in core have bolierplate code that is
added before and after the class to allow directly running
the maintenance script.
* Running the maintenance script directly has been deprecated
since 1.40, so this boilerplate code is only to support a now
deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
coverage reports as it cannot be marked as covered and also
is for deprecated code.
What:
* Wrap the boilerplate code (requiring Maintenance.php and then
later defining the maintenance script class and running if the
maintenance script was called directly) with @codeCoverageIgnore
comments.
* Some files use a different boilerplate code, however, these
should also be marked as ignored for coverage for the same
reason that coverage is not properly reported for files.
Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
The shell.php environment may be useful for testing and debugging even
without a configured MediaWiki instance. Allow it to run without
LocalSettings.php.
Change-Id: I738679384ee8065826f05148829cd04aa9f52efd
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 class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.
NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.
Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.
Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
This is necessary for the loggers in ObjectCache instances to be
updated. It will clear in-process caches; hopefully that is not
too disruptive.
Change-Id: I9e425942e43251d36a5308cf4819d9de985002de
* Extend ConsoleLogger to support filtering by log level and
forwarding to another logger.
* Extend ConsoleSpi to support filtering by channel/level and
forwarding to another provider.
* Allow configuring which channels shell.php should log to STDERR
and at what levels.
* Deprecate shell.php -d, use more meaningful parameter names.
* Change logging behavior so that logging to STDERR doesn't
prevent normal logging, which seemed like confusing behavior
(either we should always disable normal logging for shell.php
or never, it shouldn't depend on whether we log to console).
Keep old behavior for -d, just in case.
Change-Id: I5d29c95995bf83784c96dd40df9c96e22b9ec73e
Add a --no-session option to shell.php for easier manual
testing/debugging of code for which that flag is relevant.
Exempt from autoloading to avoid breaking ScopeStructureTest.
Change-Id: I97548c8fe76a833837b131a5cd5bd0006a5f7326
Avoid bobthecow/psysh#443[1] (PsySH using XDG_RUNTIME_DIR as temp
directory, which is inherited by the new user when doing sudo -E
but is only writable by the old user) by using the MediaWiki temp
dir.
[1]: https://github.com/bobthecow/psysh/issues/443
Change-Id: Ica9344cdf23323d264f66df03b9d82ccc0582e45
Deprecate the second argument to Maintenance::error() in favor of a new
Maintenance::fatalError() method. This is intended to make it easier to
review flow control in maintenance scripts.
Change-Id: I75699008638f7e99b11210c7bb9e2e131fca7c9e
Instead of iterating through load balancer info, just set the flag in
the master and replica connections, since that seems more robust.
Deprecate LoadBalancer::setServerInfo() and
LoadBalancer::getServerInfo(), no remaining callers in core or
in-tree extensions, I think I added the function just for this feature.
Do a service reset, since Logger instances are injected into
LoadBalancer by ServiceWiring (via MWLBFactory::applyDefaultConfig()).
Similarly CryptRand, MimeAnalyzer.
Fix the usage text for shell.php
Change-Id: I3e85a6e8cfa1243a0371cfb3ce1c18665e8c711d
eval.php previously set $wgDebugLogFile to /dev/stdout. This had the
following problems:
* It doesn't work if the maintenance script is executed via sudo, since
/dev/stdout is typically owned by the original user, so MW can't open
it. Using php://stdout worked on HHVM but not PHP.
* Setting $wgDebugLogFile has no effect if the wiki uses MonologSpi.
* Setting $wgDebugLogFile has no effect on channels configured with
$wgDebugLogGroups.
* stderr is a more appropriate place to send logging output.
* Writing to configuration variables is discouraged.
So, add ConsoleSpi, which is a very simple logging service provider
which sends all messages to stderr. This should be suitable for
debugging with eval.php or shell.php in WMF production or beta.
Change-Id: Ib0d6ce45e0cbecd58263fc4e360c63d4149acb3a
eval.php is meant to eval() commands in MediaWiki global scope. We had
at least a couple attempts to move it to a regular Maintenance script.
As noted on the revert commit b475e930 r54839, using a Maintenance
script drop us in the callee function scope instead of the global scope
which is a hard requirement.
http://psysh.org/ is a Read-Eval-Print-Loop with color highlight, modern
code and more.
Add maintenance/shell.php script as MediaWikiShell class.
Passing command from stdin is supported.
Execution is forked for graceful handling of PHP fatal errors.
Colors!!
Support the undocumented '-d' arguments from eval.php:
0 set $wgDebugLogFile to stdout. Eval.php used /dev/stdout, make it
php://stdout in the new script.
1 additionally set DBO_DEBUG on all the database load balancer servers
PHP globals have to be whitelisted which is not supported out of the box
by Psy. Upon request, the author of PsySh, Justin Hileman, kindly
provided a pass to inject globals (with the exceptions of super
globals). He agreed for code reuse:
https://github.com/bobthecow/psysh/issues/353
The code was added to maintenance/CodeCleanerGlobalsPass.inc
Note that this is not a perfect simulation of global scope (but pretty
close): variables declared in the shell which did not exist before
won't be global unless the 'global' keword is used.
Example usage:
$ php maintenance/shell.php
>>> $wgFullyInitialised
=> true
>>> $hashar = User::newFromName( 'hashar' )
=> User {#274
+mId: null,
+mName: "Hashar",
...
>>> ls --long --all $h
<descriptive output of all object properties/methods>
Bug: T117661
Signed-off-by: Justin Hileman <justin@justinhileman.info>
Signed-off-by: Gergő Tisza <tgr.huwiki@gmail.com>
Change-Id: I3d6d42e138d3cc4a0aaafdd7f5f97cb17d8b8cb3