MediaWiki  REL1_24
MssqlUpdater.php
Go to the documentation of this file.
00001 <?php
00031 class MssqlUpdater extends DatabaseUpdater {
00032 
00036     protected $db;
00037 
00038     protected function getCoreUpdateList() {
00039         return array(
00040             // 1.23
00041             array( 'addField', 'mwuser', 'user_password_expires', 'patch-user_password_expires.sql' ),
00042 
00043             // 1.24
00044             array( 'addField', 'page', 'page_lang', 'patch-page-page_lang.sql'),
00045             // Constraint updates
00046             array( 'updateConstraints', 'category_types', 'categorylinks', 'cl_type' ),
00047             array( 'updateConstraints', 'major_mime', 'filearchive', 'fa_major_mime' ),
00048             array( 'updateConstraints', 'media_type', 'filearchive', 'fa_media_type' ),
00049             array( 'updateConstraints', 'major_mime', 'oldimage', 'oi_major_mime' ),
00050             array( 'updateConstraints', 'media_type', 'oldimage', 'oi_media_type' ),
00051             array( 'updateConstraints', 'major_mime', 'image', 'img_major_mime' ),
00052             array( 'updateConstraints', 'media_type', 'image', 'img_media_type' ),
00053             array( 'updateConstraints', 'media_type', 'uploadstash', 'us_media_type' ),
00054             // END: Constraint updates
00055 
00056             array( 'modifyField', 'image', 'img_major_mime',
00057                 'patch-img_major_mime-chemical.sql' ),
00058             array( 'modifyField', 'oldimage', 'oi_major_mime',
00059                 'patch-oi_major_mime-chemical.sql' ),
00060             array( 'modifyField', 'filearchive', 'fa_major_mime',
00061                 'patch-fa_major_mime-chemical.sql' ),
00062         );
00063     }
00064 
00074     protected function updateConstraints( $constraintType, $table, $field ) {
00075         global $wgDBname, $wgDBmwschema;
00076 
00077         if ( !$this->doTable( $table ) ) {
00078             return true;
00079         }
00080 
00081         $this->output( "...updating constraints on [$table].[$field] ..." );
00082         $updateKey = "$field-$constraintType-ck";
00083         if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
00084             $this->output( "...$table table does not exist, skipping modify field patch.\n" );
00085             return true;
00086         } elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) {
00087             $this->output( "...$field field does not exist in $table table, " .
00088                 "skipping modify field patch.\n" );
00089             return true;
00090         } elseif ( $this->updateRowExists( $updateKey ) ) {
00091             $this->output( "...$field in table $table already patched.\n" );
00092             return true;
00093         }
00094 
00095         # After all checks passed, start the update
00096         $this->insertUpdateRow( $updateKey );
00097         $path = 'named_constraints.sql';
00098         $constraintMap = array(
00099             'category_types' =>
00100                 "($field in('page', 'subcat', 'file'))",
00101             'major_mime'     =>
00102                 "($field in('unknown', 'application', 'audio', 'image', 'text', 'video'," .
00103                 " 'message', 'model', 'multipart'))",
00104             'media_type'     =>
00105                 "($field in('UNKNOWN', 'BITMAP', 'DRAWING', 'AUDIO', 'VIDEO', 'MULTIMEDIA'," .
00106                 "'OFFICE', 'TEXT', 'EXECUTABLE', 'ARCHIVE'))"
00107         );
00108         $constraint = $constraintMap[$constraintType];
00109 
00110         # and hack-in those variables that should be replaced
00111         # in our template file right now
00112         $this->db->setSchemaVars( array(
00113             'tableName'       => $table,
00114             'fieldName'       => $field,
00115             'checkConstraint' => $constraint,
00116             'wgDBname'        => $wgDBname,
00117             'wgDBmwschema'    => $wgDBmwschema,
00118         ) );
00119 
00120         # Full path from file name
00121         $path = $this->db->patchPath( $path );
00122 
00123         # No need for a cursor allowing result-iteration; just apply a patch
00124         # store old value for re-setting later
00125         $wasScrollable = $this->db->scrollableCursor( false );
00126 
00127         # Apply patch
00128         $this->db->sourceFile( $path );
00129 
00130         # Reset DB instance to have original state
00131         $this->db->setSchemaVars( false );
00132         $this->db->scrollableCursor( $wasScrollable );
00133 
00134         $this->output( "done.\n" );
00135 
00136         return true;
00137     }
00138 }