Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 117 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
SchemaHookHandler | |
0.00% |
0 / 117 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
onLoadExtensionSchemaUpdates | |
0.00% |
0 / 117 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | declare( strict_types=1 ); |
4 | |
5 | namespace MediaWiki\Extension\Translate; |
6 | |
7 | use MediaWiki\Extension\Translate\Diagnostics\RemoveRedundantMessageGroupMetadataMaintenanceScript; |
8 | use MediaWiki\Extension\Translate\Diagnostics\SyncTranslatableBundleStatusMaintenanceScript; |
9 | use MediaWiki\Installer\DatabaseUpdater; |
10 | use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook; |
11 | |
12 | class SchemaHookHandler implements LoadExtensionSchemaUpdatesHook { |
13 | |
14 | /** @param DatabaseUpdater $updater */ |
15 | public function onLoadExtensionSchemaUpdates( $updater ) { |
16 | $dir = dirname( __DIR__, 1 ) . '/sql'; |
17 | $dbType = $updater->getDB()->getType(); |
18 | |
19 | if ( $dbType === 'mysql' || $dbType === 'sqlite' ) { |
20 | $updater->addExtensionTable( |
21 | 'translate_sections', |
22 | "{$dir}/{$dbType}/translate_sections.sql" |
23 | ); |
24 | $updater->addExtensionTable( |
25 | 'revtag', |
26 | "{$dir}/{$dbType}/revtag.sql" |
27 | ); |
28 | $updater->addExtensionTable( |
29 | 'translate_groupstats', |
30 | "{$dir}/{$dbType}/translate_groupstats.sql" |
31 | ); |
32 | $updater->addExtensionTable( |
33 | 'translate_reviews', |
34 | "{$dir}/{$dbType}/translate_reviews.sql" |
35 | ); |
36 | $updater->addExtensionTable( |
37 | 'translate_groupreviews', |
38 | "{$dir}/{$dbType}/translate_groupreviews.sql" |
39 | ); |
40 | $updater->addExtensionTable( |
41 | 'translate_tms', |
42 | "{$dir}/{$dbType}/translate_tm.sql" |
43 | ); |
44 | $updater->addExtensionTable( |
45 | 'translate_metadata', |
46 | "{$dir}/{$dbType}/translate_metadata.sql" |
47 | ); |
48 | $updater->addExtensionTable( |
49 | 'translate_messageindex', |
50 | "{$dir}/{$dbType}/translate_messageindex.sql" |
51 | ); |
52 | $updater->addExtensionTable( |
53 | 'translate_stash', |
54 | "{$dir}/{$dbType}/translate_stash.sql" |
55 | ); |
56 | $updater->addExtensionTable( |
57 | 'translate_translatable_bundles', |
58 | "{$dir}/{$dbType}/translate_translatable_bundles.sql" |
59 | ); |
60 | $updater->addExtensionUpdateOnVirtualDomain( [ |
61 | 'virtual-translate', |
62 | 'addTable', |
63 | 'translate_message_group_subscriptions', |
64 | "{$dir}/{$dbType}/translate_message_group_subscriptions.sql", |
65 | true |
66 | ] ); |
67 | $updater->addExtensionUpdateOnVirtualDomain( [ |
68 | 'virtual-translate', |
69 | 'addTable', |
70 | 'translate_cache', |
71 | "{$dir}/{$dbType}/translate_cache.sql", |
72 | true |
73 | ] ); |
74 | |
75 | if ( $dbType === 'mysql' ) { |
76 | // 1.38 |
77 | $updater->addExtensionUpdateOnVirtualDomain( [ |
78 | 'virtual-translate', |
79 | 'modifyField', |
80 | 'translate_cache', |
81 | 'tc_key', |
82 | "{$dir}/{$dbType}/translate_cache-alter-varbinary.sql", |
83 | true |
84 | ] ); |
85 | $updater->modifyExtensionField( |
86 | 'translate_groupreviews', |
87 | 'tgr_group', |
88 | "{$dir}/{$dbType}/translate_groupreviews-alter-varbinary.sql", |
89 | ); |
90 | } |
91 | } elseif ( $dbType === 'postgres' ) { |
92 | $updater->addExtensionTable( |
93 | 'translate_sections', |
94 | "{$dir}/{$dbType}/tables-generated.sql" |
95 | ); |
96 | $updater->addExtensionUpdateOnVirtualDomain( [ |
97 | 'virtual-translate', |
98 | 'changeField', |
99 | 'translate_cache', |
100 | 'tc_exptime', |
101 | 'TIMESTAMPTZ', |
102 | 'th_timestamp::timestamp with time zone' |
103 | ] ); |
104 | } |
105 | |
106 | // 1.39 |
107 | $updater->dropExtensionIndex( |
108 | 'translate_messageindex', |
109 | 'tmi_key', |
110 | "{$dir}/{$dbType}/patch-translate_messageindex-unique-to-pk.sql" |
111 | ); |
112 | $updater->dropExtensionIndex( |
113 | 'translate_tmt', |
114 | 'tms_sid_lang', |
115 | "{$dir}/{$dbType}/patch-translate_tmt-unique-to-pk.sql" |
116 | ); |
117 | $updater->dropExtensionIndex( |
118 | 'revtag', |
119 | 'rt_type_page_revision', |
120 | "{$dir}/{$dbType}/patch-revtag-unique-to-pk.sql" |
121 | ); |
122 | |
123 | // MW 1.43 |
124 | $updater->modifyExtensionTable( |
125 | 'revtag', |
126 | "{$dir}/{$dbType}/patch-revtag-int-to-bigint-unsigned.sql" |
127 | ); |
128 | $updater->modifyExtensionTable( |
129 | 'translate_reviews', |
130 | "{$dir}/{$dbType}/patch-translate_reviews-unsigned.sql" |
131 | ); |
132 | $updater->addExtensionUpdateOnVirtualDomain( [ |
133 | 'virtual-translate', |
134 | 'dropField', |
135 | 'translate_message_group_subscriptions', |
136 | 'tmgs_subscription_id', |
137 | "{$dir}/{$dbType}/patch-translate_message_group_subscriptions-composite-primary-key.sql", |
138 | true |
139 | ] ); |
140 | |
141 | $updater->addPostDatabaseUpdateMaintenance( SyncTranslatableBundleStatusMaintenanceScript::class ); |
142 | $updater->addPostDatabaseUpdateMaintenance( RemoveRedundantMessageGroupMetadataMaintenanceScript::class ); |
143 | } |
144 | } |