Commit graph

9 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
Umherirrender
fd4151da9e maintenance: Add caller when running query builder
Change-Id: I886306ef047eb3272b6ee9287f49c7b52358c6c7
2024-05-31 19:17:36 +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
Amir Sarabadani
69cabb628c maintenance: Migrate to expression builders
This was somehow left out

Bug: T210206
Change-Id: I70851b5b99fa865dbfd629caf2c1866c85418350
2024-01-17 20:27:08 +01:00
Amir Sarabadani
5a3e6564e4 maintenance: Migrate to DeleteQueryBuilder
Bug: T353219
Change-Id: Iecb55ab3f905ee9ed4e32e9cbb58c36f8cacf669
2024-01-02 13:13:49 +01: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
Kevin Israel
77dd4518ed pruneUnusedLinkTargetRows.php: Fix batching and DELETE query
* Avoid a possible one-row gap between batches: when lt_id is equal to
  the maximum ID for the current batch, it is not included in the next
  batch, so should be included in the current batch.
* Do not include lt_id values greater than $maxLtId in the final batch.
* Fix a bug that, if any unused linktarget row is found, would result in
  deletion of ALL ROWS in the table (not just the unused ones).

Follows up 62a01b7e8c.

Change-Id: Iba5643a13068c57fae2b1791f5c90ef9456aa78c
2022-09-19 08:54:15 -04:00
Amir Sarabadani
a9256d73fc pruneUnusedLinkTargetRows: Avoid deletion if there is nothing to delete
Otherwise it fatals when it tries to select with empty array.
Wikimedia\Rdbms\Platform\SQLPlatform::makeList: empty input for field lt_id

Follow up to I59fd88368e8

Change-Id: Ifc989b6527777a73bda9922006ea7cea2c4c0331
2022-09-16 11:04:51 +02:00
Amir Sarabadani
62a01b7e8c Introduce pruneUnusedLinkTargetRows maint script
To clean up unused linktarget rows

Bug: T299417
Change-Id: I59fd88368e84db7a22bf1e24c432b5bc669df1dc
2022-09-07 19:56:56 +02:00