Index: trunk/phase3/maintenance/cleanupAncientTables.php |
— | — | @@ -0,0 +1,107 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Cleans up old database tables, dropping old indexes and fields. |
| 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 | + */ |
| 24 | + |
| 25 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 26 | + |
| 27 | +class CleanupAncientTables extends Maintenance { |
| 28 | + |
| 29 | + public function __construct() { |
| 30 | + parent::__construct(); |
| 31 | + $this->mDescription = "Cleanup ancient tables and indexes"; |
| 32 | + $this->addOption( 'force', 'Actually run this script' ); |
| 33 | + } |
| 34 | + |
| 35 | + public function execute() { |
| 36 | + if( !$this->hasOption( 'force' ) ) { |
| 37 | + $this->error( "This maintenance script will remove old columns and indexes.\n" |
| 38 | + . "It is recommended to backup your database first, and ensure all your data has been migrated to newer tables\n" |
| 39 | + . "If you want to continue, run this script again with the --force \n" |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + $db = wfGetDB( DB_MASTER ); |
| 44 | + $ancientTables = array( |
| 45 | + 'blobs', // 1.4 |
| 46 | + 'brokenlinks', // 1.4 |
| 47 | + 'cur', // 1.4 |
| 48 | + 'ip_blocks_old', // Temporary in 1.6 |
| 49 | + 'links', // 1.4 |
| 50 | + 'linkscc', // 1.4 |
| 51 | + // 'math', // 1.18, but don't want to drop if math extension is enabled... |
| 52 | + 'old', // 1.4 |
| 53 | + 'oldwatchlist', // pre 1.1? |
| 54 | + 'trackback', // 1.19 |
| 55 | + 'user_rights', // 1.5 |
| 56 | + 'validate', // 1.6 |
| 57 | + ); |
| 58 | + |
| 59 | + foreach( $ancientTables as $table ) { |
| 60 | + if ( $db->tableExists( $table, __METHOD__ ) ) { |
| 61 | + $this->output( "Dropping table $table..." ); |
| 62 | + $db->dropTable( $table, __METHOD__ ); |
| 63 | + $this->output( "done.\n" ); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + $this->output( "Cleaning up text table\n" ); |
| 68 | + |
| 69 | + $oldIndexes = array( |
| 70 | + 'old_namespace', |
| 71 | + 'old_timestamp', |
| 72 | + 'name_title_timestamp', |
| 73 | + 'user_timestamp', |
| 74 | + 'usertext_timestamp', |
| 75 | + ); |
| 76 | + foreach( $oldIndexes as $index ) { |
| 77 | + if ( $db->indexExists( 'text', $index, __METHOD__ ) ) { |
| 78 | + $this->output( "Dropping index $index from the text table..." ); |
| 79 | + $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index ) |
| 80 | + . " ON " . $db->tableName( 'text' ) ); |
| 81 | + $this->output( "done.\n" ); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + $oldFields = array( |
| 86 | + 'old_namespace', |
| 87 | + 'old_title', |
| 88 | + 'old_comment', |
| 89 | + 'old_user', |
| 90 | + 'old_user_text', |
| 91 | + 'old_timestamp', |
| 92 | + 'old_minor_edit', |
| 93 | + 'inverse_timestamp', |
| 94 | + ); |
| 95 | + foreach( $oldFields as $field ) { |
| 96 | + if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) { |
| 97 | + $this->output( "Dropping the $field field from the text table..." ); |
| 98 | + $db->query( "ALTER TABLE " . $db->tableName( 'text' ) |
| 99 | + . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) ); |
| 100 | + $this->output( "done.\n" ); |
| 101 | + } |
| 102 | + } |
| 103 | + $this->output( "Done!\n" ); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +$maintClass = "CleanupAncientTables"; |
| 108 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/cleanupAncientTables.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 109 | + native |