Merge "Display MediaWiki:Loginprompt on the login page"
[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 if ( !$this->doTable( $table ) ) {
69 return true;
70 }
71
72 $this->output( "...updating constraints on [$table].[$field] ..." );
73 $updateKey = "$field-$constraintType-ck";
74 if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
75 $this->output( "...$table table does not exist, skipping modify field patch.\n" );
76 return true;
77 } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
78 $this->output( "...$field field does not exist in $table table, " .
79 "skipping modify field patch.\n" );
80 return true;
81 } elseif ( $this->updateRowExists( $updateKey ) ) {
82 $this->output( "...$field in table $table already patched.\n" );
83 return true;
84 }
85
86 # After all checks passed, start the update
87 $this->insertUpdateRow( $updateKey );
88 $path = 'named_constraints.sql';
89 $constraintMap = array(
90 'category_types' =>
91 "($field in('page', 'subcat', 'file'))",
92 'major_mime' =>
93 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
94 " 'message', 'model', 'multipart'))",
95 'media_type' =>
96 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
97 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
98 );
99 $constraint = $constraintMap[$constraintType];
100
101 # and hack-in those variables that should be replaced
102 # in our template file right now
103 $this->db->setSchemaVars( array(
104 'tableName' => $table,
105 'fieldName' => $field,
106 'checkConstraint' => $constraint,
107 'wgDBname' => $wgDBname,
108 'wgDBmwschema' => $wgDBmwschema,
109 ) );
110
111 # Full path from file name
112 $path = $this->db->patchPath( $path );
113
114 # No need for a cursor allowing result-iteration; just apply a patch
115 # store old value for re-setting later
116 $wasScrollable = $this->db->scrollableCursor( false );
117
118 # Apply patch
119 $this->db->sourceFile( $path );
120
121 # Reset DB instance to have original state
122 $this->db->setSchemaVars( false );
123 $this->db->scrollableCursor( $wasScrollable );
124
125 $this->output( "done.\n" );
126
127 return true;
128 }
129 }