Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
migrate-schema2.php
Go to the documentation of this file.
1<?php
11use MediaWiki\Maintenance\Maintenance;
12
13// Standard boilerplate to define $IP
14if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
15 $IP = getenv( 'MW_INSTALL_PATH' );
16} else {
17 $dir = __DIR__;
18 $IP = "$dir/../../..";
19}
20require_once "$IP/maintenance/Maintenance.php";
21
27class TSchema2 extends Maintenance {
28
29 public function __construct() {
30 parent::__construct();
31 $this->addDescription( 'Migrates database schema to version 2.' );
32 $this->requireExtension( 'Translate' );
33 }
34
35 public function execute() {
36 $dbw = $this->getDB( DB_PRIMARY );
37
38 if ( !$dbw->tableExists( 'revtag', __METHOD__ ) ) {
39 $this->fatalError( "Table revtag doesn't exist. Translate extension is not installed?" );
40 }
41
42 if ( !$dbw->tableExists( 'revtag_type', __METHOD__ ) ) {
43 $this->fatalError( "Table revtag_type doesn't exist. Migration is already done." );
44 }
45
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 );
49 }
50
51 $table = $dbw->tableName( 'revtag' );
52 $dbw->query( "ALTER TABLE $table MODIFY rt_type varbinary(60) not null", __METHOD__ );
53
54 $res = $dbw->newSelectQueryBuilder()
55 ->select( [ 'rtt_id', 'rtt_name' ] )
56 ->from( 'revtag_type' )
57 ->caller( __METHOD__ )
58 ->fetchResultSet();
59
60 foreach ( $res as $row ) {
61 $dbw->newUpdateQueryBuilder()
62 ->update( 'revtag' )
63 ->set( [ 'rt_type' => $row->rtt_name ] )
64 ->where( [ 'rt_type' => (string)$row->rtt_id ] )
65 ->caller( __METHOD__ )
66 ->execute();
67 }
68
69 $dbw->dropTable( 'revtag_type', __METHOD__ );
70 }
71}
72
73$maintClass = TSchema2::class;
74require_once RUN_MAINTENANCE_IF_MAIN;
Script to convert Translate extension database schema to v2.