Commit graph

17 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
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
Timo Tijhof
09a6e51499 interwiki: Overall clean up and simplification
* Remove inline `false` fallback in fetch().
  load() does this already and can't return other falsey values
  like null.

* Remove use of Database::getCacheSetOptions as this data is
  generally not mutable.

* Remove foreach-wiki logic from clearInterwikiCache.php.
  Usually to make scripts apply cross-wiki they are iterated
  externally via something like foreachwiki (as WMF does) and
  by using the `--wiki` parameter that core supports. Iterating
  in-process is somewhat fragile and depended on various hardcoding
  and assumptions, including e.g. BagOStuff::makeKey() and how
  ClassicInterwikiLookup calls this.

  Also fix clearInterwikiCache.php to actually work on simple wikis.
  Previously it did nothing locally as $wgLocalDatabases is empty.

* Remove non-confident code from loadFromArray() for tolerating
  absence of iw_url. Move the isset() check to the one place that
  needs it, namely the hook handler in load(), and document what it
  is for.

* Simplify load() usage by inlining and moving fetchPregenerated()
  responsibility there.

* Simplify load() by merging the aborted and non-aborted hook cases,
  and document the reasons explicitly.

* Move use of WikiMap::getCurrentWikiId() to the constructor
  with TODO for proper injection.

* Rename a bunch of variables and apply more consistent terminology
  within interwiki-related source code. In particular, it was
  confusing that the variable 'objectCache' in fact did not cache
  the objects, which are cached in 'localCache' instead. Use the
  common naming found in other MW components instead ("wanCache" and
  "instances").

Bug: T315315
Change-Id: If3429b0604974efd4ff5914660979d3e49266848
2022-09-29 19:46:35 +00:00
Derick Alangi
9a12b88c44 maintenance: Use SelectQueryBuilder to construct queries
Part 1 of migrating files in `maintenance/` from IDatabase::select()
to SelectQueryBuilder.

Change-Id: Idfe83b900de3fbc6a251a5a78d8af1a4cd88970f
2022-07-19 19:11:24 +01:00
Ferran Tufan
cd99df60ed Maintenance scripts: replace most globals with Config
Bug: T72673
Change-Id: Idc46e88756b1aa20f5dccbe7ab3e661b2b102964
2022-07-12 21:13:19 +02:00
mainframe98
387a3ac44c Remove usages of $wgMemc
Usages in Installer.php were not removed as the installer is
resetting $wgMemc to an EmptyBagOStuff instance. Removing it
would risk breaking the installer for extensions still using
$wgMemc.

Bug: T160813
Change-Id: I46b837c92cf86474989ee6dd97f1251cf795309f
2020-01-20 19:41:32 +01:00
Aaron Schulz
12531d2ae6 Replace wfWiki() usage with WikiMap in some additional places
Change-Id: Ide4518292bd9392d09f701b2c301673687d19f3b
2019-07-04 21:58:42 +00:00
daniel
218e8311d5 Pass '' instead of false for the $conds parameter in select calls.
Per documentation on IDatabase, $conds must be a string or an array.
Passing false for conds is confusing, since it's unclear whether this
should match everything or nothing.

Bug: T188314
Change-Id: I8be1ac4cbdaafc41aadc2a658be8a99b754b0268
2018-03-02 02:32:54 +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
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
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
Waldir Pimenta
158bf7cb55 normalize filenames of maintenance scripts
Use lowerCamelCase.php format for all files (per [[mw:CC#File_naming]]),
and make filenames more specific:
- clear_stats.php -> clearCacheStats.php
- clear_interwiki_cache.php -> clearInterwikiCache.php
- initStats.php -> initSiteStats.php
- proxy_check.php -> proxyCheck.php
- stats.php -> showCacheStats.php
- showStats.php -> showSiteStats.php

Also changed the class names accordingly (per [[mw:CC/PHP#Naming]]),
and make class names more specific:
- clear_stats -> ClearCacheStats
- InitStats -> InitSiteStats
- CacheStats -> ShowCacheStats
- ShowStats -> ShowSiteStats

Updated files that made references to the changed files/classes:
- DefaultSettings.php and SpecialBlockme.php (proxy_check.php -> proxyCheck.php)
- maintenance/showSiteStats.php (initStats.php -> initSiteStats.php)
- maintenance/README and docs/memcached.txt (stats.php -> showCacheStats.php)
- docs/maintenance.txt and docs/memcached.txt (clear_stats.php -> clearCacheStats.php)

Thanks Hashar for the initial help and encouragement :)

Change-Id: I60f76fc971e06e1b710dcda35f9c2d931b93bdd7
2013-03-06 03:57:54 +00:00
Renamed from maintenance/clear_interwiki_cache.php (Browse further)