Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / installer / MssqlUpdater.php
blob5eef335532e363d5d12036c15b1be9c26b97cc1f
1 <?php
2 /**
3 * Microsoft SQL Server-specific installer.
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.
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.
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
20 * @file
21 * @ingroup Deployment
24 /**
25 * Class for setting up the MediaWiki database using Microsoft SQL Server.
27 * @ingroup Deployment
28 * @since 1.23
31 class MssqlUpdater extends DatabaseUpdater {
33 /**
34 * @var DatabaseMssql
36 protected $db;
38 protected function getCoreUpdateList() {
39 return array(
40 // 1.23
41 array( 'addField', 'mwuser', 'user_password_expires', 'patch-user_password_expires.sql' ),
43 // 1.24
44 array( 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql'),
46 // 1.25
47 array( 'dropTable', 'hitcounter' ),
48 array( 'dropField', 'site_stats', 'ss_total_views', 'patch-drop-ss_total_views.sql' ),
49 array( 'dropField', 'page', 'page_counter', 'patch-drop-page_counter.sql' ),
50 // Constraint updates
51 array( 'updateConstraints', 'category_types', 'categorylinks', 'cl_type' ),
52 array( 'updateConstraints', 'major_mime', 'filearchive', 'fa_major_mime' ),
53 array( 'updateConstraints', 'media_type', 'filearchive', 'fa_media_type' ),
54 array( 'updateConstraints', 'major_mime', 'oldimage', 'oi_major_mime' ),
55 array( 'updateConstraints', 'media_type', 'oldimage', 'oi_media_type' ),
56 array( 'updateConstraints', 'major_mime', 'image', 'img_major_mime' ),
57 array( 'updateConstraints', 'media_type', 'image', 'img_media_type' ),
58 array( 'updateConstraints', 'media_type', 'uploadstash', 'us_media_type' ),
59 // END: Constraint updates
61 array( 'modifyField', 'image', 'img_major_mime',
62 'patch-img_major_mime-chemical.sql' ),
63 array( 'modifyField', 'oldimage', 'oi_major_mime',
64 'patch-oi_major_mime-chemical.sql' ),
65 array( 'modifyField', 'filearchive', 'fa_major_mime',
66 'patch-fa_major_mime-chemical.sql' ),
70 /**
71 * Drops unnamed and creates named constraints following the pattern
72 * <column>_ckc
74 * @param string $constraintType
75 * @param string $table Name of the table to which the field belongs
76 * @param string $field Name of the field to modify
77 * @return bool False if patch is skipped.
79 protected function updateConstraints( $constraintType, $table, $field ) {
80 global $wgDBname, $wgDBmwschema;
82 if ( !$this->doTable( $table ) ) {
83 return true;
86 $this->output( "...updating constraints on [$table].[$field] ..." );
87 $updateKey = "$field-$constraintType-ck";
88 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
89 $this->output( "...$table table does not exist, skipping modify field patch.\n" );
90 return true;
91 } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
92 $this->output( "...$field field does not exist in $table table, " .
93 "skipping modify field patch.\n" );
94 return true;
95 } elseif ( $this->updateRowExists( $updateKey ) ) {
96 $this->output( "...$field in table $table already patched.\n" );
97 return true;
100 # After all checks passed, start the update
101 $this->insertUpdateRow( $updateKey );
102 $path = 'named_constraints.sql';
103 $constraintMap = array(
104 'category_types' =>
105 "($field in('page', 'subcat', 'file'))",
106 'major_mime' =>
107 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
108 " 'message', 'model', 'multipart'))",
109 'media_type' =>
110 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
111 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
113 $constraint = $constraintMap[$constraintType];
115 # and hack-in those variables that should be replaced
116 # in our template file right now
117 $this->db->setSchemaVars( array(
118 'tableName' => $table,
119 'fieldName' => $field,
120 'checkConstraint' => $constraint,
121 'wgDBname' => $wgDBname,
122 'wgDBmwschema' => $wgDBmwschema,
123 ) );
125 # Full path from file name
126 $path = $this->db->patchPath( $path );
128 # No need for a cursor allowing result-iteration; just apply a patch
129 # store old value for re-setting later
130 $wasScrollable = $this->db->scrollableCursor( false );
132 # Apply patch
133 $this->db->sourceFile( $path );
135 # Reset DB instance to have original state
136 $this->db->setSchemaVars( false );
137 $this->db->scrollableCursor( $wasScrollable );
139 $this->output( "done.\n" );
141 return true;