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
25 * Class for setting up the MediaWiki database using Microsoft SQL Server.
31 class MssqlUpdater
extends DatabaseUpdater
{
38 protected function getCoreUpdateList() {
41 array( 'addField', 'mwuser', 'user_password_expires', 'patch-user_password_expires.sql' ),
44 array( 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql'),
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
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' ),
66 * Drops unnamed and creates named constraints following the pattern
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.
74 protected function updateConstraints( $constraintType, $table, $field ) {
75 global $wgDBname, $wgDBmwschema;
77 if ( !$this->doTable( $table ) ) {
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" );
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" );
90 } elseif ( $this->updateRowExists( $updateKey ) ) {
91 $this->output( "...$field in table $table already patched.\n" );
95 # After all checks passed, start the update
96 $this->insertUpdateRow( $updateKey );
97 $path = 'named_constraints.sql';
98 $constraintMap = array(
100 "($field in('page', 'subcat', 'file'))",
102 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
103 " 'message', 'model', 'multipart'))",
105 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
106 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
108 $constraint = $constraintMap[$constraintType];
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,
120 # Full path from file name
121 $path = $this->db
->patchPath( $path );
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 );
128 $this->db
->sourceFile( $path );
130 # Reset DB instance to have original state
131 $this->db
->setSchemaVars( false );
132 $this->db
->scrollableCursor( $wasScrollable );
134 $this->output( "done.\n" );