Commit graph

39 commits

Author SHA1 Message Date
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
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
2024-08-27 13:22:29 +01: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
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
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Reedy
44cebea941 Update wfGetDB calls in Maintenance scripts to use getDB()
Change-Id: I9ad6745d84506b736dae94747256caac89715899
2016-01-02 16:58:23 +00:00
Siebrand Mazeland
0619388d87 Pass phpcs-strict on maintenance/ (3/8)
Change-Id: I453ecc474139c7a5f1d0d20306ad28c2cee80ec9
2014-04-22 21:25:52 +00:00
Alexandre Emsenhuber
f174d2c404 (bug 50025) rebuildall.php script needs database admin rights
It calls rebuildtextindex.php, which use the ALTER command.

Bug: 50025
Change-Id: Ifbd1d1d1d9c0d6f53ce13b92d94824beee67963f
2013-06-25 07:24:13 +00: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
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
6015071beb Improve documentation of maintenance scripts.
Change-Id: I21b4fb873e88026108754eb7206e62c82648df0e
2012-08-09 19:28:14 +02:00
Chad Horohoe
26505b170a Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.
Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
2011-01-13 22:58:55 +00:00
Chad Horohoe
a548c1d87a Get rid of a bunch of $wgDBtypes in maintenance/ 2010-12-10 13:56:17 +00:00
Mark A. Hershberger
617a5b1e15 Whitespace fixup under tha maint directory. 2010-12-04 03:20:14 +00:00
Sam Reed
659778619c Stylize maintenance folder.. 2010-05-22 16:50:39 +00:00
Max Semenik
0620bb65b0 Now that rebuildtextindex.php is not MySQL-only, rebuildall.php should also take it into account 2009-11-07 20:55:57 +00:00
Tim Starling
ce9228369f * Rewrote commandLine.inc to be a simple wrapper around Maintenance.php
* Don't show help if the first argument is "help", only show it if there is a "--help" option. That makes more sense for the scripts that accept filenames as parameters and is the backwards-compatible behaviour.
* Renamed spawnChild() to runChild(), spawn implies creating a new process to run simultaneously with the old one
* Removed error_reporting override, that's a matter for local policy
* s/private/protected
2009-09-04 08:02:00 +00:00
Chad Horohoe
567f244e36 Revert r54244 which was stupid and fix this properly. Require commandLine.inc/Maintenance.php using the full path every time. 2009-08-03 21:56:41 +00:00
Chad Horohoe
a1c51e18af Merge maintenance-work branch (now with less errors!):
* Docs have been updated to indicate the standard on how to write maintenance scripts (MW.org docs will follow) Have ported vast majority of maintenance scripts to new format. Remaining ones (mostly FiveUpgrade-related) are a bit more tricky. commandLine.inc is untouched for now. Many have gotten code-style updates as well. Deleted .inc files were only used by their .php counterparts, and have been merged into single files.
* (bug 11867) Lock error on redirect table when running orphans.php
* (bug 16322) Allow maintenance scripts to accept DB user/pass over input or params
* (bug 18566) Maintenance script to un/protect pages
* initStats overhaul, now uses class SiteStatsInit. Also fixes bug 18930
2009-08-02 19:35:17 +00:00
Chad Horohoe
221967100c (bug 17948) Maintenance scripts now exit(0) or exit(1) as appropriate 2009-04-06 14:41:33 +00:00
Alexandre Emsenhuber
087a9f70c5 WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>

Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage

One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
Greg Sabino Mullane
cab0a1b096 Fix for bug 13251, allows some rebuld scripts to work with Postgres. 2008-03-14 04:39:18 +00:00
Brion Vibber
8d1b3602e3 Cleanup from r28400: avoid duplication between manually calling multiple passes of recent changes rebuild by giving them a nice wrapper function. 2007-12-20 02:50:16 +00:00
Aaron Schulz
40e6f302c0 There is a pass three now (may be a four in the future)...don't really like this duplication here 2007-12-11 22:14:44 +00:00
Aryeh Gregor
a15c419b3d Remove ?>'s from files. They're pointless, and just asking for people to mess with the files and add trailing whitespace. (Yes, I looked over every one and reverted those that were bogus. Slash-enter a million times in less worked well enough, although it was a bit mind-numbing.) 2007-06-29 01:19:14 +00:00
Antoine Musso
c771fc9c96 Use Doxygen @addtogroup instead of phpdoc @package && @subpackage 2007-01-20 15:09:52 +00:00
Brion Vibber
908c51e127 Revert to r15092; massive breakage, unable to connect to MySQL at all 2006-06-27 16:11:47 +00:00
Greg Sabino Mullane
ef89ec541c Add concept of a distinct port separate from a server.
Add some functions to DatabasePostgres.php.
2006-06-27 15:37:35 +00:00
Brion Vibber
17f6f800cd typo 2005-09-17 07:52:33 +00:00
Antoine Musso
6bbcf091bf Phpdoc comments and place holder. Part of the subpackage "maintenance", archives in subpackage "maintenanceArchive" 2004-09-03 20:33:01 +00:00
Brion Vibber
18f1971ffd Fix rebuildall on case-sensitive unix filesystems.
Bug 52: rebuildall.php maintenance script fails
http://bugzilla.wikipedia.org/show_bug.cgi?id=52
2004-08-14 19:23:51 +00:00
Brion Vibber
666306c953 Fix some of the rebuild scripts 2004-08-11 09:02:20 +00:00
Tim Starling
2ba5e0e718 * Moved content from liveCmdLine.inc into commandLine.inc, obsoleting the former.
* Put some option handling code in commandLine.inc which is untested and unused (for the moment).
* Converted all existing command line scripts to use the standard header and argument array.
* Did a quick test of compressOld.php, rebuildall.php and rebuildMessages.php to check for breakage.
* rebuildall.php was broken due to the unmaintained rebuildlinks.php, so I converted it to use refreshLinks instead. Required splitting into refreshLinks.inc and refreshLinks.php
2004-06-15 15:18:50 +00:00
Tim Starling
8f22cb45b1 include_once -> require_once 2004-05-07 13:43:10 +00:00
Brion Vibber
0332f4c598 Fix for compatibility with short_open_tag = Off 2004-02-18 02:15:00 +00:00
Mr. E23
d90d721572 Changed function call to use new function rebuildLinkTables(), replacing the old rebuildLinkTablesPass1() and rebuildLinkTablesPass2() 2003-11-28 10:43:03 +00:00
Brion Vibber
04e6adebb8 Maintenance script fixes 2003-11-17 12:55:24 +00:00
Lee Daniel Crocker
f3a4fd56c0 Completed several maintenance scripts for index rebuilding. 2003-05-02 22:55:37 +00:00