Commit graph

23 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
81c6df6a46 maintenance: Use expression builder instead of raw sql
Bug: T361023
Change-Id: Ieb229d8088cb1ff3f03e44f7ac99eb612f48bc7b
2024-07-22 22:29:20 +02:00
Umherirrender
8018e157e8 maintenance: Migrate to IDatabase::newUpdateQueryBuilder
Bug: T353219
Change-Id: Ic278c8534dad40a3f34674db2d5fbfbca5984da8
2024-04-14 18:47:55 +00: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
Daimona Eaytoy
6ddbd53eda Remove redundant empty() constructs (3)
empty() only makes sense when the expression it checks is possibly
undefined, otherwise it's equivalent to a truthiness check with the
additional downside of suppressing errors when it's not wanted.

Replace it with simple truthiness checks, using strict comparison when
that seems to help with polymorphic variables.

These were caught by a bespoke phan plugin.

Change-Id: Ide262162553d2da7e5388d05e8731529c44591c1
2023-09-08 23:37:23 +02:00
Tim Starling
95bd40b25c In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.

That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.

In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.

So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.

Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 10:16:08 +10:00
Amir Sarabadani
f783b02ff2 Migrate Database::upsert() calls to InsertQueryBuilder
Bug: T335377
Change-Id: I0e0c3f3a9150c7a62d8fff95fe8867bdce356071
2023-09-06 14:28:19 +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
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
Aaron Schulz
07036790cf Convert various callers to LoadBalancer::getConnectionRef()
Bug: T193565
Change-Id: I6dbeac4d5b11ded15263cfedfcae8cba170b5f18
2022-02-03 16:48:34 -08: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
5a318bd5bf Pass function name to database functions (maintenance scripts)
Useful for logging

Change-Id: I79fe037abcd74f56c935abc118d706bef0198124
2020-06-07 17:24:10 +00:00
Aaron Schulz
98a4fa1b37 Cleanup various calls to IDatabase::upsert()
Change-Id: Ic82154f6f62014f892a64e39b4fb6aed202f32eb
2020-02-27 15:27:29 -08:00
Brad Jorsch
c910b9b43a maintenance/populateChangeTagDef.php: Handle missing valid_tags table
The valid_tags table was added in MW 1.15 and removed in 1.33. If
someone is trying to upgrade from a really old version of MediaWiki,
valid_tags may not exist even though change_tags.ct_tag does.

Bug: T230317
Change-Id: Ib94542878b8d301c1d7f806405ee39838ebc6d4a
2019-08-14 11:57:12 -04:00
Amir Sarabadani
b6c2caf11d Set default of sleep time in populateChangeTagDef to zero
The script already has waitForReplication(), that's good for non-WMF setups

Bug: T206568
Change-Id: I020a4472796eeff2561da6c17a817091d4e9af5a
2018-12-15 17:44:14 +00:00
Amir Sarabadani
02a930d7fb Drop $wgChangeTagsSchemaMigrationStage
Bug: T194163
Change-Id: Ieb6cc60cacf9dd0d86641b1be817249cdce42112
2018-11-28 23:03:41 +01:00
Amir Sarabadani
8ebb1c166b Add part to update ctd_user_defined in populateChangeTagDef
Change-Id: I8fa3fa95b259ed82e78f4c3de0f5e148c3586407
2018-09-11 11:19:57 +02:00
Amir Sarabadani
da9d5c2188 Schema change for reading ct_tag_id instead of ct_tag
Adding unique index on ct_tag_id and making indexes on ct_tag non unique

Bug: T193874
Change-Id: I24609c57e47308d1330a97527f4ea374d0d307ba
2018-09-04 19:29:48 +02:00
Amir Sarabadani
3ea30167fb Add option to populateChangeTagDef not to update the count
I need this when I'm picking this up to continue populating

Change-Id: I52c74d3c1c59ee966027d5d9cb1a2bd3cf6dfc7a
2018-08-15 14:15:51 +00:00
Amir Sarabadani
501d31060e Append new line character to output of populateChangeTagDef.php
Right now, I run it in prod and it's basically useless

Change-Id: Ieb11884c3e9243df3058118cf2d581e715892595
2018-07-05 17:11:29 +02:00
Amir Sarabadani
4493944510 Add some output for progress in populateChangeTagDef.php
I ran it on beta cluster and all was done without one single line of output

Bug: T193871
Change-Id: I05a7c7827203eb159b5845a874b94d74f5d5e299
2018-06-25 17:38:58 +02:00
Amir Sarabadani
cfa0717d4a Move lbFactory defintion from construct to execute in populateChangeTagDef
It seems the class doesn't load needed classes in construct so we get
Uncaught Error: Class 'MediaWiki\MediaWikiServices' not found

Bug: T193871
Change-Id: I0d6a49232cbc256a34ab49e8a4e41f6cc942fe4b
2018-06-18 18:34:48 +02:00
Amir Sarabadani
f1e450564f Add maintenance to populate change_tag_def table and ct_tag_id field
Bug: T193871
Change-Id: I5e863ffcfad5f2b66fb8d50666494acae3480d1a
2018-06-15 17:57:27 +02:00