Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
LoadExtensionSchemaUpdatesHookHandler | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
onLoadExtensionSchemaUpdates | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 |
1 | <?php |
2 | |
3 | namespace GlobalPreferences\HookHandler; |
4 | |
5 | use DatabaseUpdater; |
6 | use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; |
7 | use MediaWiki\MediaWikiServices; |
8 | |
9 | class LoadExtensionSchemaUpdatesHookHandler implements LoadExtensionSchemaUpdatesHook { |
10 | |
11 | /** |
12 | * @link https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates |
13 | * @param DatabaseUpdater $updater The database updater. |
14 | * @return bool|void True or no return value to continue or false to abort |
15 | */ |
16 | public function onLoadExtensionSchemaUpdates( $updater ) { |
17 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
18 | $dBname = $config->get( 'DBname' ); |
19 | $sharedDB = $config->get( 'SharedDB' ); |
20 | |
21 | // During install, extension registry config is not loaded - T198330 |
22 | $globalPreferencesDB = $config->has( 'GlobalPreferencesDB' ) |
23 | ? $config->get( 'GlobalPreferencesDB' ) |
24 | : null; |
25 | |
26 | // Only add the global_preferences table to the $wgGlobalPreferencesDB or the $wgSharedDB, |
27 | // unless neither of them is set. See also \GlobalPreferences\Storage::getDatabase(). |
28 | if ( ( $globalPreferencesDB === null && $sharedDB === null ) |
29 | || $dBname === $globalPreferencesDB |
30 | || ( $globalPreferencesDB === null && $dBname === $sharedDB ) |
31 | ) { |
32 | $type = $updater->getDB()->getType(); |
33 | $sqlPath = dirname( __DIR__, 2 ) . '/sql'; |
34 | |
35 | $updater->addExtensionTable( 'global_preferences', "$sqlPath/$type/tables-generated.sql" ); |
36 | |
37 | if ( $type === 'mysql' || $type === 'sqlite' ) { |
38 | $updater->dropExtensionIndex( 'global_preferences', |
39 | 'global_preferences_user_property', |
40 | "$sqlPath/patch_primary_index.sql" |
41 | ); |
42 | $updater->modifyExtensionField( 'global_preferences', |
43 | 'gp_user', |
44 | "$sqlPath/$type/patch-gp_user-unsigned.sql" |
45 | ); |
46 | } |
47 | } |
48 | } |
49 | } |