OAuthUserRepository: Ensure we don't end up with duplicate rows

To do the migration we need to ensure that a single user has rows in
either the old oathauth_users table, or the new oauthauth_devices table,
but not in both.

Also add a missing startAtomic/endAtomic.

Bug: T242031
Change-Id: Ib0d42370b7206ff031873182c3fd957449656de8
This commit is contained in:
Taavi Väänänen 2023-08-15 16:09:53 +08:00
parent 2cb0c48655
commit 167d3670cb
No known key found for this signature in database
GPG key ID: EF242F709F912FBE

View file

@ -188,8 +188,18 @@ class OATHUserRepository implements LoggerAwareInterface {
];
}
// TODO: only update changed rows
$dbw = $this->database->getDB( DB_PRIMARY );
$dbw->startAtomic( __METHOD__ );
if ( $this->getMultipleDevicesMigrationStage() & SCHEMA_COMPAT_WRITE_OLD ) {
$dbw->delete(
'oathauth_users',
[ 'id' => $userId ],
__METHOD__
);
}
// TODO: only update changed rows
$dbw->delete(
'oathauth_devices',
[ 'oad_user' => $userId ],
@ -200,8 +210,8 @@ class OATHUserRepository implements LoggerAwareInterface {
$rows,
__METHOD__
);
}
if ( $this->getMultipleDevicesMigrationStage() & SCHEMA_COMPAT_WRITE_OLD ) {
$dbw->endAtomic( __METHOD__ );
} elseif ( $this->getMultipleDevicesMigrationStage() & SCHEMA_COMPAT_WRITE_OLD ) {
$data = [
'keys' => []
];