Commit graph

59 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
Bartosz Dziewoński
4108bbe1af Maintenance: Print errors from StatusValue objects in a consistent way
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.

Thoughts on the previously commonly used methods:

- $status->getMessage( false, false, 'en' )->text()
  Almost the same as the new output, but it allows on-wiki message
  overrides, and if there is more than one error, it prefixes each
  line with a '*' (like a wikitext list).

- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
  As above, but these forms do not expand parser functions
  such as {{GENDER:}}.

- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
  These forms output the message keys instead of the message text,
  which is not very human-readable.

The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.

Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
2024-06-12 00:07:02 +02: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
abador
cf87040da3
CleanupUploadStash: change fatalError to output and continue temp file cleanup if temp directory isn't located in local-temp
Bug: T283479
Change-Id: I64d4c7a938cb0944604289a3c101481ecf2c2137
2024-01-02 19:55:36 -08:00
abador
47f3071564
CleanupUploadStash: return exit code 0 when local temp repo is not present
Return return exit code 0 instead 1 when local temp repo is not present

Bug: T283479
Change-Id: I7a0791d9bfb19607999aaebfb7d5c2a94b20c8ca
2024-01-02 19:54:56 -08: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
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Tim Starling
580ec48e5b Fix more PHPStorm inspections (#2)
* Illegal string offset and invalid argument supplied to foreach, due to incorrect type information
* Array internal pointer reset is unnecessary
* $hookData unused since MW 1.35 due to incomplete revert
* array_push() with single element
* Unnecessary sprintf()
* for loop can be replaced with str_repeat()
* preg_replace() can be replaced with rtrim()
* array_values() call is redundant
* Unnecessary cast to string
* Unnecessary ternary. Often the result relies on short-circuit evaluation, but I find it more readable nonetheless.

Change-Id: I4c45bdb59b51b243fa96286bec8b58deb097d707
2023-03-25 00:19:58 +00:00
Amir Sarabadani
b525884e11 maintenance: Use $this->waitForReplication()
This adds reconfiguring db pools in case a replica gets depooled

Bug: T298485
Change-Id: Id052ce8ed45c51e51b071778858d27b48605bf93
2022-10-24 21:11:53 +02: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
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Reedy
c7eb28aac9 Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
2020-05-21 01:06:05 +00:00
Reedy
8ba1c75559 Replace wfWaitForSlaves() with LBFactory::waitForReplication()
Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
2020-05-02 02:00:01 +00:00
jenkins-bot
557bf7a762 Merge "Use Status::wrap instead of suppress PhanUndeclaredMethod" 2020-02-19 15:26:00 +00:00
Umherirrender
ed23e08a51 Use Status::wrap instead of suppress PhanUndeclaredMethod
Change-Id: I93d9c2be538ebec4865d4e1857a6111c79e35f96
2020-02-18 22:37:36 +01:00
Derick A
e7493e35bd maintenance: Avoid deprecated usage of RepoGroup::singleton()
Change-Id: I694cf124a5f90f368309b04f8ae0b843a98816eb
2020-02-18 21:28:17 +00:00
Umherirrender
167f991e31 Handle null from FileBackend::getFileList
Avoid warning with null passed to foreach

Change-Id: Id61ab8ba1952cdabd7c3f9c78a06a52553aadabe
2019-12-04 20:55:42 +01:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Kunal Mehta
a2c166cb51 Have class match filename in some maintenance scripts
Each of these scripts had a class name that was not referenced outside
of the script file itself, and are safe to rename as a result.

Change-Id: Id605aca11db51ee433baeaa998a0e33184c930ca
2018-05-23 19:36:51 -07: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
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
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
Bartosz Dziewoński
44947af94a Revert "Clean up user handling in UploadStash"
This reverts commit 58713d2b16.

Bug: T145228
Change-Id: Ic62f19109f98fab9dd029acccecd6518b649e34b
2016-09-10 15:27:49 +00:00
Chad Horohoe
58713d2b16 Clean up user handling in UploadStash
- User parameter is now *required*, remove $wgUser fallback
- We don't actually need the object after construction, don't store it

Change-Id: Id0cc859b70e5d0608ffbfa591bce6a1feb7cc3be
2016-09-02 17:40:49 +00:00
Reedy
1834ee3d8e Fix numerous class/function casing
Change-Id: I23982bfa0548c9ea3bdb432be7982f1563930715
2016-03-18 23:14:49 +00: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
3ca6f36c90 Use wfWaitForSlaves in upload stash cleanup script
Bug: T95382
Change-Id: I8d93eb15064693634076e864ed6724392448cb45
2015-04-08 16:24:29 +00:00
Aaron Schulz
36693f7dee Made cleanupUploadStash use batching for the last two loops
Change-Id: If3cfd333636f5b14c529629ce1ec408d396122a8
2013-11-13 18:06:10 +00:00
Aaron Schulz
9c862487f4 Removed sanity regex since there are too many random formats to track
Change-Id: I9da57ac5b59372324fbe0c627f012c638c88fca0
2013-11-12 20:08:17 +00:00
Aaron Schulz
c674d4c90c Speed up thumbnail purging a bit for stash script
Change-Id: Ie0f3d5aa505a5c1554d7932d38ba376811590df1
2013-11-07 16:28:09 -08:00
Aaron Schulz
2d083797db Catch temp container thumbnails in cleanup script
Change-Id: Iba2badac3abf08e5c4a409ccf10d831e0e9b341e
2013-11-06 12:47:49 -08:00
Aaron Schulz
de1d3b611d Catch all stash errors in cleanup script
bug: 56401
Change-Id: I3dcd8728a46fdcbecbda0bdc6e3aef49e8f41ed8
2013-11-04 09:40:56 -08:00
Aaron Schulz
34a89aa10f Avoid extra HEADs for stash clearing
Change-Id: I96e78b219fe12b43daf4a313eb297b98577ef955
2013-10-03 09:12:25 -07: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
umherirrender
bfb75bc8e2 Fixed spacing around parenthesis in languages/tests/maintenance
Change-Id: Idd4299d17f1fcf98ab1d635484cb4e880f35ee24
2013-04-28 15:57:34 +00:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
Aaron Schulz
b3a0ac5e93 Made upload stash cleanup script scan the temp dir for old files.
Change-Id: I490d66770182b91b23db62728f78cb117d28e1a2
2013-01-17 12:04:38 -08:00
Reedy
cdbe6fee1f When deleting old thumbnails, actually increment $i
Change-Id: Ic213fed61959ab4d25bcd891c81df20e39cbc5f5
2012-10-21 15:15:22 +01:00
Reedy
25a103f9f5 Catch and deal with UploadStashZeroLengthFileException when removing stashed files
Seen on the cluster and it halts script execution

reedy@fenari:/home/wikipedia/common$ mwscript cleanupUploadStash.php commonswiki
Getting list of files to clean up...
Removing 52958 file(s)...
File is zero length
Backtrace:

Change-Id: I740111ca20473c495a4a51edafa156169fe6dd4d
2012-09-27 19:08:47 +01:00
Aaron
17f27fef91 Made stash cleaning script also remove the old thumbnails.
Change-Id: I3dd5cc927bbbfb0f06eac9170107b17fabe39168
2012-09-25 14:49:36 -07: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
f7c4c52ba0 Improve documentation of maintenance scripts.
Change-Id: I1c911eb0fd6108fdee0b4e96363d87b926aba396
2012-06-25 21:54:41 +02:00
Reedy
7c5a5aee0e Added some more output to cleanupUploadStash.php
Change-Id: I8acf22df78a97c6e4003e7e5ed89800f1be41c6a
2012-05-09 03:38:21 +01:00
Sam Reed
ad5f0ca6e5 Appending a newline at the end of the message results in a much nicer console display 2012-03-05 21:14:10 +00:00
Sam Reed
8c35b38658 Fix stray comma from r109537 2012-01-19 15:22:28 +00:00
Sam Reed
ec4604de3d Documentation and whitespace
Clearing another w/c
2012-01-19 14:56:18 +00:00