mediawiki-extensions-OATHAuth/maintenance/updateTOTPToMultipleKeys.php
Taavi Väänänen e3d07eb0ae
Add separate OATHAuthDatabase service
Add a simple service to access the central database to decrease code
repetition.

Change-Id: Ib33000f4d44d77da31cc375e374cb595ad23bcbd
2023-01-30 14:16:37 +02:00

58 lines
1.8 KiB
PHP

<?php
/**
* Update old single-key setup to multiple-keys
*
* Usage: php updateTOTPToMultipleKeys.php
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @author Dejan Savuljesku
* @ingroup Maintenance
*/
use MediaWiki\Extension\OATHAuth\Hook\UpdateTables;
use MediaWiki\Extension\OATHAuth\OATHAuthServices;
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class UpdateTOTPToMultipleKeys extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription( 'Script to update single TOTP keys to multi-key environment' );
$this->requireExtension( 'OATHAuth' );
}
public function execute() {
$database = OATHAuthServices::getInstance()->getDatabase();
$dbw = $database->getDB( DB_PRIMARY );
// @phan-suppress-next-line PhanTypeMismatchArgumentSuperType
if ( !UpdateTables::switchTOTPToMultipleKeys( $dbw ) ) {
$this->fatalError( "Failed to update TOTP keys.\n" );
}
$this->output( "Done.\n" );
}
}
$maintClass = UpdateTOTPToMultipleKeys::class;
require_once RUN_MAINTENANCE_IF_MAIN;