Merge maintenance-work branch (now with less errors!):
[lhc/web/wiklou.git] / maintenance / renamewiki.php
1 <?php
2 /**
3 * Why yes, this *is* another special-purpose Wikimedia maintenance script!
4 * Should be fixed up and generalized.
5 *
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.
10 *
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.
15 *
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
20 *
21 * @ingroup Maintenance
22 */
23
24 require_once( "Maintenance.php" );
25
26 class RenameWiki extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Rename external storage dbs and leave a new one";
30 $this->addArgs( array( 'olddb', 'newdb' ) );
31 }
32
33 public function execute() {
34 global $wgDefaultExternalStore;
35
36 # Setup
37 $from = $this->getArg( 0 );
38 $to = $this->getArg( 1 );
39 $this->output( "Renaming blob tables in ES from $from to $to...\n" );
40 $this->output( "Sleeping 5 seconds...\n" );
41 sleep(5);
42
43 # Initialise external storage
44 if ( is_array( $wgDefaultExternalStore ) ) {
45 $stores = $wgDefaultExternalStore;
46 } elseif ( $wgDefaultExternalStore ) {
47 $stores = array( $wgDefaultExternalStore );
48 } else {
49 $stores = array();
50 }
51
52 if ( count( $stores ) ) {
53 $this->output( "Initialising external storage $store...\n" );
54 global $wgDBuser, $wgDBpassword, $wgExternalServers;
55 foreach ( $stores as $storeURL ) {
56 $m = array();
57 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
58 continue;
59 }
60
61 $cluster = $m[1];
62
63 # Hack
64 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
65 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
66
67 $store = new ExternalStoreDB;
68 $extdb =& $store->getMaster( $cluster );
69 $extdb->query( "SET table_type=InnoDB" );
70 $extdb->query( "CREATE DATABASE {$to}" );
71 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
72 $extdb->selectDB( $from );
73 $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' );
74 $extdb->immediateCommit();
75 }
76 }
77 $this->output( "done.\n" );
78 }
79 }
80
81 $maintClass = "RenameWiki";
82 require_once( DO_MAINTENANCE );