00001 <?php
00009 $optionsWithArgs = array('old','new','help');
00010
00011 require_once( 'commandLine.inc' );
00012
00013 if( @$options['help'] || !isset($options['old']) || !isset($options['new']) ) {
00014 print "usage:updateSpecialPages.php [--help] [--old x] [new y]\n";
00015 print " --help : this help message\n";
00016 print " --old x : old db prefix x\n";
00017 print " --old 0 : EMPTY old db prefix x\n";
00018 print " --new y : new db prefix y\n";
00019 print " --new 0 : EMPTY new db prefix\n";
00020 wfDie();
00021 }
00022
00023
00024 if( $options['old'] === '0' ) {
00025 $old = '';
00026 } else {
00027
00028 preg_match( '/^[a-zA-Z]+_$/', $options['old'], $m );
00029 $old = isset($m[0]) ? $m[0] : false;
00030 }
00031
00032 if( $options['new'] === '0' ) {
00033 $new = '';
00034 } else {
00035
00036 preg_match( '/^[a-zA-Z]+_$/', $options['new'], $m );
00037 $new = isset($m[0]) ? $m[0] : false;
00038 }
00039
00040 if( $old===false || $new===false ) {
00041 print "Invalid prefix!\n";
00042 wfDie();
00043 }
00044 if( $old === $new ) {
00045 print "Same prefix. Nothing to rename!\n";
00046 wfDie();
00047 }
00048
00049 print "Renaming DB prefix for tables of $wgDBname from '$old' to '$new'\n";
00050 $count = 0;
00051
00052 $dbw = wfGetDB( DB_MASTER );
00053 $res = $dbw->query( "SHOW TABLES LIKE '".$dbw->escapeLike($old)."%'" );
00054 foreach( $res as $row ) {
00055
00056
00057 $fields = get_object_vars( $row );
00058
00059 foreach( $fields as $resName => $table ) {
00060
00061 $newTable = preg_replace( '/^'.$old.'/',$new,$table);
00062 print "Renaming table $table to $newTable\n";
00063 $dbw->query( "RENAME TABLE $table TO $newTable" );
00064 }
00065 $count++;
00066 }
00067 print "Done! [$count tables]\n";
00068