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
f4e005971c Use assoc array for column alias in select queries
Simplify writing the alias by using 'alias' => 'function' syntax.

Change-Id: I9d96550c957d4dd4ea065d8ad93b6d3f07ac3483
2024-01-08 21:47:45 +01:00
Bartosz Dziewoński
e89be77475 Remove allowances for nullable rd_interwiki and rd_fragment
After the other changes in T346290 these fields can never be null.
The only place that needs to handle null values is the migration
script fixInconsistentRedirects.php.

Bug: T346290
Change-Id: I0235c4be93b203f369b29522b54c0110ee8d61e9
2023-10-03 19:29:55 +02: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
Derick Alangi
74033c50cd maintenance: Begin using Maintenance::getServiceContainer()
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
2023-09-04 10:39:58 +00:00
Umherirrender
160411d4cf Simplify WHERE conditions with field = '' OR IS NULL
Syntax supported since 26235c73

Change-Id: I397c76d4aba753a1629383559b95df86514f19ff
2023-07-01 22:17:42 +02:00
Derick Alangi
988be947d0
DoubleRedirectJob: Inject appropriate service into job p.1
As a first pass, inject various services into the job as this is
now supported by JobFactory.

The second pass will have to survey callers of fixRedirects() and
pass in various services that would be used in the static method.
Also, we need to do same for getFinalDestination() which needs a
DBLoadBalancerFactory service.

Bug: T265942
Change-Id: If61a32b6ce32dc934533603a0e99414ab5771909
2023-07-01 19:59:18 +03:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Umherirrender
9ad71e8ef9 fixDoubleRedirects.php: Work only with proper titles
Bug: T314735
Change-Id: I7a1b3ae3431a4bc41b314bbd70b0458b87ae5296
2022-10-04 19:23:07 +00:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Derick Alangi
11fbdc01bf jobqueue: Fix max no. of double redirect jobs in job queue
Introduce a constant to track the maximum number of double redirects
jobs in the job queue. Before we allow 10000 to spread in the code
base, we can just change the constant now and references of this value
will be changed.

Does this qualify to be a configuration or a regular constant will do?

Change-Id: I10c45a8c1cd5b3382edebf9a05f4b3f94f5327df
2021-11-26 19:59:41 +01:00
Reedy
c7eb28aac9 Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
2020-05-21 01:06:05 +00: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
Bryan Davis
9e34eeff23 Maintenance: add fatalError() method
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
2017-11-21 21:34:16 -07:00
Timo Tijhof
1e0a992f6c maintenance: Consistently use hasOption() for boolean options
We already do this in many places, but there were also still plenty
of getOption(, false) calls. Change these to hasOption() for consistency.

Change-Id: I74f91a5bf5a8036496ab1f493e5862a04d27ec0f
2017-07-19 14:52:21 -05:00
James D. Forrester
242df680ce maintenance: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

This includes renaming fixBug20757.php to fixT22757.php for similar consistency.

Change-Id: If81a590d658fbd82c20c54ac47dfdc8856745ca3
2017-02-21 18:32:44 -08: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
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
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
withoutaname
7869747ff4 Remove RequestContext from edit.php and fixDoubleRedirects.php
Change-Id: I9388e6b3fec3c8ea92099aeaf010dd067f62a20f
2014-07-23 20:30:08 +00:00
Alexandre Emsenhuber
4c4d3051e7 Don't use isset() to check for null
Fixes in maintenance/

Change-Id: I300a2a0cb240cb3f9c1d0c76d4575f93e9706b59
2014-05-10 14:23:50 +02:00
Siebrand Mazeland
f2f31fadc7 Update formatting in maintenance/ (2/4)
Change-Id: I2b791d3bff0de464b6bdaaeae0622c065389c31c
2014-04-23 20:08:42 +02:00
Siebrand Mazeland
80dd48238c Pass phpcs-strict on maintenance/ (5/8)
Change-Id: I156b547b504e7267ea43deff4b8c532635508e81
2014-04-23 11:27:25 +02:00
jenkins-bot
853e86af36 Merge "Provide RequestContext from fixDoubleRedirects" 2014-03-31 16:21:21 +00:00
Mark A. Hershberger
76416e2a9b Provide RequestContext from fixDoubleRedirects
Lots of code depends on RC having the title.  I think setting it to
titleA is correct here, but maybe it should be titleB.

Bug: 62966
Change-Id: I875e1bf8f6d3468ea78c5a557a07cb6384965514
2014-03-22 22:53:26 +00:00
Ladsgroup
16a5102765 Change URLs to mediawiki.org in comments to HTTPS
These are only documentation fixes
http://www.mediawiki.org --> https://www.mediawiki.org

Change-Id: I62ad42be1a3aac410cc53e98ce79389ceddd8988
2014-03-20 16:59:46 +00:00
umherirrender
2fb4181ad4 Remove extra parenthesis on where conditions
No need for parenthesis there, because Database::makeList always add
parenthesis around raw where clauses.

Also replaced hard coded quotes by Database::addQuotes

Change-Id: Idcfea54383ac1ba22daa38fba81b883dc0d883f6
2014-01-04 22:03:02 +01: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
Platonides
a1e7329d8f Use JobQueueGroup::singleton()
Replaces usages of the deprecated pop() and insert()/insertBatch()
methods of Job class.

Change-Id: I5572c9e31a14bd660d7e3b9aa7792d0be9a26103
2012-12-07 20:30:45 +01:00
Timo Tijhof
f85255bd3b (bug 40352) fixDoubleRedirects.php: Support interwiki redirects
While at it, prettified code a bit and added list to output.

Change-Id: I989b5742ad46a9dd8c928a4ff5f76c869924730e
2012-09-26 09:16:42 +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
02e15ebd0b Improve documentation of maintenance scripts.
Change-Id: I0e2869970c46f4fd14b792f2978cc1ba9d8550be
2012-07-10 18:50:19 +02:00
Siebrand Mazeland
75c6696aa8 Use consistent notation for "@todo FIXME". Should update http://svn.wikimedia.org/doc/todo.html nicely. 2011-05-17 22:03:20 +00:00
Ilmari Karonen
aa3357a932 followup r81408: fix option desc and year in copyright statement 2011-02-02 21:30:02 +00:00
Ilmari Karonen
7df8a6f2a4 followup r81408: fix class name in comment 2011-02-02 19:33:32 +00:00
Ilmari Karonen
846c60b9ae Add a maintenance script to fix double redirects (and corresponding edit summary messages). Still lacks some features like batch querying, but basically it works. 2011-02-02 19:25:53 +00:00