11use MediaWiki\Maintenance\Maintenance;
14if ( getenv(
'MW_INSTALL_PATH' ) !==
false ) {
15 $IP = getenv(
'MW_INSTALL_PATH' );
18 $IP =
"$dir/../../..";
20require_once
"$IP/maintenance/Maintenance.php";
29 public function __construct() {
30 parent::__construct();
31 $this->addDescription(
'Migrates database schema to version 2.' );
32 $this->requireExtension(
'Translate' );
35 public function execute() {
36 $dbw = $this->getDB( DB_PRIMARY );
38 if ( !$dbw->tableExists(
'revtag', __METHOD__ ) ) {
39 $this->fatalError(
"Table revtag doesn't exist. Translate extension is not installed?" );
42 if ( !$dbw->tableExists(
'revtag_type', __METHOD__ ) ) {
43 $this->fatalError(
"Table revtag_type doesn't exist. Migration is already done." );
46 if ( $dbw->getType() !==
'mysql' ) {
47 $this->error(
'This migration script only supports mysql. Please help ' .
48 "us to write routine for {$dbw->getType()}.", 1 );
51 $table = $dbw->tableName(
'revtag' );
52 $dbw->query(
"ALTER TABLE $table MODIFY rt_type varbinary(60) not null", __METHOD__ );
54 $res = $dbw->newSelectQueryBuilder()
55 ->select( [
'rtt_id',
'rtt_name' ] )
56 ->from(
'revtag_type' )
57 ->caller( __METHOD__ )
60 foreach ( $res as $row ) {
61 $dbw->newUpdateQueryBuilder()
63 ->set( [
'rt_type' => $row->rtt_name ] )
64 ->where( [
'rt_type' => (
string)$row->rtt_id ] )
65 ->caller( __METHOD__ )
69 $dbw->dropTable(
'revtag_type', __METHOD__ );
73$maintClass = TSchema2::class;
74require_once RUN_MAINTENANCE_IF_MAIN;
Script to convert Translate extension database schema to v2.