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