From 167d3670cb63e44db23ba1eb69a267f8aac92fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taavi=20V=C3=A4=C3=A4n=C3=A4nen?= Date: Tue, 15 Aug 2023 16:09:53 +0800 Subject: [PATCH] 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 --- src/OATHUserRepository.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/OATHUserRepository.php b/src/OATHUserRepository.php index 319518c5..db3e701c 100644 --- a/src/OATHUserRepository.php +++ b/src/OATHUserRepository.php @@ -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' => [] ];