migrate-schema2.php
Go to the documentation of this file.00001 <?php
00011
00012 if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
00013 $IP = getenv( 'MW_INSTALL_PATH' );
00014 } else {
00015 $dir = __DIR__;
00016 $IP = "$dir/../../..";
00017 }
00018 require_once "$IP/maintenance/Maintenance.php";
00019
00025 class TSchema2 extends Maintenance {
00026
00027 public function __construct() {
00028 parent::__construct();
00029 $this->mDescription = 'Migrates database schema to version 2.';
00030 }
00031
00032 public function execute() {
00033 $dbw = wfGetDB( DB_MASTER );
00034 if ( !$dbw->tableExists( 'revtag' ) ) {
00035 $this->error( "Table revtag doesn't exist. Translate extension is not installed?", 1 );
00036 }
00037
00038 if ( !$dbw->tableExists( 'revtag_type' ) ) {
00039 $this->error( "Table revtag_type doesn't exist. Migration is already done.", 1 );
00040 }
00041
00042 if ( $dbw->getType() !== 'mysql' ) {
00043 $this->error( "This migration script only supports mysql. Please help " .
00044 "us to write routine for {$dbw->getType()}.", 1 );
00045 }
00046
00047 $table = $dbw->tableName( 'revtag' );
00048 $dbw->query( "ALTER TABLE $table MODIFY rt_type varbinary(60) not null", __METHOD__ );
00049
00050 $res = $dbw->select(
00051 'revtag_type',
00052 array( 'rtt_id', 'rtt_name' ),
00053 array(),
00054 __METHOD__
00055 );
00056
00057 foreach ( $res as $row ) {
00058 $dbw->update(
00059 'revtag',
00060 array( 'rt_type' => $row->rtt_name ),
00061 array( 'rt_type' => (string)$row->rtt_id ),
00062 __METHOD__
00063 );
00064 }
00065
00066 $dbw->dropTable( 'revtag_type', __METHOD__ );
00067 }
00068 }
00069
00070 $maintClass = 'TSchema2';
00071 require_once DO_MAINTENANCE;