Whitespace changes
[mediawiki.git] / maintenance / renamewiki.php
blobf5722cf179502e2aab18771f305c3f9ed541710b
1 <?php
2 /**
3 * Why yes, this *is* another special-purpose Wikimedia maintenance script!
4 * Should be fixed up and generalized.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
22 * @ingroup Wikimedia
25 require_once( dirname(__FILE__) . '/Maintenance.php' );
27 class RenameWiki extends Maintenance {
28 public function __construct() {
29 parent::__construct();
30 $this->mDescription = "Rename external storage dbs and leave a new one";
31 $this->addArgs( array( 'olddb', 'newdb' ) );
34 public function execute() {
35 global $wgDefaultExternalStore;
37 # Setup
38 $from = $this->getArg( 0 );
39 $to = $this->getArg( 1 );
40 $this->output( "Renaming blob tables in ES from $from to $to...\n" );
41 $this->output( "Sleeping 5 seconds...\n" );
42 sleep(5);
44 # Initialise external storage
45 if ( is_array( $wgDefaultExternalStore ) ) {
46 $stores = $wgDefaultExternalStore;
47 } elseif ( $wgDefaultExternalStore ) {
48 $stores = array( $wgDefaultExternalStore );
49 } else {
50 $stores = array();
53 if ( count( $stores ) ) {
54 $this->output( "Initialising external storage $store...\n" );
55 global $wgDBuser, $wgDBpassword, $wgExternalServers;
56 foreach ( $stores as $storeURL ) {
57 $m = array();
58 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
59 continue;
62 $cluster = $m[1];
64 # Hack
65 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
66 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
68 $store = new ExternalStoreDB;
69 $extdb =& $store->getMaster( $cluster );
70 $extdb->query( "SET table_type=InnoDB" );
71 $extdb->query( "CREATE DATABASE {$to}" );
72 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
73 $extdb->selectDB( $from );
74 $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' );
75 $extdb->immediateCommit();
78 $this->output( "done.\n" );
82 $maintClass = "RenameWiki";
83 require_once( DO_MAINTENANCE );