Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
SchemaHooks | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 1 |
onLoadExtensionSchemaUpdates | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications; |
4 | |
5 | use DatabaseUpdater; |
6 | use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; |
7 | |
8 | class SchemaHooks implements LoadExtensionSchemaUpdatesHook { |
9 | |
10 | /** |
11 | * @param DatabaseUpdater $updater |
12 | */ |
13 | public function onLoadExtensionSchemaUpdates( $updater ) { |
14 | global $wgEchoCluster; |
15 | if ( $wgEchoCluster ) { |
16 | // DatabaseUpdater does not support other databases, so skip |
17 | return; |
18 | } |
19 | |
20 | $db = $updater->getDB(); |
21 | $dbType = $db->getType(); |
22 | |
23 | $dir = dirname( __DIR__ ) . '/sql'; |
24 | |
25 | $updater->addExtensionTable( 'echo_event', "$dir/$dbType/tables-generated.sql" ); |
26 | |
27 | // 1.35 |
28 | $updater->addExtensionTable( 'echo_push_provider', "$dir/echo_push_provider.sql" ); |
29 | $updater->addExtensionTable( 'echo_push_subscription', "$dir/echo_push_subscription.sql" ); |
30 | |
31 | // 1.36 |
32 | $updater->addExtensionTable( 'echo_push_topic', "$dir/echo_push_topic.sql" ); |
33 | |
34 | // 1.39 |
35 | if ( $dbType === 'mysql' && $db->tableExists( 'echo_push_subscription', __METHOD__ ) ) { |
36 | // Split into single steps to support updates from some releases as well - T322143 |
37 | $updater->renameExtensionIndex( |
38 | 'echo_push_subscription', |
39 | 'echo_push_subscription_user_id', |
40 | 'eps_user', |
41 | "$dir/$dbType/patch-echo_push_subscription-rename-index-eps_user.sql", |
42 | false |
43 | ); |
44 | $updater->dropExtensionIndex( |
45 | 'echo_push_subscription', |
46 | 'echo_push_subscription_token', |
47 | "$dir/$dbType/patch-echo_push_subscription-drop-index-eps_token.sql" |
48 | ); |
49 | $updater->addExtensionIndex( |
50 | 'echo_push_subscription', |
51 | 'eps_token', |
52 | "$dir/$dbType/patch-echo_push_subscription-create-index-eps_token.sql" |
53 | ); |
54 | $updater->addExtensionField( |
55 | 'echo_push_subscription', |
56 | 'eps_topic', |
57 | "$dir/$dbType/patch-echo_push_subscription-add-column-eps_topic.sql" |
58 | ); |
59 | |
60 | $res = $db->query( 'SHOW CREATE TABLE ' . $db->tableName( 'echo_push_subscription' ), __METHOD__ ); |
61 | $row = $res ? $res->fetchRow() : false; |
62 | $statement = $row ? $row[1] : ''; |
63 | if ( str_contains( $statement, $db->addIdentifierQuotes( 'echo_push_subscription_ibfk_1' ) ) ) { |
64 | $updater->modifyExtensionTable( |
65 | 'echo_push_subscription', |
66 | "$dir/$dbType/patch-echo_push_subscription-drop-foreign-keys_1.sql" |
67 | ); |
68 | } |
69 | if ( str_contains( $statement, $db->addIdentifierQuotes( 'echo_push_subscription_ibfk_2' ) ) ) { |
70 | $updater->modifyExtensionTable( |
71 | 'echo_push_subscription', |
72 | "$dir/$dbType/patch-echo_push_subscription-drop-foreign-keys_2.sql" |
73 | ); |
74 | } |
75 | } |
76 | if ( $dbType === 'sqlite' ) { |
77 | $updater->addExtensionIndex( 'echo_push_subscription', 'eps_user', |
78 | "$dir/$dbType/patch-cleanup-push_subscription-foreign-keys-indexes.sql" ); |
79 | } |
80 | |
81 | global $wgEchoSharedTrackingCluster, $wgEchoSharedTrackingDB; |
82 | // Following tables should only be created if both cluster and database are false. |
83 | // Otherwise, they are not created in the place they are accesses, because |
84 | // DatabaseUpdater does not support other databases other than the main wiki schema. |
85 | if ( $wgEchoSharedTrackingCluster === false && $wgEchoSharedTrackingDB === false ) { |
86 | $updater->addExtensionTable( 'echo_unread_wikis', "$dir/$dbType/tables-sharedtracking-generated.sql" ); |
87 | } |
88 | } |
89 | |
90 | } |