Merge "Allow wildcard searching in wiki IDs for interwiki user rights logs"
[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 // Constraint updates
46 array( 'updateConstraints', 'category_types', 'categorylinks', 'cl_type' ),
47 array( 'updateConstraints', 'major_mime', 'filearchive', 'fa_major_mime' ),
48 array( 'updateConstraints', 'media_type', 'filearchive', 'fa_media_type' ),
49 array( 'updateConstraints', 'major_mime', 'oldimage', 'oi_major_mime' ),
50 array( 'updateConstraints', 'media_type', 'oldimage', 'oi_media_type' ),
51 array( 'updateConstraints', 'major_mime', 'image', 'img_major_mime' ),
52 array( 'updateConstraints', 'media_type', 'image', 'img_media_type' ),
53 array( 'updateConstraints', 'media_type', 'uploadstash', 'us_media_type' ),
54 // END: Constraint updates
55 );
56 }
57
58 /**
59 * Drops unnamed and creates named constraints following the pattern
60 * <column>_ckc
61 *
62 * @param string $constraintType
63 * @param string $table Name of the table to which the field belongs
64 * @param string $field Name of the field to modify
65 * @return bool False if patch is skipped.
66 */
67 protected function updateConstraints( $constraintType, $table, $field ) {
68 global $wgDBname, $wgDBmwschema;
69
70 if ( !$this->doTable( $table ) ) {
71 return true;
72 }
73
74 $this->output( "...updating constraints on [$table].[$field] ..." );
75 $updateKey = "$field-$constraintType-ck";
76 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
77 $this->output( "...$table table does not exist, skipping modify field patch.\n" );
78 return true;
79 } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
80 $this->output( "...$field field does not exist in $table table, " .
81 "skipping modify field patch.\n" );
82 return true;
83 } elseif ( $this->updateRowExists( $updateKey ) ) {
84 $this->output( "...$field in table $table already patched.\n" );
85 return true;
86 }
87
88 # After all checks passed, start the update
89 $this->insertUpdateRow( $updateKey );
90 $path = 'named_constraints.sql';
91 $constraintMap = array(
92 'category_types' =>
93 "($field in('page', 'subcat', 'file'))",
94 'major_mime' =>
95 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
96 " 'message', 'model', 'multipart'))",
97 'media_type' =>
98 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
99 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
100 );
101 $constraint = $constraintMap[$constraintType];
102
103 # and hack-in those variables that should be replaced
104 # in our template file right now
105 $this->db->setSchemaVars( array(
106 'tableName' => $table,
107 'fieldName' => $field,
108 'checkConstraint' => $constraint,
109 'wgDBname' => $wgDBname,
110 'wgDBmwschema' => $wgDBmwschema,
111 ) );
112
113 # Full path from file name
114 $path = $this->db->patchPath( $path );
115
116 # No need for a cursor allowing result-iteration; just apply a patch
117 # store old value for re-setting later
118 $wasScrollable = $this->db->scrollableCursor( false );
119
120 # Apply patch
121 $this->db->sourceFile( $path );
122
123 # Reset DB instance to have original state
124 $this->db->setSchemaVars( false );
125 $this->db->scrollableCursor( $wasScrollable );
126
127 $this->output( "done.\n" );
128
129 return true;
130 }
131 }