Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 116
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SqliteUpdater
0.00% covered (danger)
0.00%
0 / 116
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 getCoreUpdateList
0.00% covered (danger)
0.00%
0 / 100
0.00% covered (danger)
0.00%
0 / 1
2
 indexHasField
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 doFixIpbAddressUniqueIndex
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Sqlite-specific updater.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup Installer
23 */
24
25namespace MediaWiki\Installer;
26
27use FixInconsistentRedirects;
28use MigrateExternallinks;
29use MigrateRevisionActorTemp;
30use MigrateRevisionCommentTemp;
31use PopulateUserIsTemp;
32use UpdateRestrictions;
33
34/**
35 * Class for handling updates to Sqlite databases.
36 *
37 * @ingroup Installer
38 * @since 1.17
39 * @property \Wikimedia\Rdbms\DatabaseSqlite $db
40 */
41class SqliteUpdater extends DatabaseUpdater {
42
43    protected function getCoreUpdateList() {
44        return [
45            // 1.35
46            [ 'addField', 'revision', 'rev_actor', 'patch-revision-actor-comment-MCR.sql' ],
47            [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
48            [ 'modifyfield', 'filearchive', 'fa_actor', 'patch-filearchive-drop-fa_actor-DEFAULT.sql' ],
49            [ 'modifyfield', 'recentchanges', 'rc_actor', 'patch-recentchanges-drop-rc_actor-DEFAULT.sql' ],
50            [ 'modifyfield', 'logging', 'log_actor', 'patch-logging-drop-log_actor-DEFAULT.sql' ],
51            [ 'modifyField', 'page', 'page_restrictions', 'patch-page_restrictions-null.sql' ],
52            [ 'renameIndex', 'ipblocks', 'ipb_address', 'ipb_address_unique', false,
53                'patch-ipblocks-rename-ipb_address.sql' ],
54            [ 'dropField', 'archive', 'ar_text_id', 'patch-archive-MCR.sql' ],
55            [ 'doFixIpbAddressUniqueIndex' ],
56            [ 'modifyField', 'actor', 'actor_name', 'patch-actor-actor_name-varbinary.sql' ],
57
58            // 1.36
59            [ 'modifyField', 'content', 'content_id', 'patch-content-content_id-fix_not_null.sql' ],
60            [ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ],
61            [ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ],
62            [ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
63            [ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
64            [ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
65            [ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
66            [ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ],
67            [ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ],
68            [ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ],
69            [ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ],
70            [ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ],
71            [ 'modifyField', 'protected_titles', 'pt_expiry', 'patch-protected_titles-pt_expiry-drop-default.sql' ],
72            [ 'modifyField', 'ip_changes', 'ipc_rev_timestamp', 'patch-ip_changes-pc_rev_timestamp-drop-default.sql' ],
73            [ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false,
74                'patch-watchlist-namespace_title-rename-index.sql' ],
75            [ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ],
76            [ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id-fix_not_null.sql' ],
77            [ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id-fix_not_null.sql' ],
78            [ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ],
79            [ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ],
80            [ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false,
81                'patch-user_properties-rename-index.sql' ],
82            [ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ],
83            [ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ],
84            [ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ],
85            [ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ],
86            [ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ],
87            [ 'modifyField', 'ipblocks', 'ipb_timestamp', 'patch-ipblocks-ipb_timestamp-drop-default.sql' ],
88            [ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false,
89                'patch-archive-rename-name_title_timestamp-index.sql' ],
90            [ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ],
91            [ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
92                'patch-site_identifiers-rename-indexes.sql' ],
93            [ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
94            [ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
95                'patch-recentchanges-rc_new_name_timestamp.sql' ],
96            [ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ],
97            [ 'modifyField', 'page', 'page_title', 'patch-page-page_title-varbinary.sql' ],
98            [ 'modifyField', 'user', 'user_name', 'patch-user_table-updates.sql' ],
99
100            // 1.37
101            [ 'renameIndex', 'revision', 'page_timestamp', 'rev_page_timestamp', false,
102                'patch-revision-rename-index.sql' ],
103            [ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ],
104            [ 'modifyField', 'revision', 'rev_timestamp', 'patch-revision-rev_timestamp-drop-default.sql' ],
105            [ 'addIndex', 'oldimage', 'oi_timestamp', 'patch-oldimage-oi_timestamp.sql' ],
106            [ 'renameIndex', 'page', 'name_title', 'page_name_title', false,
107                'patch-page-rename-name_title-index.sql' ],
108            [ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id', false,
109                'patch-change_tag-rename-indexes.sql' ],
110
111            // 1.38
112            [ 'doConvertDjvuMetadata' ],
113            [ 'dropField', 'page_restrictions', 'pr_user', 'patch-drop-page_restrictions-pr_user.sql' ],
114            [ 'addTable', 'linktarget', 'patch-linktarget.sql' ],
115            [ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ],
116            [ 'modifyField', 'page_restrictions', 'pr_page', 'patch-page_restrictions-pr_page.sql' ],
117            [ 'modifyField', 'page_props', 'pp_page', 'patch-page_props-pp_page.sql' ],
118            [ 'modifyField', 'ipblocks_restrictions', 'ir_value', 'patch-ipblocks_restrictions-ir_value.sql' ],
119            [ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ],
120
121            // 1.39
122            [ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ],
123            [ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ],
124            [ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ],
125            [ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ],
126            [ 'runMaintenance', MigrateRevisionActorTemp::class, 'maintenance/migrateRevisionActorTemp.php' ],
127            [ 'dropTable', 'revision_actor_temp' ],
128            [ 'runMaintenance', UpdateRestrictions::class, 'maintenance/updateRestrictions.php' ],
129            [ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ],
130            [ 'migrateTemplatelinks' ],
131            [ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ],
132            [ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ],
133
134            // 1.40
135            [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
136
137            // 1.41
138            [ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ],
139            [ 'runMaintenance', MigrateRevisionCommentTemp::class, 'maintenance/migrateRevisionCommentTemp.php' ],
140            [ 'dropTable', 'revision_comment_temp' ],
141            [ 'runMaintenance', MigrateExternallinks::class, 'maintenance/migrateExternallinks.php' ],
142            [ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
143            [ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
144            [ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
145            [ 'runMaintenance', FixInconsistentRedirects::class, 'maintenance/fixInconsistentRedirects.php' ],
146            [ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ],
147            [ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ],
148            [ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ],
149            [ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ],
150
151            // 1.42
152            [ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ],
153            [ 'addTable', 'block_target', 'patch-block_target.sql' ],
154            [ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
155            [ 'runMaintenance', PopulateUserIsTemp::class, 'maintenance/populateUserIsTemp.php' ],
156            [ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
157            [ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ],
158        ];
159    }
160
161    /**
162     * Check whether an index contains a field
163     *
164     * @param string $table Table name
165     * @param string $index Index name to check
166     * @param string $field Field that should be in the index
167     * @return bool
168     */
169    protected function indexHasField( $table, $index, $field ) {
170        $info = $this->db->indexInfo( $table, $index, __METHOD__ );
171        if ( $info ) {
172            foreach ( $info as $column ) {
173                if ( $column == $field ) {
174                    $this->output( "...index $index on table $table includes field $field.\n" );
175                    return true;
176                }
177            }
178        }
179        $this->output( "...index $index on table $table has no field $field; added.\n" );
180
181        return false;
182    }
183
184    protected function doFixIpbAddressUniqueIndex() {
185        if ( !$this->indexHasField( 'ipblocks', 'ipb_address_unique', 'ipb_anon_only' ) ) {
186            $this->output( "...ipb_address_unique index up-to-date.\n" );
187            return;
188        }
189
190        $this->applyPatch(
191            'patch-ipblocks-fix-ipb_address_unique.sql',
192            false,
193            'Removing ipb_anon_only column from ipb_address_unique index'
194        );
195    }
196}