Commit graph

235 commits

Author SHA1 Message Date
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Aaron Schulz
633eb437a3 rdbms: clean up return values of IDatabase write methods
Also improved the atomicity and affected row count logic for
insert/replace with sqlite.

Also remove unused "fileHandle" code from insert().

Change-Id: If7b9148fd44f3a958899885753c7c86ba66bf193
2018-10-30 03:34:52 +00:00
Brad Jorsch
993baa3493 ActorMigration: Remove possibility of read-both
When this was originally written, the plan was to read both the old and
new fields during the transition period, while stopping writes to them
midway through. It turns out that the WHERE conditions to do read-both
correctly are generally not handled well by the database and working
around that would require a lot of complicated code (see what's being
removed from ApiQueryUserContribs here, for example).

We can simplify things greatly by instead having it write both fields
during the transition period, reading from the old for the first part
and the new for the second part, as is being done for MCR.

Bug: T204669
Change-Id: I4764c1c7883dc1003cb12729455c8107319f70b1
Depends-On: I845f6ae462f2539ebd35cbb5f2ca8b5714e2c1fb
Depends-On: I88b31b977543fdbdf69f8c1158e77e448df94e11
2018-10-11 12:12:00 +11:00
Aaron Schulz
fe0af6cad5 rdbms: Database::selectDB() update the domain and handle failure better
LoadBalancer uses Database::getDomainId() for deciding which keys to use
in the foreign connection handle arrays. This method should reflect any
changes made to the DB selection.

If the query fails, then do not change domain field. This is the sort of
approach that LoadBalancer is expects in openForeignConnection(). Also,
throw an exception when selectDB() fails.

The db/schema/prefix fields of Database no longer exist in favor of just
using the newer currentDomain field.

Also:
* Add IDatabase::selectDomain() method and made selectDB() wrap it.
* Extract the DB name from sqlite files if not explicitly provided.
* Fix inconsistent open() return values from Database subclasses.
* Make a relationSchemaQualifier() method to handle the concern of
  omitting schema names in queries. The means that getDomainId() can
  still return the right value, rather than confusingly omitt the schema.
* Make RevisionStore::checkDatabaseWikiId() account for the domain schema.
  Unlike d2a4d614fc, this does not incorrectly assume the storage is
  always for the current wiki domain. Also, LBFactorySingle sets the local
  domain so it is defined even in install.php.
* Make RevisionStoreDbTestBase actually set the LoadBalancer local domain.
* Make RevisionTest::testLoadFromTitle() account for the domain schema.

Bug: T193565
Change-Id: I6e51cd54c6da78830b38906b8c46789c79498ab5
2018-10-10 12:03:30 -07:00
Aaron Schulz
41a37d14fa rdbms: make Database::open() protected
This is not called externally and there is little reason for that to
change. The current caller pattern is to use factory(), possibly with
initConnection() afterwards, or to use a LoadBalancer to begin with.

Change-Id: Ib1fdd5c960f1ed877fcd17bcb99b999d5d894716
2018-08-21 18:34:51 -07:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Fomafix
3714131b5d Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
This is a followup to 485f66f1.

Change-Id: I7a2a44b7e933103178929b3cdc015859612c8b35
2018-06-11 19:23:15 +02:00
addshore
f3df984c79 Introduce IDatabase::buildSubstring
Change-Id: I96f3e0c4920d52f63175cb6767c149f20a8a8cde
2018-03-07 12:32:50 +00:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00
Aaron Schulz
ec550d4823 rdbms: remove "m" prefix from Database fields
Done using the PhpStorm refactor->rename tool.

Also move "defaultBigSelects" declaration to DatabaseMysqlBase
as no other classes uses that.

Change-Id: I424a2d9815de3a5d4cca2522f3db23a5efe6b592
2018-02-15 23:29:34 +00:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Aaron Schulz
6237fd11b6 rdbms: make affectedRows() work more consistently
* Update replace()/upsert() to combine the affected row
  count for the non-native case
* Also make replace() atomic in the non-native case,
  similar to how upsert() already works

Change-Id: I6c9bcba54eca6bcf4a93a9b230aaedf7f36aa877
2018-01-30 20:02:07 -08:00
Brad Jorsch
0a9c55bfd3 Deprecate IDatabase::nextSequenceValue()
It's often forgotten because MySQL and Sqlite don't use it, the only
users are PostgreSQL and Oracle. And when used, if inserts to multiple
tables are being done it's easy to get the ordering wrong.

This patch reimplements DatabasePostgres::insertId() in terms of PG's
lastval() function, and adds triggers to the Oracle schema to make it
work the same as the other databases.

Bug: T164900
Change-Id: Ib308190c52673a9266c8495a589ae644f9fbefce
2017-08-31 11:16:26 -04:00
Brad Jorsch
31cb62dd2d DB: Add join conditions to selectField, selectFieldValues, and insertSelect
selectField() and selectFieldValues() are trivial, they just need to
pass it through to select(). In fact, selectFieldValues() was already
doing it, just no one ever updated IDatabase.

insertSelect() is a little more work. nativeInsertSelect() was
originally written as largely a copy-paste of select() and has since
gotten well out of sync. Now that we have selectSQLText(), we should be
able to just use that. DatabasePostgres's implementation can wrap the
parent implementation instead of being another copy-paste, but
DatabaseOracle seems to still need to be special.

Change-Id: I0e6a9e6daa510639d3212641606047a5db96c500
2017-06-14 05:07:42 +00:00
Aaron Schulz
dd359741cc Move DB errors to Rdbms namespace
Change-Id: I463bd86123501abc68fdb78b4cda6110f7af2549
2017-04-15 10:47:41 -07:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
Aaron Schulz
2dc621fd82 Move ORAResult to /db
Change-Id: I9be89faef693343a4071d7c29b6ca0c021e7fb63
2017-02-17 03:07:14 +00:00
Aaron Schulz
019fa7cb9c Move Blob class to Rdbms namespaces
Leave \Blob as an alias. Callers can now use the Rdbms\Blob class
for "extends"/"new" and the Rdbms\IBlob interface for type hints.

Change-Id: I983b76f181ac60c1eb92c350cd27ad77ec90a192
2017-02-13 21:07:00 +00:00
Aaron Schulz
58ecdd060c Fix assortment of IDEA warnings
Change-Id: I3fb482232483f37bf73ebbeb405056794109e618
2017-02-11 18:12:42 -08:00
Brad Jorsch
fb3ae6fbe3 Replace use of &$this
Use of &$this doesn't work in PHP 7.1. For callbacks to methods like
array_map() it's completely unnecessary, while for hooks we still need
to pass a reference and so we need to copy $this into a local variable.

Bug: T153505
Change-Id: I8bbb26e248cd6f213fd0e7460d6d6935a3f9e468
2017-01-31 23:01:54 -05:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Aaron Schulz
aa8d127b73 Avoid use of DatabaseBase in /includes
Change-Id: Ia3b7f9cb7d40f4ec9f19c924904e8a096880ec6a
2016-12-02 12:34:06 -08:00
Aaron Schulz
83b573a3e8 Remove strictIPs(), cascadingDeletes(), and cleanupTriggers()
These DatabaseBase methods have no callers are were a mistake to
begin with. They only encouraged code forking and incompatibilities
among different backing DB types.

Also removed stray realTimestamps() method that was left over
from prior removals.

Change-Id: I37bef8585151e2782d2c88b5ae1e6752109c6ac7
2016-09-19 20:12:11 +00:00
Aaron Schulz
fcf67bde0e Stub out DatabaseBase::getSearchEngine() as a dummy method
SearchEngineFactory::getSearchEngineClass() should be used instead

Change-Id: I984b80815633a8dc38a76d7de8a46ec249ae729f
2016-09-19 08:11:18 -07:00
Aaron Schulz
4ef4438739 Remove long-since unused cruft methods from DatabaseBase
Change-Id: I4b28c15a8589504bdbbe79ba0d3aed1e52dbe65b
2016-09-18 00:20:49 +00:00
Aaron Schulz
403a1ea178 Move all of the reasonable DatabaseBase methods to Database class
The Database class was previously just a short-hand for "Database::",
and such calls should still work. The class now resides in /libs/rdbms.

The subclasses now extend DatabaseBase to avoid breaking type hints
that use that (hints use either IDatabase or DatabaseBase).

Also, use CASCADE with DROP TABLE for MySQL as with other DBs.
Keep SQLite excempt due to lack of support.

Added getDomainID() methods to avoid mentioning the word "wiki".

Change-Id: Ibd05d786cb26c21dcc9cb9601f6b2b52056af9ae
2016-09-17 03:38:05 +00:00
Aaron Schulz
0bbba6e0d4 Move various DB helper classes to /libs/rdbms
Change-Id: I0724f1acce4f6c43b1f0983fa119e628e7c53ba5
2016-09-14 20:40:12 -07:00
Aaron Schulz
272f45a8a0 Change DatabaseBase => IDatabase in /db where possible
Change-Id: Ia0a049cd4294c5a39aa9ed228d4eb5b15736ea1f
2016-09-14 19:31:51 -07:00
Aaron Schulz
4be70af8c6 Replace some MWExceptions with natives ones in /db
Change-Id: I94532d09216926d401e94c61acd60fdc6241a2a0
2016-09-14 01:50:33 -07:00
jenkins-bot
4a975b8099 Merge "add IGNORE INDEX option to mysql database handler" 2016-09-12 12:33:59 +00:00
Ariel T. Glenn
53fc101b22 add IGNORE INDEX option to mysql database handler
BUG: T29112
Change-Id: I9a5a4f7983ebd37b7889abb8433e5acc44b8f9ac
2016-09-12 03:23:49 +03:00
umherirrender
90e9fc296a Added a Database::buildStringCast and use on int/string join
The database specific sql is untested, but sql is taken from docs

mssql - knows about impilict casts -
https://technet.microsoft.com/en-us/library/ms191530(v=sql.105).aspx
mysql - knows about impilict casts
oracle - https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj33562.html
postgresql -
https://www.postgresql.org/docs/9.2/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS
sqlite - http://www.sqlite.org/lang_expr.html

Bug: T69065
Change-Id: I3a83276dc65aae58124460af1810d37dff52e943
2016-09-03 23:59:39 +00:00
Aaron Schulz
52d2ebb30a Make insertSelect() do two separate queries in non-CLI mode
This avoids slave lag and makes query time account easier.
It also avoids table-level autoinc locking and slave drift
with statement-based replication in some setups.

Also refactored the use of $wgCommandLine mode in
DatabaseBase slightly, so that it can be injected.

Change-Id: I2dba6024ecf32c9ee24a3080cce3b02568c1458b
2016-08-31 17:21:30 -07:00
Erik Bernhardson
dd3b9a3343 Fix a few incorrect annotations
Found by applying etsy/phan to the mediawiki codebase, in preparation
for getting it running more regularly via CI. Has no effect on how the
code runs, simply does a better job of documenting the code.

Change-Id: I4c844a51df3ffe4fbb96cac25f3eff2f7a9faca2
2016-06-30 17:50:40 -07:00
Siebrand Mazeland
5b119a0e44 Replace uses of join() by implode()
All of core uses implode() consistently now.

Change-Id: Iba50898c64c43f356d1caf8869f484e90d9ff651
2016-03-08 18:24:16 +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
umherirrender
5311afb6a4 phpcs: Assignment expression not allowed
Fix some "Assignment expression not allowed"

Found by tests:
https://integration.wikimedia.org/ci/job/mediawiki-core-phpcs/2736/consoleFull

Change-Id: Ibfc62b0aaa5c7fa63081edea3ef2b4d0dc984f85
2015-11-18 19:39:19 +01:00
Aaron Schulz
1b67a929ab Start rename of DatabaseBase => Database
This gives static method callers the option
to use methods like Database::factory() instead
of having to use the uglier DatabaseBase::factory().

Change-Id: I61800626b71ad2803a897df060059dbaf8778679
2015-10-04 12:36:56 -07:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Kevin Israel
5a4c5985ae Database: Remove unused errorCount() method
Also removed the protected $mErrorCount property used by this method.

Also removed DatabaseOracle::reportQueryError(). After removing its use
of $mErrorCount and applying relevant changes from 419221e4a7 ("Fixed
bug where catching DB errors left ignoreErrors() on"), the only effect
would be that, like for the other DB types, query errors would be
logged using wfLogDBError().

Change-Id: Ie26a5f5ef7dc5619d9db38d3eb6b7af3e6592aff
2015-09-18 04:35:13 -04:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Aaron Schulz
2cfcb390c6 DatabaseBase constructor cleanups
* The array based format is now required
* Pass any additional parameters through factory() to __construct() even
  if the base clase does not recognize them. This makes DB specific
  options simpler.
* Also added missing bits to Sqlite constructors

Bug: T90288
Change-Id: I29b79a3c1bb2b5e51c1c8f5e04cd08c71e0662a3
2015-02-23 13:02:28 -08:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00
umherirrender
02dc9da399 Cleanup some docs (includes/[a-d])
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I7b65fe04db431342cc58b469dc48f41a50c4e891
2014-07-24 19:42:45 +02:00
withoutaname
176213b898 Fetch string to pass through writeTemporary() in DatabaseOracle.php
Pulled some code from insertOneRow() to fix the update() function
and prevent the error warnings in bugzilla 64970 from showing up.
Note that since insertOneRow() and update() contains a lot of
duplicate code, they may be candidates for merging, but that is
outside the scope of this request.

Bug: 64970
Change-Id: I9ff9077d68e77f05f878fc541f87e0a5ce86ecc2
2014-06-08 02:45:46 -07:00
umherirrender
f5f1e38b9a Fixed some @params documentation (includes/[db|installer])
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: I3595e9aac69ac42fbb74b0783fae0ad9bcc831aa
2014-04-19 13:55:27 +02:00
umherirrender
23fab68274 Fix spacing after @param and friends in comments
Searched for:
\@(param|return|throws|since|deprecated|access|todo|var)[ \t]{2,}

Change-Id: Icce22ba9fe0635455691ca58d9872d618151f346
2014-04-05 20:02:29 +00:00
umherirrender
7c314de876 Rename some local vars to start with a lowercase letter
Change-Id: I6e5975ed7351c1439eda19afaba5120c6afa50f1
2014-03-15 21:03:05 +00:00
Siebrand Mazeland
db7de5f4c1 Fix CodeSniffer and warnings in includes/db
Follow-up with a slightly wider scope to e611604d10.

Change-Id: I9bb5ef0ceef0cd7a9c044e675b953db6d3b35407
2014-03-12 18:29:16 +00:00