mDescription = "Cleanup ancient tables and indexes"; $this->addOption( 'force', 'Actually run this script' ); } public function execute() { if( !$this->hasOption( 'force' ) ) { $this->error( "This maintenance script will remove old columns and indexes.\n" . "It is recommended to backup your database first, and ensure all your data has been migrated to newer tables\n" . "If you want to continue, run this script again with the --force \n" ); } $db = wfGetDB( DB_MASTER ); $ancientTables = array( 'blobs', // 1.4 'brokenlinks', // 1.4 'cur', // 1.4 'ip_blocks_old', // Temporary in 1.6 'links', // 1.4 'linkscc', // 1.4 // 'math', // 1.18, but don't want to drop if math extension is enabled... 'old', // 1.4 'oldwatchlist', // pre 1.1? 'trackback', // 1.19 'user_rights', // 1.5 'validate', // 1.6 ); foreach( $ancientTables as $table ) { if ( $db->tableExists( $table, __METHOD__ ) ) { $this->output( "Dropping table $table..." ); $db->dropTable( $table, __METHOD__ ); $this->output( "done.\n" ); } } $this->output( "Cleaning up text table\n" ); $oldIndexes = array( 'old_namespace', 'old_timestamp', 'name_title_timestamp', 'user_timestamp', 'usertext_timestamp', ); foreach( $oldIndexes as $index ) { if ( $db->indexExists( 'text', $index, __METHOD__ ) ) { $this->output( "Dropping index $index from the text table..." ); $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index ) . " ON " . $db->tableName( 'text' ) ); $this->output( "done.\n" ); } } $oldFields = array( 'old_namespace', 'old_title', 'old_comment', 'old_user', 'old_user_text', 'old_timestamp', 'old_minor_edit', 'inverse_timestamp', ); foreach( $oldFields as $field ) { if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) { $this->output( "Dropping the $field field from the text table..." ); $db->query( "ALTER TABLE " . $db->tableName( 'text' ) . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) ); $this->output( "done.\n" ); } } $this->output( "Done!\n" ); } } $maintClass = "CleanupAncientTables"; require_once( RUN_MAINTENANCE_IF_MAIN );