summaryrefslogtreecommitdiff
path: root/maintenance/renamewiki.php
blob: 66de326b733771d121af200c55bddfb55b819f67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
 * Why yes, this *is* another special-purpose Wikimedia maintenance script!
 * Should be fixed up and generalized.
 *
 * @file
 * @ingroup Maintenance
 */

require_once( "commandLine.inc" );

if ( count( $args ) != 2 ) {
	wfDie( "Rename external storage dbs and leave a new one...\n" .
			"Usage: php renamewiki.php <olddb> <newdb>\n" );
}

list( $from, $to ) = $args;

echo "Renaming blob tables in ES from $from to $to...\n";
echo "Sleeping 5 seconds...";
sleep(5);
echo "\n";

$maintenance = "$IP/maintenance";

# Initialise external storage
if ( is_array( $wgDefaultExternalStore ) ) {
	$stores = $wgDefaultExternalStore;
} elseif ( $wgDefaultExternalStore ) {
	$stores = array( $wgDefaultExternalStore );
} else {
	$stores = array();
}
if ( count( $stores ) ) {
	require_once( 'ExternalStoreDB.php' );
	print "Initialising external storage $store...\n";
	global $wgDBuser, $wgDBpassword, $wgExternalServers;
	foreach ( $stores as $storeURL ) {
		$m = array();
		if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
			continue;
		}
		
		$cluster = $m[1];
		
		# Hack
		$wgExternalServers[$cluster][0]['user'] = $wgDBuser;
		$wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
		
		$store = new ExternalStoreDB;
		$extdb =& $store->getMaster( $cluster );
		$extdb->query( "SET table_type=InnoDB" );
		$extdb->query( "CREATE DATABASE {$to}" );
		$extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
		$extdb->selectDB( $from );
		dbsource( "$maintenance/storage/blobs.sql", $extdb );
		$extdb->immediateCommit();
	}
}

echo "done.\n";