r101299 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101298‎ | r101299 | r101300 >
Date:12:42, 30 October 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Really added the script into version control
Modified paths:
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/scripts/migrate-schema2.php (added) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/migrate-schema2.php
@@ -0,0 +1,74 @@
 2+<?php
 3+/**
 4+ * Script to convert Translate extension database schema to v2
 5+ *
 6+ * @author Niklas Laxstrom
 7+ * @copyright Copyright © 2011, Niklas Laxström
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 9+ * @file
 10+ */
 11+
 12+// Standard boilerplate to define $IP
 13+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
 14+ $IP = getenv( 'MW_INSTALL_PATH' );
 15+} else {
 16+ $dir = dirname( __FILE__ ); $IP = "$dir/../../..";
 17+}
 18+require_once( "$IP/maintenance/Maintenance.php" );
 19+
 20+/**
 21+ * Script to convert Translate extension database schema to v2.
 22+ * Essentially gets rid of revtag_type table, which was unnecessary
 23+ * abstraction.
 24+ */
 25+class TSchema2 extends Maintenance {
 26+
 27+ public function __construct() {
 28+ parent::__construct();
 29+ $this->mDescription = 'Migrates db schema to version 2.';
 30+ }
 31+
 32+ public function execute() {
 33+ $dbw = wfGetDB( DB_MASTER );
 34+ if ( !$dbw->tableExists( 'revtag' ) ) {
 35+ $this->error( "Table revtag doesn't exist. Translate extension is not installed?" );
 36+ return;
 37+ }
 38+
 39+ if ( !$dbw->tableExists( 'revtag_type' ) ) {
 40+ $this->error( "Table revtag_type doesn't exist. Migration is already done." );
 41+ return;
 42+ }
 43+
 44+ if ( $dbw->getType() !== 'mysql' ) {
 45+ $this->error( "This migration script only supports mysql. Please help us to write routine for {$dbw->getType()}." );
 46+ return;
 47+ }
 48+
 49+ $table = $dbw->tableName( 'revtag' );
 50+ $dbw->query( "ALTER TABLE $table MODIFY rt_type varbinary(60) not null", __METHOD__ );
 51+
 52+ $res = $dbw->select(
 53+ 'revtag_type',
 54+ array( 'rtt_id', 'rtt_name' ),
 55+ array(),
 56+ __METHOD__
 57+ );
 58+
 59+ foreach ( $res as $row ) {
 60+ $dbw->update(
 61+ 'revtag',
 62+ array( 'rt_type' => $row->rtt_name ),
 63+ array( 'rt_type' => (string) $row->rtt_id ),
 64+ __METHOD__
 65+ );
 66+ }
 67+
 68+ $dbw->dropTable( 'revtag_type' );
 69+
 70+ }
 71+
 72+}
 73+
 74+$maintClass = 'TSchema2';
 75+require_once( DO_MAINTENANCE );
Property changes on: trunk/extensions/Translate/scripts/migrate-schema2.php
___________________________________________________________________
Added: svn:eol-style
176 + native
Index: trunk/extensions/Translate/README
@@ -30,6 +30,7 @@
3131
3232 == Change log ==
3333 * 2011-10-30
 34+- The script referenced at 2011-08-26 is now included in the source
3435 - Fixed compatibility with MW 1.17
3536 * 2011-10-28
3637 - New configuration variable $wgTranslatePermissionUrl

Status & tagging log