Commit graph

24 commits

Author SHA1 Message Date
Umherirrender
76719d8425 maintenance: Replace deprecated Maintenance::$mOptions
Change-Id: I1b48b3c0b0e4bda5b61307725a2f08bbb5bbaaa9
2024-08-29 22:08:23 +02:00
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
Bartosz Dziewoński
978d739bc6 Replace single-value $db->buildComparison() with $db->expr()
Find:
->buildComparison\( ('..?'), \[(\s*)([^\],]+) => ([^\],]+)(\s*)\] \)

Replace with:
->expr($2$3, $1, $4$5)

Change-Id: I2cfc3070c2a08fc3888ad48a995f7d79198cc336
2023-10-22 01:05:47 +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
Amir Sarabadani
310333906a maintenance: Switch simple calls of Database::select to SQB
Done semi-automatically via a php parser written on top of ANTLR4.

Bug: T311866
Change-Id: I33f5b6703c0aa9c80c907a21c2a770e30642edd3
2023-07-19 17:42:23 +02: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
thiemowmde
2574ef4bfd Replace some in_array( array_keys() ) with simple isset()
Usually it doesn't make much of a difference, but potentially can
when the array is big. The extra conversion also makes the code more
complicated, I would argue.

Change-Id: I91b9e82ca801dd64523557d616462b7ea7edc7b0
2022-11-14 17:56:34 +01:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Derick A
e7493e35bd maintenance: Avoid deprecated usage of RepoGroup::singleton()
Change-Id: I694cf124a5f90f368309b04f8ae0b843a98816eb
2020-02-18 21:28:17 +00:00
Thiemo Kreuz
007bfbf835 maintenance: Add missing limit parameters to some explode()
This is, in theory, a loophole that can not only cause such code to
consume suprising amounts of memory and runtime. It can also create
suprising results. For example, an input like

 -param="might contain a = char"

might result in a cut-off value.

Not so much of a problem in a maintenance script. But still good
practice, I find.

Change-Id: I14fb278e6fdb61d0c486ca7e23229851ea479408
2019-03-01 17:17:40 +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
Max Semenik
dac20d0ffa Introduce Maintenance::getBatchSize()
Just to isolate the internals. Fix most of usages in the core.

Change-Id: I8b3e9ca1f42b7c49ee57f17b88ca2fc7b404f342
2017-11-05 13:26:12 -08:00
Aaron Schulz
f525c72590 Rename getSlaveDB() FileRepo method to getReplicaDB()
The old name is left as an alias.

Change-Id: I60ab2cd5ce05df4247d5e25b017d2debee56554e
2016-11-18 07:42:39 -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
Aaron Schulz
b645d0f8f9 Make PurgeChangedFiles actually purge old versions too
Change-Id: I7aa746535ceae7d19c492145c3254d55511a8576
2016-08-10 16:29:10 -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
Aaron Schulz
c518eaf0e0 Removed LocalFile::purgeHistory method
* This just purges an unused key as OldLocalFile::getCacheKey
  simply returns false (rather than a key with "oldfile" in it)

Change-Id: Ic7dda9bf192803a75eaa9bd3bb5a145ad1409dd2
2015-04-27 17:36:02 -07:00
Timo Tijhof
ff6513f28b Remove '@section LICENSE'
This was used in 2 special classes, the logger classes and spread
to a few other random classes.

Afaik this has no meaning. Is for something we don't use, and
goes against the meaning of '@section' in Doxygen, which we do
use.

In Doxygen output, all LICENSE references became links to
ProfilerXhprof (the one Doxygen encoutered first).

Bug: T72328
Change-Id: Icc7c443245c70bc0f549bee7d105eef5691c864d
2014-11-26 02:20:55 +00:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
umherirrender
f153998317 Fixed spacing
- Removed double spaces
- Added space after if/switch/foreach
- Removed space on elseif
- Added space around parentheses
- Added newline at end of file
- Removed space before semicolon at end of line

Change-Id: Id40b87e04786c6111e6686d7f7eea1e588bdf37d
2013-11-19 19:03:54 +01:00
Aaron Schulz
96a3d3a608 Added --sleep-per-batch to purgeChangedFiles.php
Change-Id: Ied673879b91034cc4ae5e730963fab443eda55f9
2013-10-24 16:43:29 -07:00
Bryan Davis
f90a9ec93a Add script to purge changed files from cache
This maintenance script enhances the prior purgeDeletedFiles script to
optionally also process create and modify events that may have left
stale information in front-end caches.

Changes from purgeDeletedFiles:
* `--starttime` & `--endtime` are now required
* `--type` allows selecting 'created' and/or 'modified' events in
    addition to 'deleted' events.
* `--dry-run` to list affected files but perform no purges
* `--htcp-dest` option to restrict HTCP broadcast messages

Change-Id: I7181ea461ba9758747bff4fd70530d00dab492cc
2013-10-08 14:17:25 -06:00