| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\OATHAuth\Hook; |
| 4 |
|
| 5 |
use MediaWiki\Extension\OATHAuth\Maintenance\UpdateForMultipleDevicesSupport; |
| 6 |
use MediaWiki\Extension\OATHAuth\Maintenance\UpdateTOTPScratchTokensToArray; |
| 7 |
use MediaWiki\Installer\DatabaseUpdater; |
| 8 |
use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; |
| 9 |
|
| 10 |
class UpdateTables implements LoadExtensionSchemaUpdatesHook { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public function onLoadExtensionSchemaUpdates( $updater ) { |
| 16 |
$type = $updater->getDB()->getType(); |
| 17 |
$baseDir = dirname( __DIR__, 2 ); |
| 18 |
$typePath = "$baseDir/sql/$type"; |
| 19 |
|
| 20 |
$updater->addExtensionUpdateOnVirtualDomain( |
| 21 |
[ 'virtual-oathauth', 'addTable', 'oathauth_types', "$typePath/tables-generated.sql", true ] |
| 22 |
); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
if ( $updater->tableExists( 'oathauth_users' ) ) { |
| 27 |
switch ( $type ) { |
| 28 |
case 'mysql': |
| 29 |
case 'sqlite': |
| 30 |
|
| 31 |
$updater->addExtensionUpdate( [ |
| 32 |
'runMaintenance', |
| 33 |
UpdateTOTPScratchTokensToArray::class, |
| 34 |
] ); |
| 35 |
break; |
| 36 |
|
| 37 |
case 'postgres': |
| 38 |
|
| 39 |
$updater->addExtensionUpdateOnVirtualDomain( [ |
| 40 |
'virtual-oathauth', |
| 41 |
'modifyTable', |
| 42 |
'oathauth_users', |
| 43 |
"$typePath/patch-oathauth_users-drop-oathauth_users_id_seq.sql", |
| 44 |
true |
| 45 |
] ); |
| 46 |
break; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
$updater->addExtensionUpdateOnVirtualDomain( [ |
| 51 |
'virtual-oathauth', |
| 52 |
'runMaintenance', |
| 53 |
UpdateForMultipleDevicesSupport::class, |
| 54 |
] ); |
| 55 |
$updater->addExtensionUpdateOnVirtualDomain( [ 'virtual-oathauth', 'dropTable', 'oathauth_users' ] ); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
} |
| 60 |
} |