Drop ss_total_views and page_counter fields from MediaWiki
[lhc/web/wiklou.git] / includes / installer / MssqlUpdater.php
1 <?php
2 /**
3 * Microsoft SQL Server-specific installer.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Deployment
22 */
23
24 /**
25 * Class for setting up the MediaWiki database using Microsoft SQL Server.
26 *
27 * @ingroup Deployment
28 * @since 1.23
29 */
30
31 class MssqlUpdater extends DatabaseUpdater {
32
33 /**
34 * @var DatabaseMssql
35 */
36 protected $db;
37
38 protected function getCoreUpdateList() {
39 return array(
40 // 1.23
41 array( 'addField', 'mwuser', 'user_password_expires', 'patch-user_password_expires.sql' ),
42
43 // 1.24
44 array( 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql'),
45 array( 'dropTable', 'hitcounter' ),
46 array( 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ),
47 array( 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ),
48 // Constraint updates
49 array( 'updateConstraints', 'category_types', 'categorylinks', 'cl_type' ),
50 array( 'updateConstraints', 'major_mime', 'filearchive', 'fa_major_mime' ),
51 array( 'updateConstraints', 'media_type', 'filearchive', 'fa_media_type' ),
52 array( 'updateConstraints', 'major_mime', 'oldimage', 'oi_major_mime' ),
53 array( 'updateConstraints', 'media_type', 'oldimage', 'oi_media_type' ),
54 array( 'updateConstraints', 'major_mime', 'image', 'img_major_mime' ),
55 array( 'updateConstraints', 'media_type', 'image', 'img_media_type' ),
56 array( 'updateConstraints', 'media_type', 'uploadstash', 'us_media_type' ),
57 // END: Constraint updates
58
59 array( 'modifyField', 'image', 'img_major_mime',
60 'patch-img_major_mime-chemical.sql' ),
61 array( 'modifyField', 'oldimage', 'oi_major_mime',
62 'patch-oi_major_mime-chemical.sql' ),
63 array( 'modifyField', 'filearchive', 'fa_major_mime',
64 'patch-fa_major_mime-chemical.sql' ),
65 );
66 }
67
68 /**
69 * Drops unnamed and creates named constraints following the pattern
70 * <column>_ckc
71 *
72 * @param string $constraintType
73 * @param string $table Name of the table to which the field belongs
74 * @param string $field Name of the field to modify
75 * @return bool False if patch is skipped.
76 */
77 protected function updateConstraints( $constraintType, $table, $field ) {
78 global $wgDBname, $wgDBmwschema;
79
80 if ( !$this->doTable( $table ) ) {
81 return true;
82 }
83
84 $this->output( "...updating constraints on [$table].[$field] ..." );
85 $updateKey = "$field-$constraintType-ck";
86 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
87 $this->output( "...$table table does not exist, skipping modify field patch.\n" );
88 return true;
89 } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
90 $this->output( "...$field field does not exist in $table table, " .
91 "skipping modify field patch.\n" );
92 return true;
93 } elseif ( $this->updateRowExists( $updateKey ) ) {
94 $this->output( "...$field in table $table already patched.\n" );
95 return true;
96 }
97
98 # After all checks passed, start the update
99 $this->insertUpdateRow( $updateKey );
100 $path = 'named_constraints.sql';
101 $constraintMap = array(
102 'category_types' =>
103 "($field in('page', 'subcat', 'file'))",
104 'major_mime' =>
105 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
106 " 'message', 'model', 'multipart'))",
107 'media_type' =>
108 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
109 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
110 );
111 $constraint = $constraintMap[$constraintType];
112
113 # and hack-in those variables that should be replaced
114 # in our template file right now
115 $this->db->setSchemaVars( array(
116 'tableName' => $table,
117 'fieldName' => $field,
118 'checkConstraint' => $constraint,
119 'wgDBname' => $wgDBname,
120 'wgDBmwschema' => $wgDBmwschema,
121 ) );
122
123 # Full path from file name
124 $path = $this->db->patchPath( $path );
125
126 # No need for a cursor allowing result-iteration; just apply a patch
127 # store old value for re-setting later
128 $wasScrollable = $this->db->scrollableCursor( false );
129
130 # Apply patch
131 $this->db->sourceFile( $path );
132
133 # Reset DB instance to have original state
134 $this->db->setSchemaVars( false );
135 $this->db->scrollableCursor( $wasScrollable );
136
137 $this->output( "done.\n" );
138
139 return true;
140 }
141 }