Commit graph

105 commits

Author SHA1 Message Date
addshore
34a17b32fc Add a basic interactive install.php
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
2024-07-24 22:12:12 +00:00
thiemowmde
2cbce841c4 maintenance: Hint at better replacements for deprecated fields
I believe these methods are what should be used in
maintenance scripts, not anything that literally starts with
$this->parameters->…

Change-Id: I5a2d19475834386e03146985ed9e5a5cd4ae1c52
2024-07-07 16:45:29 +02:00
Bartosz Dziewoński
4108bbe1af Maintenance: Print errors from StatusValue objects in a consistent way
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
2024-06-12 00:07:02 +02:00
Bartosz Dziewoński
11accb12e7 Maintenance: Consistently print a newline after errors
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
2024-06-07 01:49:49 +02:00
Taavi Väänänen
9553121e2a
maintenance: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I9eb336837b21aa37327f571aad4f973592bdddf7
2024-04-21 23:06:00 +03:00
Umherirrender
523372df32 Migrate to IDatabase::newDeleteQueryBuilder
Change-Id: Idf42d67c1b0b311f81a1d60a7a8a6f875f99e864
2024-04-12 20:12:05 +02:00
Bartosz Dziewoński
166748e3ac maintenance: Replace unnecessary uses of LBFactory and LoadBalancer
* Change `$services->getDBLoadBalancerFactory()->waitForReplication()`
  to `$this->waitForReplication()`
* Change various complicated expressions to `$this->getReplicaDB()`
  and `$this->getPrimaryDB()`
* Remove unused variables

Change-Id: Ia857be54938a32bb6288dcdf695a35cd38761c3c
2024-01-23 16:48:36 +00:00
Amir Sarabadani
d9370003fb maintenance: Introduce getReplicaDB() and getPrimaryDB()
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
2024-01-18 15:12:04 +01:00
daniel
cea8aee05e 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
2024-01-08 09:40:18 -05:00
Bartosz Dziewoński
b2c83a0721 Deprecate $wgCommandLineMode
The global variable is now exactly the same as
`MW_ENTRY_POINT === 'cli'`.

Bug: T313841
Change-Id: I254bf4aa426e4834705be351cc9eb06d18a33f79
2024-01-02 22:21:50 +01:00
Amir Sarabadani
9009c4cbd7 Migrate away from $db->makeList in favor of expression builder
Bug: T210206
Change-Id: I803a6130fff5ce6faaaa5221443a436195b03c75
2023-11-02 16:40:48 +00:00
jenkins-bot
b286f79f5d Merge "maintenance: Migrate another batch to SelectQueryBuilder" 2023-09-21 14:03:35 +00:00
Amir Sarabadani
eaedb7da16 maintenance: Migrate another batch to SelectQueryBuilder
Around fifty-ish. Found becuase of fixed MigrateSelect.

Bug: T344971
Change-Id: If85428d5a033822bfd8ee1f6ab730863bfad55bd
2023-09-21 14:15:42 +02:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Derick Alangi
ab1bfd9e3a maintenance: Move shutdown() logic to MaintenanceRunner
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
2023-09-12 17:00:09 +00:00
Derick Alangi
b797e96195
maintenance: Use $this->getServiceContainer() since we have it
The `$this->getServiceContainer()` is already available, let's just
use it instead of repeated calls to ::getInstance() on MediaWikiServices.

Change-Id: Ia9159e02c8ff6df078e0d14c21314fffc16536e7
2023-08-24 11:34:38 +01:00
Derick Alangi
48baf63e62
maintenance: Cleanup Maintenance class for unused/dead code
This patch removes: Maintenance::$mArgList, ::shouldExecute(),
::setAgentAndTriggers(), ::adjustMemoryLimit(), ::globals(),
and ::loadSettings() that are no longer exercise in prod.

Change-Id: If131f14b3774afd8207761d1f27a9146f73fd1a0
2023-08-24 11:32:19 +01:00
daniel
38cf45a747 parserTests: ensure test classes get auto-loaded.
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
2023-03-27 20:38:53 +02:00
daniel
97112a11bc Maintenance: Add convenience methods to the Maintenance base class
This adds:
* getArgs() to complement getArg()
* getServiceContainer() to provide access to services.

Change-Id: I507eb83ab2709a98fe583c7be87b4ef449b204ce
2023-03-24 22:15:24 +00:00
daniel
7dcfbf2a62 Allow some maintenance scripts to be called without a LocalSettings
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
2023-02-16 21:11:33 +00:00
daniel
52ebdb1ed0
Maintenance: Add support for documenting multi-args
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
2023-01-28 22:34:52 -08:00
daniel
963ef5d645 Maintenance: improve option help
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
2023-01-23 19:30:56 +00:00
daniel
f1eeb5f890 Maintenance: Avoid premature access to service container
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
2023-01-13 20:00:46 +01:00
daniel
180f0a6468 Introduce run.php for running maintenance scripts
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
2022-12-21 06:52:04 +00:00
daniel
455e7686bf SettingsBuilder: introduce a "registration" stage
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
2022-12-16 15:47:05 +00:00
Aaron Schulz
d7db1f542d profiler: Actually output profiler data in CLI/Maintenance mode
Bug: T253547
Change-Id: Iab44aadeb7094d73441c69c4ba8ef16d1eb4d386
2022-10-14 16:56:18 +00:00
Marius Hoch
5e42675963 Maintenance: Fix hasArg/getArg $argId PHPDoc
The respective MaintenanceParameters methods
also support strings.

Change-Id: Iec61d99d2303d52cdd9bc0d793f711482f770921
2022-09-07 14:41:11 +02:00
daniel
5b0b54599b Allow DB config to be reloaded on the fly
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
2022-08-05 17:32:12 +02:00
daniel
21810232b6 Maintenance: allow legacy mOptions field to be manipulated.
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
2022-07-19 15:37:39 +02:00
daniel
18d3ad081d Runner: Handle more params in runner.
This moves the handling for the following parameters fully into the
MaintenanceRunner class:
  --conf, --wiki, --globlas, --memory-limit, --server, --profiler

Change-Id: I63624ba1fcbcf446630eba1b81b2c84b1a943932
2022-06-13 16:10:51 +00:00
daniel
6e9b957d6c Move code from Maintenance to MaintenanceRunner
All code related to the runtime environment should live in the runner.

Change-Id: I50dc30be805378b4febc57d5f5a0967afa377dfa
2022-05-25 10:42:39 +02:00
daniel
a9f47fd5ad Extract parameter handling from Maintenance base class.
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
2022-05-25 10:40:24 +02:00
jenkins-bot
40abc7d834 Merge "Use User::isRegistered for readability instead of ::getId falsy check" 2022-05-23 04:06:10 +00:00
jenkins-bot
654ccb3a4c Merge "Setup.php: clarify the use of $IP." 2022-05-04 18:10:39 +00:00
daniel
bedd996fe6 Setup.php: clarify the use of $IP.
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
2022-05-03 11:53:05 +02:00
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Umherirrender
65942f4402 maintenance scripts: use MainConfigNames for config names
Change-Id: Ie58dd6ca13951fa24ace2a095a9db2d7ee31f013
2022-04-29 20:13:47 +02:00
Ammarpad
185758d5af Maintenance: Remove unused MW_CMDLINE_CALLBACK constant
Bug: T305422
Change-Id: I2002d7d66823df2db2564faa5da84173d4915d8f
2022-04-05 19:39:38 +01:00
daniel
5fcedc88c9 Add wiki-farm support
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
2022-04-01 14:29:22 +02:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
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
2022-03-21 18:25:07 +00:00
Umherirrender
6dd8a2bb32 phan: Disable scalar_implicit_cast setting
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
2022-03-18 18:52:24 +00:00
Umherirrender
bbcf9f7539 Call Maintenance::readconsole statically and fix documentation
Change-Id: Ib33ee8158ee62f8699241c55bd4f43599df9c80f
2022-03-14 21:15:35 +00:00
jenkins-bot
d1cfc0317d Merge "Add explicit casts between scalar types" 2022-03-08 17:32:26 +00:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
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
2022-03-08 16:59:01 +00:00
Umherirrender
a9aa1e7346 Fix type of value directly passed to php internal functions
Found by phan strict checks

Change-Id: Icc44cd143f2e98fa3ca188e625a3289441de0f73
2022-03-07 20:41:55 +01:00
Umherirrender
9ed1ed185f Fix various documentation related to false
Some function already document "False on failure", but does not document
it on the used type

Found by phan strict checks

Change-Id: I12eb8bbc99179833ee3e42c1a7d1dc1443682ca6
2022-03-03 21:33:31 +01:00
Tim Starling
6ce4044fe1 Make runJobs.php die peacefully if the DB server goes away
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
2022-02-10 15:17:43 +11:00
daniel
dcef1674a5 Allow main settings file to be selected via env variable.
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
2022-02-06 21:13:00 +01:00
jenkins-bot
3843d16823 Merge "Reapply "SettingsBuilder: allow maintenance scripts to manipulate config"" 2022-01-27 17:53:01 +00:00