Fix syntax error from r55287
[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 * @ingroup Wikimedia
23 */
24
25 require_once( dirname(__FILE__) . '/Maintenance.php' );
26
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->addArg( 'olddb', 'Old DB name' );
32 $this->addArg( 'newdb', 'New DB name' );
33 }
34
35 protected function getDbType() {
36 return Maintenance::DB_ADMIN;
37 }
38
39 public function execute() {
40 global $wgDefaultExternalStore;
41
42 # Setup
43 $from = $this->getArg( 0 );
44 $to = $this->getArg( 1 );
45 $this->output( "Renaming blob tables in ES from $from to $to...\n" );
46 $this->output( "Sleeping 5 seconds...\n" );
47 sleep(5);
48
49 # Initialise external storage
50 if ( is_array( $wgDefaultExternalStore ) ) {
51 $stores = $wgDefaultExternalStore;
52 } elseif ( $wgDefaultExternalStore ) {
53 $stores = array( $wgDefaultExternalStore );
54 } else {
55 $stores = array();
56 }
57
58 if ( count( $stores ) ) {
59 $this->output( "Initialising external storage $store...\n" );
60 global $wgDBuser, $wgDBpassword, $wgExternalServers;
61 foreach ( $stores as $storeURL ) {
62 $m = array();
63 if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) {
64 continue;
65 }
66
67 $cluster = $m[1];
68
69 # Hack
70 $wgExternalServers[$cluster][0]['user'] = $wgDBuser;
71 $wgExternalServers[$cluster][0]['password'] = $wgDBpassword;
72
73 $store = new ExternalStoreDB;
74 $extdb =& $store->getMaster( $cluster );
75 $extdb->query( "SET table_type=InnoDB" );
76 $extdb->query( "CREATE DATABASE {$to}" );
77 $extdb->query( "ALTER TABLE {$from}.blobs RENAME TO {$to}.blobs" );
78 $extdb->selectDB( $from );
79 $extdb->sourceFile( $this->getDir() . '/storage/blobs.sql' );
80 $extdb->immediateCommit();
81 }
82 }
83 $this->output( "done.\n" );
84 }
85 }
86
87 $maintClass = "RenameWiki";
88 require_once( DO_MAINTENANCE );