Commit graph

91 commits

Author SHA1 Message Date
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
Timo Tijhof
5bfa31187b maintenance: Move $IP and MEDIAWIKI assignment to doMaintenance.php
Per 4eb1e679d5, these are now documented as the bare minimum
entry point responsibilities. For WebStart these are already
consolidated, but for the CLI use case they were a bit scattered.
Consolidate these in the CLI entry point (doMaintenance.php)
for clarity.

* $IP was previously assigned in Maintenance::__construct,
  which is called from doMaintenance.php.
  It still executes at the same logical time, one line above
  'new $maintClass()'.

* MEDIAWIKI was (for CLI) previously defined in Maintenance::setup()
  which is called from doMaintenance.php.
  This is now done a few lines earlier, and in the entry point file
  instead.

For both of these, they are still available and set in all the same
scenarios as before.

Bug: T246076
Bug: T250003
Change-Id: I2a6f5e997a36502535eb383a95deac0ce74d83fb
2020-04-14 19:33:13 +00:00
RazeSoldier
eadde762b0 Make sure DBLoadBalancerFactory service is not disabled
After b873e929, when the CLI installation failed, the script will throw
a ServiceDisabledException.
This is because the installer disables DBLoadBalancerFactory service
during instantiation and throws the exception because the installation
failed to restore the service.
So I check if the service is enabled before try commit
the master changes.

Bug: T229601
Change-Id: Ia7589d14ee55bcb03a64856b6dd2c81d8bda783c
2019-11-07 00:09:18 +08:00
Marius Hoch
3f7fa975e0 doMaintenance: Try to print errors to stderr
Don't mix them in with stdout (which might be redirected,
like dump output, making the errors hard to discover).

Change-Id: Ibed8c0e8dde3e44de60bf32abd3fc5ce5d29e1ba
2019-07-16 13:15:57 +02:00
jenkins-bot
243a466018 Merge "Print chained exceptions when maintenance script fails." 2019-05-29 20:21:01 +00:00
Reedy
9f2ffdfbd4 Remove "Squiz.WhiteSpace.FunctionSpacing" from phpcs exclusions
Change-Id: I78b3315f26ab91b6b443f5b028a635552f82f5a3
2019-05-11 02:44:26 +01:00
Bill Pirkle
4d5edb65f3 Allow extensions to add params to the update.php maintenance script
T110209 caused maintenance scripts to fail on unknown parameters,
which is normally desirable.  However, some extensions (notably
SemanticMediaWiki) need to support additional params and had no
way to add them to the list of expected parameters.  It will
now be possible them to update.php via a new hook:
MaintenanceUpdateAddParams.

Bug: T213893
Change-Id: Ia40949ccb2f32090f21e0f3f7e5b9c4aef322330
2019-03-26 21:12:49 -05:00
daniel
e1e5beb43e Print chained exceptions when maintenance script fails.
PHP supports exception chaining. This patch will output the error
message and stack trace not just for the latest exceptions, but for all
exceptions in the chain, using the Exception::getPrevious() method. This
avoids the problem where aftereffects obscure the actual problem, because
only the last exception in the chain was printed.

Change-Id: If577c5c89bb3b3e5766400fff07d8cc0a2d82610
2018-12-10 13:27:36 +00:00
Tim Starling
72f2e98499 Exit maintenance script with non-zero status if execute() returns false
There's a whole lot of shutdown code in doMaintenance.php that is
skipped when you use exit() directly. In HHVM by default, destructors
are not even called.

There are a few cases where maintenance scripts want to do something after
doMaintenance.php returns, so returning null should continue to mean no exit.

Change-Id: I0891e2ee3af7ef2c64c03b70edcf9e281ce1e7ba
2018-05-31 16:46:14 +10:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Chad Horohoe
e7c86d8537 Remove some dumb headers with my name in it
Change-Id: Ib34b623b47fb92f1383bc5c55c50a16dd6d49abd
2017-11-30 15:39:46 -08:00
Timo Tijhof
8b7bafec21 Setup: Merge PreConfigSetup into Setup.php
Follows-up 41ea7e2fef.

The following previously happened between PreConfigSetup and Setup
and must now happen either before it, after it, or moved inside it.

* WebStart: Detect missing composer.
  This must be after Autoloader/Vendor but before the first call to
  wfDebugLog (or other loggers) so that we can output a more descriptive
  error instead of a generic "Unknown class" fatal error.
  Moving it to before Setup is too early, and after is too late.
  Move it to within Setup.php and make it work in CLI mode.

* WebStart: Install header callback
  Moving it to before Setup is too early, and after is too late.
  Move it to within Setup.php (no-op in CLI mode).

* WebStart/Maintenance: Load LocalSetings.
  Must be between PreConfigSetup and Setup.
  Move to Setup.php to maintain execution order.
  Utilise MW_CONFIG_File for custom handling in Maintenance.php.

* WebStart: Initialise output buffering
  Utilise (new) MW_SETUP_CALLBACK hook.

* WebStart: Display NoLocalSettings.php
  Utilise MW_CONFIG_CALLBACK hook.

* Maintenance: Setting $wgLocalisationCacheConf, calling Maintenance::finalSetup.
  Utilise (new) MW_SETUP_CALLBACK hook.

Change-Id: I633a6ff235b4275391c48034c0525d2fbfa3fecd
2017-10-24 23:50:54 +00:00
Tim Starling
41ea7e2fef Split common pre-setup code out of WebStart/doMaintenance
Introduce PreConfigSetup.php, which is common file-scope code run before
LocalSettings.php.

I'm not maintaining autoload.ide.php since it supports closed source
software which I don't have, and it apparently needs significant work to
make it not be weird and hacky.

Change-Id: I44ac69b6b00a51d015546b9766d89d1c59749334
2017-08-23 14:00:34 +10:00
addshore
ba87c9a6c6 Allow install.php to run env-checks with no db
Bug: T169668
Change-Id: Ibb05b26cbf2d26c02ee7f26497e16d2c98e97de2
2017-07-04 19:39:42 +01:00
addshore
b12086b618 Get ConfigFactory & MainConfig from MediaWikiServices
Change-Id: Iafdd7e00747060572463ffb05aae4543f3a06163
2016-11-23 00:12:38 +00:00
Aaron Schulz
66b0ad56df Postgres installation fixes
* Make isTransactableQuery() exclude CREATE/ALTER.
  Starting transactions for schema changes like this can cause
  errors as it is not supported for MySQL and some Postgres
  operations. Note that temporary tables are session-level,
  so they are not effected by this change.
* Clean up the transaction logic in determineCoreSchema()
  so a transaction is not left dangling.
* Fix broken getSchemaPath() call in PostgresInstaller.
* Avoid warnings in DatabasePostgres::closeConnection() if
  mConn is already unset.
* Commit master changes in doMaintenance.php before running
  deferred updates, just as MediaWiki.php does.
* Change E_WARNING to E_USER_WARNING to avoid notices in the
  default /rdbms error handlers.
* Also avoid trying to rollback in MWExceptionHandler if the
  LBFactory service is disabled, which just results in an error.

Bug: T147599
Change-Id: I64ccab7f9b74f60309ba0c9a8ce68337c42ffb0f
2016-10-17 15:06:38 -07:00
Aaron Schulz
16b4e3a9f1 Avoid global state in DatabaseBase::factory()/query()
Change-Id: Ibb4f1c0dafea071a1c34e0cd5b5c15b8b4bb7bc6
2016-09-16 00:40:57 +00:00
Aaron Schulz
a3dacac90f Support masking the WRITE_SYNC latency from ChronologyProtector
* Use OutputPage::output() as the method to mask latency, since it
  takes a good while to run. By the time it runs, cache replication
  should have caught up, so the reap call will likely not block.
* For redirects emitted after changes in POST, instead of masking
  with OutputPage, add a parameter to the redirect and block on
  the positions appearing. This uses the redirection RTT to mask
  the replication latency.

Change-Id: Ib23690c302e8033610fef9a0ef451dafe8a5803e
2016-09-12 23:58:49 +00:00
Aaron Schulz
44f486ffac Use transaction listener to run DeferredUpdates in CLI mode
This sets triggers on master position waits typically called
after commitMasterChanges() or in commitAndWaitForReplication().

Change-Id: I127a8fe3cfc319abfa84fcd221ee2dae191c6d3b
2016-09-01 03:30:00 +00:00
Kunal Mehta
4de667f3c2 maintenance: Allow having a nicer error message if an extension isn't enabled
Maintenance scripts can be invoked regardless of whether an extension is
enabled on a wiki or not. On wiki farms where some wikis may have an
extension or not, this can potentially be rather confusing. Especially
when the script bails out with a fatal class missing error or a database
table missing.

This allows maintenance scripts to specify that they require an
extension by calling:
 $this->requireExtension( 'ExtensionName' );
in the script's constructor.

Bug: T141531
Change-Id: Icfbf063bb9c9ac9e55c3a5a8ed815528a2c1ce1e
2016-07-30 10:38:51 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
58cffd04b8 Pass __METHOD__ to load balancer commit/rollback methods
Change-Id: I3fd87908c2a493fae49de6a29efe79f8d433c112
2015-12-22 18:30:20 -08:00
Aaron Schulz
a8590172c8 Make DeferredUpdates::doUpdates always commit per task
* All callers are either using commit already or would be fine
  using it (e.g. Maintenance scripts and JobRunner that have
  no real transaction open).

Change-Id: I9f54b27619da6dac2cb63d255995aabc4ee78002
2015-10-22 01:27:08 +00:00
Kunal Mehta
a0d422e67f maintenance: Defer initilization of 'main' Config until after Setup.php runs
Bug: T90680
Change-Id: I72d6306404bc1f6c7a605853130a026e9858b493
2015-03-03 23:51:44 -08:00
Erik Bernhardson
d99963bc2a No such method Exception::getText()
It looks like a recent change converted this try/catch
statement from MWException to Exception, unfortunatly it
is still calling a method that only exists on MWException.

We arn't doing anything with the exception but exiting.  Lets
just allow the exception to be uncaught and fail naturally. The
uncaught exception will still output an error and return
a non-0 exit code.

Change-Id: I3e0e9d283c255d2aba8139d675943e93d7cb021a
2015-02-03 11:09:54 -08:00
Aaron Schulz
6921770414 Updated some try-catch statements: MWException -> Exception
Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
2015-01-09 17:20:22 -08:00
Kunal Mehta
bfe4ddd810 Implement extension registration from an extension.json file
Introduces wfLoadExtension()/wfLoadSkin() which should be used in
LocalSettings.php rather than require-ing a PHP entry point.

Extensions and skins would add "extension.json" or "skin.json" files
in their root, which contains all the information typically
present in PHP entry point files (classes to autoload, special pages,
API modules, etc.) A full schema can be found at
docs/extension.schema.json, and a script to validate these to the
schema is provided. An additional script is provided to convert
typical PHP entry point files into their JSON equivalents.

The basic flow of loading an extension goes like:
 * Get the ExtensionRegistry singleton instance
 * ExtensionRegistry takes a filename, reads the file or tries
   to get the parsed JSON from APC if possible.
 * The JSON is run through a Processor instance,
   which registers things with the appropriate
   global settings.
 * The output of the processor is cached in APC if possible.
 * The extension/skin is marked as loaded in the
   ExtensionRegistry and a callback function is executed
   if one was specified.

For ideal performance, a batch loading method is also provided:
 * The absolute path name to the JSON file is queued
   in the ExtensionRegistry instance.
 * When loadFromQueue() is called, it constructs a hash
   unique to the members of the current queue, and sees
   if the queue has been cached in APC. If not, it processes
   each file individually, and combines the result of each
   Processor into one giant array, which is cached in APC.
 * The giant array then sets various global settings,
   defines constants, and calls callbacks.

To invalidate the cached processed info, by default the mtime
of each JSON file is checked. However that can be slow if you
have a large number of extensions, so you can set $wgExtensionInfoMTime
to the mtime of one file, and `touch` it whenever you update
your extensions.

Change-Id: I7074b65d07c5c7d4e3f1fb0755d74a0b07ed4596
2015-01-08 01:40:01 +00:00
Chad Horohoe
4e61f1bb8b Profiler code cleanup
- Put Profiler, ProfileSection and TransactionProfiler in their own
  files and rely on Autoloader to use them (maintenance has been
  using the autoloader here for some time--we don't profile the
  autoloader manually)
- This reduces overhead in WebStart/doMaintenance by only loading
  three functions at profiler initialization and defers until the
  first profiling call happens
- Inline callback functions in ProfilerSimpleText rather than having
  public static functions.
- Small comment and code formatting changes in various touched files.

Change-Id: Idf27677c068c50b847152c523a33e7f0c33fdeeb
2014-11-04 21:14:51 +00:00
Kunal Mehta
b016aa66dc Maintenance: Add an easy way to access Config instances
Change-Id: I97d50c624e988c70bb2ac0da4fc33957ce3cf524
2014-09-09 17:37:03 -07:00
withoutaname
2997b116f3 Remove check for wikimedia-mode file, which no longer exists
Change-Id: Ib463e7687b7b35147bddef68b9548e7b86c5ef52
2014-07-19 21:31:08 -07:00
Siebrand Mazeland
752c708149 Pass phpcs-strict on maintenance/ (6/8)
Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286
2014-04-23 09:27:41 +00:00
Chad Horohoe
518fa756f2 Remove $wgTitle from all maintenance scripts
Shouldn't be needed and aren't for any core operations. If any
extension relies on these $wgTitles being set in maintenance
environments those extensions are broken and should be fixed.

Change-Id: Ie02a5042ab96e155d783d56d5340dd0da8e3d55c
2014-03-12 18:28:47 -07:00
Chad Horohoe
4d6dad7100 Remove vestiges of AdminSettings.php
This has been deprecated and mostly unused for quite some time.
Remove the few remaining uses that exist.

Change-Id: I522ef138d291cf7567250fef1de34bb41673bc6c
2014-01-29 15:09:33 -08:00
umherirrender
0bc583af2c Move closing parenthesis from multi line if and function to own line
The Line continuation Coding conventions prefers the closing parenthesis
on the same line than the beginning curly braces. This is done for ifs
and functions.
Also move some boolean operator from the end of a line to the beginning
and changed some indentation to make the condition hopefully better
readable.

Change-Id: Id0437b06bde86eb5a75bc59eefa19e7edb624426
2013-12-01 21:39:00 +01:00
Siebrand Mazeland
e711503e7a Remove underscore from classes LCStore_*
iPart of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core, and are updated in
this change.

Change-Id: I432dc249d22053728013ae7d0d56c3c398021c5e
2013-11-17 22:09:31 +01:00
Kevin Israel
12c61d3e7f Remove remaining calls to MWInit methods
... as well as the require_once statements in includes/WebStart.php
and maintenance/doMaintenance.php, now that the autoloader lists
MWInit (since r85807 / c68957c5e3).

Also removed code paths in maintenance/userDupes.inc that seem to be
dead (class_exists( 'Revision' ) should always be true) and useless
global/require_once statements in languages/Language.php.

Follows-up Ic3e769f1fbad4f7ad26dd819406796fee48c6b45.

Change-Id: I48fd6810fdb923b3065ae98024912eb18d394415
2013-09-15 19:04:08 +00:00
Kevin Israel
052f1fcf30 Deprecate MWFunction::call and ::callArray
These functions existed to work around a bug (fixed in PHP 5.3) and
a missing feature (added in PHP 5.2) in older versions of PHP;
therefore, they are no longer necessary.

Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7
2013-07-19 18:48:51 -04:00
jeroendedauw
b1c73fc670 Move inclusion of the Composer autoloader to after inclusion of DefaultSettings
If it is before, settings set by extensions will end up being overriden.

Change-Id: Ibe80d621cfaa7258cfd759094a1e9f0008a469b1
2013-07-15 17:33:50 +02:00
Daniel Friesen
2740518620 Support installing PHPUnit using composer.
"phpunit/phpunit" already exists inside our composer.json's "require-dev" however this has been
entirely useless as we don't include the autoloader which would load composer's PHPUnit.

This change begins including composer's autoloader when present and also tweaks phpunit.php
to ensure PHPUnit isn't double loaded. As a result besides supporting PHPUnit via composer this
also means that we're ready to make use of any library we add to our composer.json in the future.

Change-Id: I891740e8fd3d237c5f473862027205d951f564b9
2013-06-07 02:07:27 -07:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
umherirrender
21751b9ba7 echo is not a function
Removed parenthesis after echo

Change-Id: Ia533aedf63b11d15dcc6a5cf75a56134a4b11d86
2013-05-09 19:52:45 +00:00
Tim Starling
1fe9340bb3 Remove hphpc support and deprecate related functions
hphpc has been superseded by hhvm, so support for hphpc is no longer
needed.

* Continue to use Preprocessor_Hash under HipHop since it is still
  faster under hhvm
* Keep $wgCompiledFiles for now, so that wikihiero doesn't give an error
  before Ic9d1e795 is merged
* Migrate the run-server script and associated configuration file to
  hhvm. Enable EnableStaticContentFromDisk since it doesn't seem
  ridiculously inefficient at first glance. Run from $IP rather than
  $IP/.. since hhvm is apparently not picky about sourcing files from
  outside of the current directory.

Change-Id: Ic3e769f1fbad4f7ad26dd819406796fee48c6b45
2013-05-09 08:28:05 +10:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
Aaron Schulz
820de0f13b Set up the profiler in CLI mode.
Change-Id: I7f36786573870b66b4f1e93c2fc2e444f1ae1252
2013-04-17 10:05:00 -07:00
Tyler Anthony Romeo
c628b6d121 (bug 42600) (bug 24375) Fix doMaintenance.php exit procedures.
Fixed the post-execution calls in doMaintenance.php
to perform proper cleanup after the maintenance
script runs (modeled after MediaWiki::restInPeace).

Added a global call to wfWaitForSlaves() and then
wfDoUpdates() in doMaintenance.php to ensure that
deferred updates are always performed at the end
of maintenance scripts (and that they're performed
after the slaves catch up to avoid lag).

Also added calls to shutdown the DB factory so
that implicit transactions are committed and the
connections are closed.

Change-Id: I6f9580559d75f4761c5ddb504b2e3380e2e562a3
2013-02-20 14:25:44 -05:00
Antoine Musso
f6b92231fd style: normalize end of files
By PSR2 PHP Standard, the files should ends with exactly one newline.
Some of our files have 2 or more and some other were missing a newline.

Fix almost all occurences of CodeSniffer sniff:
PSR2.Files.EndFileNewline.TooMany

I have not fixed the selenium files, I believe we will drop them.

Change-Id: I89fca8c1786fee94855b7b77bb0f364001ee84b6
2013-02-03 15:04:39 +01:00
daniel
2926b29da3 Log profiling info from maintenance scripts.
Previously, maintenance scripts did not log profiling info.

Change-Id: Ib63dd54b815cca774cd764f28505f9dbdfd02cfc
2013-02-01 11:23:21 +01:00
Platonides
1bb25971f2 Disable the db LCStore if the maintenance script doesn't need a db.
If $wgLanguageCode != 'en', loading of the language class will
go to the LCStore looking for the fallbacks, even if the script
doesn't need a database.

Change-Id: I6a1920ba02d146622f3a5647bf02ddec3e3da54b
2012-06-26 18:58:37 +02:00
Antoine Musso
27bfa2854f revert r102636
This move back the maintenance finalSetup code above core Setup.
If we really need to do any setup after core Setup has run, we should use
a new method in the Maintenance class. For example afterCoreSetup()
2011-11-24 09:41:54 +00:00