Commit graph

34 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
Dreamy Jazz
fb713b5f8a Test migrateUserGroup.php
Why:
* The maintenance scripts in core are mostly untested and testing
  the less complex scripts will improve the test coverage in core.
* The migrateUserGroup.php maintenance script has a few bugs which
  were found by testing the script, and are fixed.

What:
* Add an integration test for migrateUserGroup.php
* Fix the maintenance script to:
** Correctly report the number of affected users (instead of
   affected rows)
** Clear the cache in the UserGroupManager when a batch is
   performed.

Bug: T371167
Change-Id: Ibd4c82332cbe83b7c5576a9e3bce6a99fa15c240
2024-07-28 14:24:59 +01:00
Umherirrender
fea5c2f687 Use expression builder to avoid raw sql via BETWEEN operator
Replace BETWEEN with >= and <= operator

Change-Id: Ic21b6f4cc11c773c967d9d4c5f20e762c2ff9629
2024-04-21 14:24:21 +02: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
Alexander Vorwerk
0831905a45 Migrate some usages of Database::update() to UpdateQueryBuilder
Bug: T353219
Change-Id: I98bf4c2e2c3023fba226ac10826e52a1108b8aea
2024-01-17 15:24:45 +00:00
Amir Sarabadani
5a3e6564e4 maintenance: Migrate to DeleteQueryBuilder
Bug: T353219
Change-Id: Iecb55ab3f905ee9ed4e32e9cbb58c36f8cacf669
2024-01-02 13:13:49 +01: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
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Umherirrender
bf5a104146 Remove wfWaitForSlaves when using Maintenance::commitTransaction
Maintenance::commitTransaction is calling waitForReplication already.
No need to wait a second time, hopefully the lags are 0 already.

Change-Id: Id457ed2cdd6bfd9663665ba0cd5c4e3dd640b738
2018-02-26 21:05:33 +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
Phantom42
9b4d71f531 Cast block start to int in maintenace SQL
Bug: T182209
Change-Id: Ic2dbbacdf0a77b8ac531cff8e11be0da8014e083
2017-12-08 22:03:49 +02: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
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
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
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
Aaron Schulz
fa8e1a9b00 Clean up transactions in maintenance scripts
Add transaction methods to complement getDB().
This makes it easy to grep for direct begin()/commit()
calls to IDatabase by having script use their own
wrapper. Maintenance scripts are one of the few places
that can (and need to) use begin/commit instead of the
start/end atomic methods.

Eventually, there should be almost no direct callers
and those methods can be made stricter about throwing
errors on nested calls.

Change-Id: Ibbfc7a77c0d2a55f7fc2261087f6c3a19061e0aa
2015-12-30 23:40:35 +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
Timo Tijhof
2549c49562 (bug 40340) Fix cache issues with changing user groups
* migrateUserGroup.php: Call User::invalidateCache

* While at it, also fix the issue where User::clearInstanceCache
  did not clear cache for User::getGroups.

  Although it does clear the caches of methods used to calculate
  other group-related lists (such as User::getEffectiveGroups),
  the one for the query from user_groups was still cached in
  $this->mGroups.

  Presumably this was forgotten when this pattern was introduced
  as the instance cache precedes the user_group table.

Change-Id: I22abdba00f8ccf587a3d7696e57970ed4653afc8
2012-12-28 14:35:49 +00:00
Demon
67e23ec357 Merge "Update migrateUserGroup to deal with primary key issue" 2012-08-30 20:20:59 +00: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
b2a7aafbed Improve documentation of maintenance scripts.
Change-Id: I93e80edcfc3dc2d5630f7514808cafc22daf39f7
2012-07-25 21:35:53 +02:00
Mark A. Hershberger
d5fced5058 Update migrateUserGroup to deal with primary key issue
Update migrateUserGroup so that if a user is in both the old group and
the new group, the script still succeeds.  Otherwise, it will fail
with violations to the PRIMARY KEY index on the user_groups table.

Change-Id: I7bfda03f5735633d03b81092dad29d73293cd182
2012-06-29 23:39:25 +04:00
Sam Reed
c47f83a4d4 More __METHOD__ in our madness 2012-02-24 18:45:24 +00:00
Platonides
62053ac8fd Merge r86398 into the old wfWaitForSlaves. Update core calls.
maintenance/waitForSlave.php still calls the old prototype.
Most instances were replaced with 
sed -i 's/wfWaitForSlaves( [0-9]* );/wfWaitForSlaves();/' ./maintenance/initEditCount.php ./maintenance/updateRestrictions.php ./maintenance/updateSpecialPages.php ./maintenance/importDump.php ./maintenance/moveBatch.php ./maintenance/storage/resolveStubs.php ./maintenance/storage/trackBlobs.php ./maintenance/storage/fixBug20757.php ./maintenance/storage/moveToExternal.php ./maintenance/storage/compressOld.inc ./maintenance/populateSha1.php ./maintenance/deleteDefaultMessages.php ./maintenance/migrateUserGroup.php ./maintenance/importImages.php ./maintenance/runJobs.php ./maintenance/archives/upgradeLogging.php ./maintenance/deleteBatch.php ./maintenance/populateLogSearch.php ./maintenance/populateLogUsertext.php ./maintenance/gearman/gearmanWorker.php ./maintenance/populateRevisionLength.php ./maintenance/refreshLinks.php ./maintenance/deleteSelfExternals.php ./maintenance/upgrade1_5.php ./maintenance/rebuildFileCache.php ./includes/job/RefreshLinksJob.php ./includes/installer/MysqlUpdater.php ./maintenance/convertUserOptions.php ./maintenance/populateParentId.php ./maintenance/runBatchedQuery.php ./maintenance/upgrade1_5.php ./maintenance/waitForSlave.php ./maintenance/populateCategory.php ./maintenance/importImages.php
2011-04-20 00:12:06 +00: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
Sam Reed
659778619c Stylize maintenance folder.. 2010-05-22 16:50:39 +00:00
Alexandre Emsenhuber
87e7919e62 * svn:eol-style native
* svn:mime-type image/svg+xml on extensions/LiquidThreads/icons/quote.svg
2009-09-07 13:18:54 +00:00
Aaron Schulz
2142fb46af May as well use the master for start/end points 2009-09-01 22:37:37 +00:00
Aaron Schulz
c578da64af Added a script to move users from one group to another 2009-09-01 20:53:55 +00:00