quickie script to move ES blob tables from one wiki name to another, leaving fresh...
[lhc/web/wiklou.git] / maintenance / renamewiki.php
1 <?php
2 require_once( "commandLine.inc" );
3
4 /**
5 * Why yes, this *is* another special-purpose Wikimedia maintenance script!
6 * Should be fixed up and generalized.
7 */
8
9 if ( count( $args ) != 2 ) {
10 wfDie( "Rename external storage dbs and leave a new one...\n" .
11 "Usage: php renamewiki.php <olddb> <newdb>\n" );
12 }
13
14 list( $from, $to ) = $args;
15
16 echo "Renaming blob tables in ES from $from to $to...\n";
17 echo "Sleeping 5 seconds...";
18 sleep(5);
19 echo "\n";
20
21 # Initialise external storage
22 if ( is_array( $wgDefaultExternalStore ) ) {
23 $stores = $wgDefaultExternalStore;
24 } elseif ( $wgDefaultExternalStore ) {
25 $stores = array( $wgDefaultExternalStore );
26 } else {
27 $stores = array();
28 }
29 if ( count( $stores ) ) {
30 require_once( 'ExternalStoreDB.php' );
31 print "Initialising external storage $store...\n";
32 global $wgDBuser, $wgDBpassword, $wgExternalServers;
33 foreach ( $stores as $storeURL ) {
34 $m = array();
35 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
36 continue;
37 }
38
39 $cluster = $m[1];
40
41 # Hack
42 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
43 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
44
45 $store = new ExternalStoreDB;
46 $extdb =& $store->getMaster( $cluster );
47 $extdb->query( "SET table_type=InnoDB" );
48 $extdb->query( "CREATE DATABASE {$to}" );
49 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
50 $extdb->selectDB( $to );
51 dbsource( "$maintenance/storage/blobs.sql", $extdb );
52 $extdb->immediateCommit();
53 }
54 }
55
56 echo "done.\n";
57
58 ?>