MediaWiki  REL1_20
cleanupAncientTables.php
Go to the documentation of this file.
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 been migrated to newer tables\n"
00044                                 . "If you want to continue, run this script again with the --force \n"
00045                         );
00046                 }
00047 
00048                 $db = wfGetDB( DB_MASTER );
00049                 $ancientTables = array(
00050                         'blobs', // 1.4
00051                         'brokenlinks', // 1.4
00052                         'cur', // 1.4
00053                         'ip_blocks_old', // Temporary in 1.6
00054                         'links', // 1.4
00055                         'linkscc', // 1.4
00056                         // 'math', // 1.18, but don't want to drop if math extension is enabled...
00057                         'old', // 1.4
00058                         'oldwatchlist', // pre 1.1?
00059                         'trackback', // 1.19
00060                         'user_rights', // 1.5
00061                         'validate', // 1.6
00062                 );
00063 
00064                 foreach( $ancientTables as $table ) {
00065                         if ( $db->tableExists( $table, __METHOD__ ) ) {
00066                                 $this->output( "Dropping table $table..." );
00067                                 $db->dropTable( $table, __METHOD__ );
00068                                 $this->output( "done.\n" );
00069                         }
00070                 }
00071 
00072                 $this->output( "Cleaning up text table\n" );
00073 
00074                 $oldIndexes = array(
00075                         'old_namespace',
00076                         'old_timestamp',
00077                         'name_title_timestamp',
00078                         'user_timestamp',
00079                         'usertext_timestamp',
00080                 );
00081                 foreach( $oldIndexes as $index ) {
00082                         if ( $db->indexExists( 'text', $index, __METHOD__ ) ) {
00083                                 $this->output( "Dropping index $index from the text table..." );
00084                                 $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index )
00085                                                 . " ON " . $db->tableName( 'text' ) );
00086                                 $this->output( "done.\n" );
00087                         }
00088                 }
00089 
00090                 $oldFields = array(
00091                         'old_namespace',
00092                         'old_title',
00093                         'old_comment',
00094                         'old_user',
00095                         'old_user_text',
00096                         'old_timestamp',
00097                         'old_minor_edit',
00098                         'inverse_timestamp',
00099                 );
00100                 foreach( $oldFields as $field ) {
00101                         if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) {
00102                                 $this->output( "Dropping the $field field from the text table..." );
00103                                 $db->query( "ALTER TABLE  " . $db->tableName( 'text' )
00104                                                 . " DROP COLUMN " . $db->addIdentifierQuotes( $field )  );
00105                                 $this->output( "done.\n" );
00106                         }
00107                 }
00108                 $this->output( "Done!\n" );
00109         }
00110 }
00111 
00112 $maintClass = "CleanupAncientTables";
00113 require_once( RUN_MAINTENANCE_IF_MAIN );