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
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
When an username cannot be a valid actor,
ActorStore::newUserIdentityByName() should return null instead of
throwing an Exception.
Bug: T283167
Change-Id: Id04978cf2a417f2354d5e336ed1b0b67462603e9
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
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
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
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
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
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
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
Replace UserIdentity::getUserId with ::getId
Add $wikiId = self::LOCAL as an optinal parameter to User and
UserIdentity
Bug: T275482
Change-Id: I44494845c469a14284c3e23cb620e5a7cbf59cd5
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
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
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
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
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