API:
[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 $maintenance = "$IP/maintenance";
22
23 # Initialise external storage
24 if ( is_array( $wgDefaultExternalStore ) ) {
25 $stores = $wgDefaultExternalStore;
26 } elseif ( $wgDefaultExternalStore ) {
27 $stores = array( $wgDefaultExternalStore );
28 } else {
29 $stores = array();
30 }
31 if ( count( $stores ) ) {
32 require_once( 'ExternalStoreDB.php' );
33 print "Initialising external storage $store...\n";
34 global $wgDBuser, $wgDBpassword, $wgExternalServers;
35 foreach ( $stores as $storeURL ) {
36 $m = array();
37 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
38 continue;
39 }
40
41 $cluster = $m[1];
42
43 # Hack
44 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
45 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
46
47 $store = new ExternalStoreDB;
48 $extdb =& $store->getMaster( $cluster );
49 $extdb->query( "SET table_type=InnoDB" );
50 $extdb->query( "CREATE DATABASE {$to}" );
51 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
52 $extdb->selectDB( $from );
53 dbsource( "$maintenance/storage/blobs.sql", $extdb );
54 $extdb->immediateCommit();
55 }
56 }
57
58 echo "done.\n";
59