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