MediaWiki
REL1_24
|
00001 <?php 00024 require_once __DIR__ . '/Maintenance.php'; 00025 00032 class CleanupAncientTables extends Maintenance { 00033 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Cleanup ancient tables and indexes"; 00037 $this->addOption( 'force', 'Actually run this script' ); 00038 } 00039 00040 public function execute() { 00041 if ( !$this->hasOption( 'force' ) ) { 00042 $this->error( "This maintenance script will remove old columns and indexes.\n" 00043 . "It is recommended to backup your database first, and ensure all your data has\n" 00044 . "been migrated to newer tables. If you want to continue, run this script again\n" 00045 . "with --force.\n" 00046 ); 00047 } 00048 00049 $db = wfGetDB( DB_MASTER ); 00050 $ancientTables = array( 00051 'blobs', // 1.4 00052 'brokenlinks', // 1.4 00053 'cur', // 1.4 00054 'ip_blocks_old', // Temporary in 1.6 00055 'links', // 1.4 00056 'linkscc', // 1.4 00057 // 'math', // 1.18, but don't want to drop if math extension is enabled... 00058 'old', // 1.4 00059 'oldwatchlist', // pre 1.1? 00060 'trackback', // 1.19 00061 'user_rights', // 1.5 00062 'validate', // 1.6 00063 ); 00064 00065 foreach ( $ancientTables as $table ) { 00066 if ( $db->tableExists( $table, __METHOD__ ) ) { 00067 $this->output( "Dropping table $table..." ); 00068 $db->dropTable( $table, __METHOD__ ); 00069 $this->output( "done.\n" ); 00070 } 00071 } 00072 00073 $this->output( "Cleaning up text table\n" ); 00074 00075 $oldIndexes = array( 00076 'old_namespace', 00077 'old_timestamp', 00078 'name_title_timestamp', 00079 'user_timestamp', 00080 'usertext_timestamp', 00081 ); 00082 foreach ( $oldIndexes as $index ) { 00083 if ( $db->indexExists( 'text', $index, __METHOD__ ) ) { 00084 $this->output( "Dropping index $index from the text table..." ); 00085 $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index ) 00086 . " ON " . $db->tableName( 'text' ) ); 00087 $this->output( "done.\n" ); 00088 } 00089 } 00090 00091 $oldFields = array( 00092 'old_namespace', 00093 'old_title', 00094 'old_comment', 00095 'old_user', 00096 'old_user_text', 00097 'old_timestamp', 00098 'old_minor_edit', 00099 'inverse_timestamp', 00100 ); 00101 foreach ( $oldFields as $field ) { 00102 if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) { 00103 $this->output( "Dropping the $field field from the text table..." ); 00104 $db->query( "ALTER TABLE " . $db->tableName( 'text' ) 00105 . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) ); 00106 $this->output( "done.\n" ); 00107 } 00108 } 00109 $this->output( "Done!\n" ); 00110 } 00111 } 00112 00113 $maintClass = "CleanupAncientTables"; 00114 require_once RUN_MAINTENANCE_IF_MAIN;