OATHUserRepository: Remove some legacy handling

The migration from `oathauth_users.secret` to `oathauth_users.module`
was added in I71286534d21d950834. It resides now in the UpdateTables
class, which runs from the LoadExtensionSchemaUpdates hook.

The transition has been completed at WMF as well.

Bug: T304375
Change-Id: I5fa88704c6da2ae2679a19e0c5a2cfe7f3bf5f50
This commit is contained in:
Reedy 2022-03-21 23:59:51 +00:00 committed by Krinkle
parent 6adc5ecabf
commit 22505f73ae

View file

@ -26,7 +26,6 @@ use MediaWiki\MediaWikiServices;
use MWException;
use Psr\Log\LoggerInterface;
use RequestContext;
use stdClass;
use User;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\ILoadBalancer;
@ -84,21 +83,13 @@ class OATHUserRepository {
->centralIdFromLocalUser( $user );
$res = $this->getDB( DB_REPLICA )->selectRow(
'oathauth_users',
'*',
[ 'module', 'data' ],
[ 'id' => $uid ],
__METHOD__
);
if ( $res ) {
$data = $res->data;
$moduleKey = $res->module;
if ( $this->isLegacy( $res ) ) {
$module = $this->auth->getModuleByKey( 'totp' );
$data = $this->checkAndResolveLegacy( $data, $res );
} else {
$module = $this->auth->getModuleByKey( $moduleKey );
}
$module = $this->auth->getModuleByKey( $res->module );
if ( $module === null ) {
// For sanity
throw new MWException( 'oathauth-module-invalid' );
}
@ -204,40 +195,4 @@ class OATHUserRepository {
return $this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase );
}
/**
* @param stdClass $row
* @return bool
*/
private function isLegacy( $row ) {
if ( $row->module !== '' ) {
return false;
}
if ( property_exists( $row, 'secret' ) && $row->secret !== null ) {
return true;
}
return false;
}
/**
* Checks if the DB data is in the new format,
* if not converts old data to new
*
* @param string $data
* @param stdClass $row
* @return string
*/
private function checkAndResolveLegacy( $data, $row ) {
if ( $data ) {
// New data exists - no action required
return $data;
}
if ( property_exists( $row, 'secret' ) && property_exists( $row, 'scratch_tokens' ) ) {
return FormatJson::encode( [
'secret' => $row->secret,
'scratch_tokens' => $row->scratch_tokens
] );
}
return '';
}
}