Commit graph

31 commits

Author SHA1 Message Date
Timo Tijhof
4ef0891994 rdbms: Consolidate logger channels into one
Notable changes:

* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
  injected. The rest implicitly got a NullLogger due to being absent.
  These are now effectively unsilenced.

* Database::__construct() required almost all parameters, even the
  loggers. I've wanted to move some of DatabaseFactory into the ctor
  here for a while. In order to make this change not a breaking
  change, the new 'logger' parameter is optional with NullLogger as
  default. This allowed some of the test cases, which were simply
  passing NullLogger, to be fixed by passing nothing instead of
  passing the new option name.

  The Database class is behind a dozen layers of indirection for
  real use, so this will still be injected just fine (DBF, LB, LBF,
  MWLBF, etc.).

* In LegacyLogger, the handling for $wgDBerrorLog was previously
  limited to DBConnection and DBQuery. This now includes errors
  from other (generally, newer) parts of Rdbms as well, which were
  previously missing.

  This only affects sites (typically CI and dev setup) where
  $wgDBerrorLog is used, as opposed to the more common
  $wgDebugLogGroups by-channel configuration.

* TransactionProfiler gets its logger injected in a rather odd way,
  via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
  as opposed to service wiring. This is kept as-is for now.

* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
  there are cases that intentionally produce failures of which
  the result is then observed. In CI we assert that dberror.log is
  empty so instead of adding the missing logger fields to that
  LBFactory instance, the only one set (replLogger) is removed.
  The alternative is to set 'logger' now, which would naturally
  cause CI failures due to unexpected entries coming through to
  non-mocked error log.

Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
2023-01-03 22:46:38 +00:00
Derick Alangi
f88eab53a6 tests: Use overrideConfig(Value|Values) where needed
This continues the work in the child patch to replace callers
of setMwGlobals() with the appropriate method. Directory this
patch covers is `tests/phpunit/integration/`.

Change-Id: I0a9abf0d2a43587f2ffa029b68024a1ba5165fc7
2022-07-12 14:40:46 +01:00
Majavah
7e3df796b0 Revert "Remove last User dependencies from File"
This reverts commit 73a25838b4.

Reason for revert: T296508

Bug: T296508
Change-Id: I8af37665eeb284b85157a72459d43261ec4829ed
2021-11-26 17:06:36 +00:00
Petr Pchelko
73a25838b4 Remove last User dependencies from File
Change-Id: I953fcc66b5cde1ef481178b08e16c50b8a118702
2021-11-26 05:42:00 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Umherirrender
bcee220ad1 tests: Avoid non-namespaced aliases for Wikimedia\Rdbms namespace
Change-Id: I49cb151f64c578f41dc1236b2a8906694ca97b93
2021-09-18 20:24:08 +02:00
jenkins-bot
93a1fd20bd Merge "Support ActorStore::newSelectQueryBuilder with query flags" 2021-07-27 21:41:02 +00:00
Petr Pchelko
7e0246a89c Support ActorStore::newSelectQueryBuilder with query flags
Change-Id: Ia731415f627d72811cf7a354721bb0fb28b128eb
2021-07-21 15:32:44 +00:00
Alexander Vorwerk
def29c6d06 ActorStore: avoid throwing in case of invalid usernames
When an username cannot be a valid actor,
ActorStore::newUserIdentityByName() should return null instead of
throwing an Exception.

Bug: T283167
Change-Id: Id04978cf2a417f2354d5e336ed1b0b67462603e9
2021-05-19 20:30:55 +00:00
Petr Pchelko
f870ea5232 ActorStore: Always canonicalize provided user name
We don't actually know where is the given user name coming from
and whether it's been normalized before hitting the storage layer,
so always check if it's a valid user name.

Bug: T273933
Change-Id: Ie9848188c81c95bedff9d18e6398bd3511c459e4
2021-04-29 06:34:03 -07:00
Petr Pchelko
8ef1a98260 Add ActorStore::deleteActor
This is an extremely dangerous method, but it's needed
for the temporary users magic in translate extension.
At least going via ActorStore we can keep our in-process
caches consistent and get rid of some static methods
and caching in user object.

Change-Id: I8157f7ccee7d72aee405e9b6109dfc1838e1f380
2021-04-29 05:13:55 -07:00
Petr Pchelko
f50c097b9a Keep ActorStore caches consistent on user rename
Multi-key in-memory keys for the actors is complicated
enough to have it's own small abstraction.

Change-Id: Id0e091504b71a44ce52d418c5737d64ac70495e9
2021-04-26 14:02:00 -07:00
Petr Pchelko
021206c232 User: use ActorNormalization to insert actor
While creating users, we have several interesting corner cases:

- When creating a new User, we actually rely on the 'unique'
constraint on actor_name. This is important if something calls
'User::createNew' with a name that is already occupied by an
existing anon actor with no user. This is quite a weird corner case,
but there's a test for that. We could probably assimilate this
nicly in actor store by checking whether the user id in the database
for the actor we found is the same as user id in the passed in user identity.
- Even more interesting use-case is 'subsuming' existing actors with
reserved user names. When we call User::newSystemUser, and there is
already an actor with the same reserved name, we 'subsume' that actor
and take over it's actor_id for our new system user. This can now be
done with an upsert. This state of having reserved actor with no user
is not easy to cause, but imports or updating from old MW versions
seem to be able to produce this state. Archeology revealed that
'subsuming' existing actor was added for installer.

Change-Id: I16b2f088217db0283215fc2ef5fb04a3742e1626
2021-04-15 13:42:39 -07:00
Petr Pchelko
50f5d65c81 Fix up ActorStoreTest with new UserIdentityValue
Change-Id: I60e2dfef9f7c20c98b02f9fed341d4290ee6ca0b
2021-04-14 09:54:54 -07:00
jenkins-bot
37ab31298c Merge "Remove $actor field from UsererIdentityValue" 2021-04-14 14:40:12 +00:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
Petr Pchelko
9e0c6afaae Support User:0 in ActorStore
Surprizingly, PHP treats string "0" as false, so user name "0"
was unconditionally rejected by ActorStore. Even more surprizingly,
we actually have an actor with user name "0" [1], so we need to
explicitly check for nulls instead of just checking for falsy.

[1] https://en.wikipedia.org/wiki/User:0

Change-Id: I535c2aee3e109c3f535e40b747a1c7e4508171cb
2021-04-06 19:49:53 -06:00
Petr Pchelko
0f170d0bb8 ActorStore: clean cache if transaction aborted.
In case acquireActorId was called as a part of a larger
transaction and it gets rolled back, we need to clean in-process
caches in case something else would try to acquire actor ID
for the same actor again within the same request.

Bug: T277795
Change-Id: I912ebb380a1beead3043ac4c5653df947d613b99
2021-03-22 14:59:27 -06:00
daniel
806792281f ActorNormalization should require a DB connection.
ActorNormalization should only be used in contexts where a DB connection
is already being used, or at least easily available.

Bug: T276986
Change-Id: Ie8aadaffa4a30e63fcad0502d45b8ec364fc79ef
2021-03-10 21:43:49 +01:00
Vadim Kovalenko
493105109e Avoid using UserIdentity::getUserId
Replace UserIdentity::getUserId with ::getId
Add $wikiId = self::LOCAL as an optinal parameter to User and
UserIdentity

Bug: T275482
Change-Id: I44494845c469a14284c3e23cb620e5a7cbf59cd5
2021-03-02 16:12:55 -07:00
Petr Pchelko
1abe2e5318 Remove ActorStore::getUserIdentityByAnyId.
Adding this method was a mistake, there's no good use
for is really.

Change-Id: I0b2ecee7420573092f85f4e19da731a6bd56c50b
2021-03-01 17:41:42 -07:00
daniel
0ebf43b26d ActorStore: introduce findActorIdByName
The findActorIdByName method is intended to be used when we need to
select by actor ID, but all we have is a user name. We can't use
findActorId(), since it requires a UserIdentity, which would needlessly
force us to look up a user ID, resulting in two queries.

Bug: T274179
Change-Id: I0e65d3258fd3d23ebff793ae04d59e027eb51fba
2021-03-01 22:12:05 +01:00
jenkins-bot
5008ca185e Merge "UserQueryBuilder: abstraction for actor table queries." 2021-02-23 12:27:26 +00:00
jenkins-bot
9cd7d35500 Merge "Add a few tests for ActorStore corner cases" 2021-02-22 20:35:24 +00:00
Petr Pchelko
87a5cb4673 UserQueryBuilder: abstraction for actor table queries.
This introduces a specialized SelectQueryBuilder for
queries related to actor table. So far it's fairly basic,
but in future it is intended to grow.

This patch only introduces the new abstraction, using
it will be separated into separate patches.

Bug: T274223
Change-Id: Ibb1c58016e3956a46bfaf1a9f51f265114bb9ace
2021-02-22 11:47:07 -07:00
Cindy Cicalese
fd71596f97 Add caching to ActorStore
Bug: T273974
Depends-On: I8c18d86fe42056fbb676467a6657fd2f62e9c998
Change-Id: Iff5e3f07ac5b1192dd7a9f7f37589d8eae09a746
2021-02-22 09:25:13 -07:00
Petr Pchelko
49220ff4ab Add a few tests for ActorStore corner cases
Change-Id: Iba6c5d8fa15952cfef689f8f151f262aaff46417
2021-02-16 22:52:47 -06:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Petr Pchelko
4d8dc6b992 Use ActorStore in RevisionStore
Bug: T273290
Change-Id: Iff9b67455d337ea03cb728dd570c4ce760c39e49
2021-02-10 14:37:54 -06:00
Petr Pchelko
1398a72999 Reorder arguments in ActorStore::newActorFromRowFields
The order $userId, $name, $actorId is more consistent
with existing order of arguments in UIV constructor,
User::newFromAnyId etc. Even though it's not as logical
as placing the primary key argument first, it's more practical.

Change-Id: Ic36c0ee451cf6825976e374f0c2f721085c0a507
2021-02-09 08:46:24 -06:00
Petr Pchelko
8d2c674ab0 Introduce ActorStore, ActorLookup and ActorFactory.
The ActorNormalization factory methods create
UserIdentityValue from the database rows, either via
fields of a joined table, or via a row from actor table.
They assume that the actor_id exist and throw othervise.

ActorNormalization is a storage-layer service providing
access to finding and acquiring actor_id.

The UserIdentityLookup methods do not instantiate new actor
on demand, they just find an appropriate row in the actor
table and return the result.

Bug: T272689
Depends-On: I74d81f3f0233efb17fc8df5178e4c477cc669c6f
Change-Id: Icfa1daca960c696a8cef8adab5eab53985802858
2021-02-08 10:06:46 -06:00