Commit graph

50 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
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Ferran Tufan
cd99df60ed Maintenance scripts: replace most globals with Config
Bug: T72673
Change-Id: Idc46e88756b1aa20f5dccbe7ab3e661b2b102964
2022-07-12 21:13:19 +02:00
Aaron Schulz
aef08cec9f maintenance: Add support to mctest.php for SqlBagOStuff with LB
Change-Id: Iead976145b54cda9e2424ec60b15aa595e587312
2022-04-23 20:16:50 +00:00
Aaron Schulz
cc1bb73490 objectcache: remove "multiPrimaryMode" DB type assertion
Since no mysql-specific queries are required, allow sqlite and
Postgres setups to use "multiPrimaryMode" for easier testing.

Avoid "CASE types text and integer cannot be matched" Postgres
error by making dbEncodeSerialValue() cast the result to a string
so that addQuotes() applies in buildUpsertSetForOverwrite().

Bug: T212129
Change-Id: Ic84a804c272a7070779c8d41d3a33003852d0839
2022-04-21 16:20:39 -07:00
Umherirrender
a9aa1e7346 Fix type of value directly passed to php internal functions
Found by phan strict checks

Change-Id: Icc44cd143f2e98fa3ca188e625a3289441de0f73
2022-03-07 20:41:55 +01:00
Aaron Schulz
bc79ce7fb7 objectcache: deprecate BagOStuff incr() and decr() methods
All callers in Wikimedia gerrit repos have since been migrated to
incrWithInit(), which is usually what is desired and is easier to
implement in various backends. Newer memcached versions of the
memcached protocol even support auto-initializing increments
(including an initial TTL) via the 'ma' command. The incr()/decr()
methods currently bloat the interface and subclasses (often with
slow and buggy implementations). These methods are also hard to
implement in a multi-DC store (either extremely slow or racey)
even though callers might assume they handle high concurrency.

Also, force each MediumSpecificBagOStuff subclass to implement
incrWithInit() instead of having some rely on the base method

In mcc.php, add incrWithInit() and simplify parameters, making
it possible to test non-memcached backends.

Change-Id: I53c9c2c839a1e71d5c104913fea0680c30d11108
2022-02-18 11:15:27 +11:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Aaron Schulz
1afbb016bd Prime connections and update description of McTest script
Change-Id: I4a53b5e4c02a9e2d1163ab9458dd309f651345bc
2019-08-17 20:49:52 +00:00
Aaron Schulz
efba2a4afc objectcache: optimize MemcachedPeclBagOStuff::*Multi() write methods
Make use of Memcached::OPT_NO_BLOCK and Memcached::OPT_BUFFER_WRITES
at selective points to avoid slow internal blocking for loops in the
PECL extension methods. As this mode makes the return values less
meaningful, this is only triggered only if WRITE_BACKGROUND is
provided (it only catches some glaring format or size errors that the
client runs into).

Leave changeTTLMulti() to the default as the above approach would not
make it faster, since the diver does not buffer for that command.

Expand mctest.php to include *Multi() methods and also break down the
single key method timings by method.

Change-Id: I11fc58e1a2296778b2526a0b2f3103fef1baba0c
2019-07-15 19:45:37 -07:00
Aaron Schulz
3a3d117f26 objectcache: use OPT_TCP_NODELAY for MemcachedPeclBagOStuff
Clean up the option setting code in __construct() as well
and make it more strict in terms of checking bogus options

Make mctest.php recognize when memcached is used more easily

Change-Id: I77be506e80478ddbb4fcfa44d82aba8162fa984f
2019-07-10 21:58:02 +00:00
Thiemo Kreuz
06c1a5976c maintenance: Deprecate Maintenance::hasArg/getArg with no param
Benefit of keeping the parameter optional:
- In maintenance scripts that really only have one parameter, it's a
  little more convenient to be able to ask for *the* parameter via an
  empty getArg().

Disadvantages:
- It's unclear what getArg() means when there is no indication *which*
  argument the code asks for. This might as well return the last
  argument, or an array of all arguments.
- In scripts with two or more arguments, it's confusing to see
  getArg( 1 ) next to an empty getArg().
- The methods are more complex and a bit more complicated to use with
  the extra feature of this parameter being optional. Users need to
  look up what the default is to be able to use it safely.

Change-Id: I22a43bfdfc0f0c9ffdb468c13aba73b888d1f15e
2019-03-29 14:37:46 +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
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
addshore
77adf7534b Remove used of deprecated MemCachedClientforWiki
Change-Id: Ib947c0cc1cfc3b365617d12f7564c199d6189c31
2016-04-03 11:52:50 +03: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
Kevin Israel
7c08af2165 Remove some PHP4 microtime() compat wrappers
Trivially replaced with microtime( true ).

The following classes still use microtime() without the
argument, though I have chosen not to change them in this
commit because of a possible loss of precision:

* MWCryptHKDF
* UIDGenerator
* UpdateSpecialPages
* UploadStash

Change-Id: I4f594f6ada9e8fce3319b61844b9857d87e9aa99
2014-07-16 23:39:48 -04:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
umherirrender
783fe84d00 Let maintenance class start with a upper case letter
the case of a class is not a argument for php, but upper case letters
are recommend.

Change-Id: Ibc9169b238ee3f73021e8f73188c3e5b5f1d36a3
2013-11-23 22:53:29 +01:00
Aaron Schulz
50836d0907 Fixed check of BagOStuff set() return value in mctest
Change-Id: I6e69cdc24b9b40132641205cb40f64bb5db45f70
2013-09-18 18:23:59 +00:00
Antoine Musso
480f2d0581 mctest.php: nicely align server names
The servers entries being made of an IP address and a port, they would
often have different lenghts which clutter the output indentation.

Previously the output columns would be slightly misaligned:

$ mwscript mctest.php --wiki=enwiki
10.4.1.255:11211 set: 100   time: 0.17192602157593
10.4.1.1:11211 set: 100   time: 0.19056081771851
$

With this patch:

$ mwscript mctest.php --wiki=enwiki
10.4.1.255:11211 set: 100   time: 0.17192602157593
10.4.1.1:11211   set: 100   time: 0.19056081771851
$

Change-Id: I80199a229ed6310686411f08e0344c7d906414ea
2013-08-01 11:09:33 +02: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
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
cef7179057 Added a --cache option to mctest.php and mcc.php.
* This lets the server list used be that of different object caches.

Change-Id: I88039370affec6e431c931337d220f7472f6eaeb
2013-03-14 23:09:24 -07:00
Reedy
d7dbdd7335 Fix mctest to work with new WMF memcached setup
Change-Id: I0b366284e9c92365d4c8b8458f59d6cc25c998ed
2013-01-16 23:54:07 +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
Tim Starling
8685e3adec In mctest.php, use the configured timeout instead of the default
Change-Id: Ia003c7f96cd0de91db57ec83036493e4bb995ee7
2012-04-27 14:51:52 +10:00
Sam Reed
abf0a5ceb2 Add braces
Cache result of variable calls

Minor RELEASE-NOTES-1.19 updates
2012-01-22 00:58:47 +00:00
Ben Hartshorne
1cb65c5b10 changed help text to indicate an optional port if nonstandard 2011-09-06 23:21:39 +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
Mark A. Hershberger
617a5b1e15 Whitespace fixup under tha maint directory. 2010-12-04 03:20:14 +00:00
Sam Reed
659778619c Stylize maintenance folder.. 2010-05-22 16:50:39 +00:00
Niklas Laxström
a203a369b3 Fix messed output 2010-05-17 08:20:48 +00:00
Brion Vibber
5f77720601 Fix regression: server parameter needs to be optional; most of the time we *do not* want to use one since it's going to test all defined servers 2009-09-30 21:24:47 +00:00
Chad Horohoe
25e604f1c0 Redo addArgs() as addArg() so we can actually do useful things with arguments like descriptions and proper requirement checks, similar to addOption() 2009-08-18 23:06:24 +00:00
Chad Horohoe
567f244e36 Revert r54244 which was stupid and fix this properly. Require commandLine.inc/Maintenance.php using the full path every time. 2009-08-03 21:56:41 +00:00
Chad Horohoe
a1c51e18af Merge maintenance-work branch (now with less errors!):
* Docs have been updated to indicate the standard on how to write maintenance scripts (MW.org docs will follow) Have ported vast majority of maintenance scripts to new format. Remaining ones (mostly FiveUpgrade-related) are a bit more tricky. commandLine.inc is untouched for now. Many have gotten code-style updates as well. Deleted .inc files were only used by their .php counterparts, and have been merged into single files.
* (bug 11867) Lock error on redirect table when running orphans.php
* (bug 16322) Allow maintenance scripts to accept DB user/pass over input or params
* (bug 18566) Maintenance script to un/protect pages
* initStats overhaul, now uses class SiteStatsInit. Also fixes bug 18930
2009-08-02 19:35:17 +00:00
Chad Horohoe
0248beaea9 Remove stupid id that makes clean merges impossible and doesn't help anyone 2009-07-25 22:11:58 +00:00
Brion Vibber
1c9773bd01 Revert r52336 "Merge maintenance-work branch:"
Seems to have broken a bunch of stuff. Don't commit giant non-critical changes that break Setup.php and all maint scripts. Thanks!
2009-06-24 02:49:24 +00:00
Chad Horohoe
59b60fc311 Merge maintenance-work branch:
* (bug 16322) Allow maint scripts to accept DB user/pass over input or params if no AdminSettings.php
* (bug 18768) Remove AdminSettings.php from MediaWiki core
* (bug 19157) createAndPromote error on bad password
* (bug 14201) Create AdminSettings.php during wiki installation, in the same way as LocalSettings.php
* Introduce new Maintenance class framework and port a good number of scripts over; the ones that are left are a little more complicated. Read the docs.
* Not deleting "unused" files yet, don't want to break everything at once :)
2009-06-24 02:02:37 +00:00
Greg Sabino Mullane
35abc46185 Minor grammar fixes, etc. 2008-07-21 17:06:35 +00:00
Antoine Musso
15eb06032a Fix 12384 : comment on maintenance/*php files 2008-07-19 12:15:07 +00:00
Alexandre Emsenhuber
087a9f70c5 WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>

Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage

One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
Aryeh Gregor
a15c419b3d Remove ?>'s from files. They're pointless, and just asking for people to mess with the files and add trailing whitespace. (Yes, I looked over every one and reverted those that were bogus. Slash-enter a million times in less worked well enough, although it was a bit mind-numbing.) 2007-06-29 01:19:14 +00:00
Brion Vibber
d88bf87284 Apply most of the code tweaks from the live site:
* use configured cache servers for mctest.php
* bucket details in mcc.php
* fix input validation and remove debugging code in compressOld
* full ID range for moveToExternal
* fix resolveStubs.php for compatibility with older serialized data
* maximum line length for bar graphs in getLagTimes.php
* recognize specieswiki in rebuildInterwiki.inc
* --purge option to do additional parser-cache purging for purgeList.php
* default changed in MiniDonation extension
* profile unicode cleanup in Xml
* log slow parses in Article.php
* profile wfMsgReal
* log mkdir failures
* profile AutoLoader
* rebuild empty DjVu metadata containing ''
* security fix for DjVu metadata retrieval
2007-01-17 00:54:54 +00:00
Brion Vibber
bf63ffaa2c Committed a bunch of live hacks from Wikimedia servers
A few left, but these don't look too evil
2006-10-02 17:04:13 +00:00
Tim Starling
f2b988ed33 Was never committed to HEAD for some reason 2006-01-28 08:22:24 +00:00