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