Commit graph

79 commits

Author SHA1 Message Date
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
Umherirrender
94792e97be maintenance: Cleanup use of exit in Maintenance::execute implementation
Returning void from execute() is success.
Returning true is success, false is failure with exit(1)
Using fatalError also using exit(1)

Change-Id: I1d40430ad6226e4aab8f0810b03ee1213282d123
2021-08-30 19:48:27 +00:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
Aaron Schulz
99d5d2e8cc rdbms: cleanup getServer() and connection parameter fields in Database
Make getServer() always return a string, as documented, even with new
Database::NEW_UNCONNECTED handles that have yet to call open(). If the
'host' parameter to __construct() is ''/null, getServer() now returns
'localhost' instead of null. This avoids problems like fatal errors in
calls to TransactionProfiler::recordConnection().

Use Database constants for "connectionParams" field keys for better
static analysis.

Also:
* Add Database::getServerName() method that returns "readable" server
  names in the style of LoadBalancer::getServerName(). Note that the
  "hostName" field is already passed in from LoadBalancer.
* Migrate most getServer() callers to getServerName() for easier
  debugging and more readable logging.
* Also, normalize Database/LoadBalancer SPI logging context to use
  "db_server" and reduce logging code duplication in LoadBalancer.

Bug: T277056
Change-Id: I00ed4049ebb45edab1ea07561c47e226a423ea3b
2021-05-05 19:44:02 +00: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
Reedy
66b3088064 maintenance: Remove --slave option from sql.php
The --replicadb option was added in MW 1.28 with c0a9ab0f6d.

Change-Id: Ie44116a640af51da90261bc68997e40a662345f3
2020-06-11 01:26:20 +00: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
Reedy
8ba1c75559 Replace wfWaitForSlaves() with LBFactory::waitForReplication()
Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
2020-05-02 02:00:01 +00:00
Tim Starling
3c59969f9e Revert "maintenance: Remove sql.php temporarily"
I confirmed that the LoadExtensionSchemaUpdates hook no longer runs
after the parent patch to fix T249584 is merged, in either sql.php or
patchSql.php.

Note that sql.php is not just a "debugging script", it's intended for
use in production, and was used in production, hence T249565.

Bug: T249565
Bug: T157651
Change-Id: Ia4d99e00e6455eec9cf0fa486ec5e4b83c9cf25d
2020-04-09 00:46:49 +00:00
Timo Tijhof
b5f95da54b maintenance: Remove sql.php temporarily
It's dangerously broken.

This is supposed to be a read-only ad-hoc debugging script but in actually
triggers 'LoadExtensionSchemaUpdates', which is effectively update.php, but
without any of the safe guards, and at a time where you least expect write
queries to happen, let alone administrative queries that drop tables and
run other schema migrations.

Bug: T157651
Change-Id: I8d18a7f5b1731333aa40a9d04dafdb7176cf1d52
2020-04-07 00:04:37 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Umherirrender
3b767e498b Add string cast when outputting exceptions in sql.php
Change-Id: Ibf21869a2525a8c55f53ec79727c818888344e99
2019-09-01 20:43:18 +02:00
Aaron Schulz
2f8e07cfcb maintenance: Sanity check that --replicadb isn't using the master in sql.php
Change-Id: I0b7fd896c88b06cbc17b31b1ae2b9cb8e375da1b
2019-08-24 19:50:36 +00:00
Aaron Schulz
4a55e578ff Convert maintenance scripts to LoadBalancer::getMaintenanceConnectionRef()
Change-Id: I8944a052f51a1941ad3b76a40fc9c46d1363c426
2019-08-02 22:29:43 +00:00
Umherirrender
fa607f56b2 Type hint against IResultWrapper in maintenance classes
Change-Id: I6a58e9cfe645056a854c80b2db1e71fb59bd226b
2019-06-19 21:42:32 +02:00
Gergő Tisza
200f0ad20f
Make sql.php exit status more informative
Add a --status option which sets nonzero exit status for a query
returning or updating no rows. This is useful for shell scripts which
want to do simple existence checks (e.g. 'unless' conditions in Puppet)
or need to do a single-row change.

Change-Id: I3988c4fb24251dd8b33ac85aed9d0ae03eb0f910
2018-12-16 21:55:04 -08:00
Gergő Tisza
3f43c57024
Fix sql.php --json behavior
* return empty array when the query had no result (instead of
  falling back into non-JSON mode)
* return JSON for write queries as well
* retain legacy behavior in non-JSON mode for empty SELECTs, just in
  case somebody relied on it

Change-Id: Iaefbb443650a395278d1cc9ab6aa668b13b217c9
2018-12-16 21:09:17 -08:00
Umherirrender
554f9c857c Replace wfGetLBFactory
@deprecated since 1.27

Change-Id: I11a7253cebe525948a55cebee183e6de128fdc39
2018-02-27 20:02:48 +00:00
Chad Horohoe
d8c29fee35 sql.php: Provide --json output mode
stdObject is a pretty useless format unless you're working with PHP

Change-Id: I7549347a630768223fba5b282a930361dfe6f2d3
2018-02-16 13:22:31 -08: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
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01: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
Aaron Schulz
dd359741cc Move DB errors to Rdbms namespace
Change-Id: I463bd86123501abc68fdb78b4cda6110f7af2549
2017-04-15 10:47:41 -07:00
Aaron Schulz
21e71e0235 Use IDatabase type hints in /maintenance
Relatedly, move lockTables()/unlockTables() to IMaintainableDatabase

Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9
2017-04-07 23:37:41 +00:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
James D. Forrester
242df680ce maintenance: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

This includes renaming fixBug20757.php to fixT22757.php for similar consistency.

Change-Id: If81a590d658fbd82c20c54ac47dfdc8856745ca3
2017-02-21 18:32:44 -08:00
Aaron Schulz
c71fde92ad Fix Database IDEA warnings about callable parameters
Change-Id: Ia9ccc86bb9cbd78b5890ceaedce8cca8d6bb7fe4
2016-10-03 10:48:58 -07:00
Aaron Schulz
3a839c5927 Inject schema vars into DatabaseMysql
Also fix broken patchSql.php maintenance script

Change-Id: I45bccb0e2e10bd06651a551fa08ed0c66d11eb6a
2016-09-22 21:07:27 +00:00
Aaron Schulz
d7785d82f1 Fix undefined getDelimiter() call in sql.php
* Fixes regression from 4ef4438739.
* Also fixed numerous IDEA warnings.

Change-Id: Id41faff835ca25399ce1ceb10a19d19ffc914689
2016-09-19 22:30:06 +00:00
Aaron Schulz
3d5016569d More replication var cleanups in /maintenance
* Fix option check in sql.php
* Rename RecompressTracked vars and avoid deprecated
  method calls

Change-Id: Ie04f6e841d68d69c9243a185de1bd13a612b2070
2016-09-05 23:00:43 -07: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
Aaron Schulz
c0a9ab0f6d Change "slave" => "replica DB" in /maintenance
Change-Id: Ibd3d617901130378a935402326cd4eefbb382c9e
2016-09-06 00:13:08 +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
Timo Tijhof
fc34ed8df7 maintenance: Add --query option in sql.php
This makes it easier to run a query in a scripted fashion,
e.g. with Wikimedia's foreachwiki.

Change-Id: I5562be2fb0871817ee55f1395b686537069f78dc
2015-07-18 20:53:25 +00:00
Brad Jorsch
f9b579efc6 Fix sql.php behavior on error
When an erroneous query is entered into sql.php, it doesn't clear its
line buffer, so the intended next query (often fixing a typo in the
original) winds up concatenated onto the erroneous query. Usually
leading to another error, which repeats the process.

The solution is simple enough: clear the line buffer unconditionally,
not only when no exception is caught.

Change-Id: Ia78e2df8b9c6698c0a225bfb3135274ed8da5303
2015-07-10 17:55:44 +00:00
Marius Hoch
a89338ff82 Improve documentation of maintenance/sql.php
I found this to be lacking earlier this week...

Change-Id: I409c7451baa71b88cf554af0d82d1bf5904a2c4c
2015-05-20 21:24:33 +02:00
Aaron Schulz
f4f5f41194 Allow the empty string as the wiki DB
* This is useful when cluster= is set but the DB is not there yet

Change-Id: I1766c564448502c7359c7da964f0becd2e3222c6
2014-11-06 23:40:24 +00:00
Bartosz Dziewoński
9e5443abc3 No space within the ?: operator
This style is a lot more common in our code.

Change-Id: I7f2fb3716c24c4a95a4c6c4a732b0226c315f242
2014-08-25 17:40:51 +02:00
umherirrender
25971af694 Cleanup some docs (maintenance)
- Fixed spacing inside docs
- Makes beginning of @param/@return in capital

Change-Id: I864b8b3f1f67e34e369aba7aadaf87e7752c894d
2014-08-09 22:08:40 +02:00
Siebrand Mazeland
606c680b21 Update formatting in maintenance/ (4/4)
Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca
2014-04-23 20:09:26 +02:00
Siebrand Mazeland
a50a5d9da7 Pass phpcs-strict on maintenance/ (1/8)
Change-Id: Ib68a7cf4251e8f4c71233df869673f4c5d3cf84c
2014-04-22 21:25:22 +00:00
umherirrender
e78776373e Fixed some @params documentation (maintenance)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I727deec35a712de0f0c676cc87dfa661f1ee965b
2014-04-17 22:48:32 +02:00
Aaron Schulz
dd3a475346 Added --wikidb param to sql.php
* This is useful for updating DBs that are not actually a that of a wiki.
  For example a global blocking or central auth DB may not correspond to
  any single wiki. Trying to use --wiki will fail with het deploy

Change-Id: I232182b79c9ca6421789f19771ba427498fff713
2013-12-10 15:03:41 -08:00
Aaron Schulz
d2254ba11c Allow server selection when running sql.php
Change-Id: I2a643eb3a517eba09b80da19158e0957441bcaa5
2013-05-22 23:08:35 -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