00001 <?php
00010 require_once( "commandLine.inc" );
00011
00012 if ( count( $args ) != 2 ) {
00013 wfDie( "Rename external storage dbs and leave a new one...\n" .
00014 "Usage: php renamewiki.php <olddb> <newdb>\n" );
00015 }
00016
00017 list( $from, $to ) = $args;
00018
00019 echo "Renaming blob tables in ES from $from to $to...\n";
00020 echo "Sleeping 5 seconds...";
00021 sleep(5);
00022 echo "\n";
00023
00024 $maintenance = "$IP/maintenance";
00025
00026 # Initialise external storage
00027 if ( is_array( $wgDefaultExternalStore ) ) {
00028 $stores = $wgDefaultExternalStore;
00029 } elseif ( $wgDefaultExternalStore ) {
00030 $stores = array( $wgDefaultExternalStore );
00031 } else {
00032 $stores = array();
00033 }
00034 if ( count( $stores ) ) {
00035 require_once( 'ExternalStoreDB.php' );
00036 print "Initialising external storage $store...\n";
00037 global $wgDBuser, $wgDBpassword, $wgExternalServers;
00038 foreach ( $stores as $storeURL ) {
00039 $m = array();
00040 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
00041 continue;
00042 }
00043
00044 $cluster = $m[1];
00045
00046 # Hack
00047 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
00048 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
00049
00050 $store = new ExternalStoreDB;
00051 $extdb =& $store->getMaster( $cluster );
00052 $extdb->query( "SET table_type=InnoDB" );
00053 $extdb->query( "CREATE DATABASE {$to}" );
00054 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
00055 $extdb->selectDB( $from );
00056 dbsource( "$maintenance/storage/blobs.sql", $extdb );
00057 $extdb->immediateCommit();
00058 }
00059 }
00060
00061 echo "done.\n";
00062