00001 <?php
00026 require_once( dirname(__FILE__) . '/Maintenance.php' );
00027
00028 class RenameWiki extends Maintenance {
00029 public function __construct() {
00030 parent::__construct();
00031 $this->mDescription = "Rename external storage dbs and leave a new one";
00032 $this->addArg( 'olddb', 'Old DB name' );
00033 $this->addArg( 'newdb', 'New DB name' );
00034 }
00035
00036 public function getDbType() {
00037 return Maintenance::DB_ADMIN;
00038 }
00039
00040 public function execute() {
00041 global $wgDefaultExternalStore;
00042
00043 # Setup
00044 $from = $this->getArg( 0 );
00045 $to = $this->getArg( 1 );
00046 $this->output( "Renaming blob tables in ES from $from to $to...\n" );
00047 $this->output( "Sleeping 5 seconds...\n" );
00048 sleep(5);
00049
00050 # Initialise external storage
00051 if ( is_array( $wgDefaultExternalStore ) ) {
00052 $stores = $wgDefaultExternalStore;
00053 } elseif ( $wgDefaultExternalStore ) {
00054 $stores = array( $wgDefaultExternalStore );
00055 } else {
00056 $stores = array();
00057 }
00058
00059 if ( count( $stores ) ) {
00060 $this->output( "Initialising external storage $store...\n" );
00061 global $wgDBuser, $wgDBpassword, $wgExternalServers;
00062 foreach ( $stores as $storeURL ) {
00063 $m = array();
00064 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
00065 continue;
00066 }
00067
00068 $cluster = $m[1];
00069
00070 # Hack
00071 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
00072 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
00073
00074 $store = new ExternalStoreDB;
00075 $extdb =& $store->getMaster( $cluster );
00076 $extdb->query( "SET table_type=InnoDB" );
00077 $extdb->query( "CREATE DATABASE {$to}" );
00078 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
00079 $extdb->selectDB( $from );
00080 $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' );
00081 $extdb->commit();
00082 }
00083 }
00084 $this->output( "done.\n" );
00085 }
00086 }
00087
00088 $maintClass = "RenameWiki";
00089 require_once( DO_MAINTENANCE );