3 * Cleans up old database tables, dropping old indexes and fields.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 require_once( dirname( __FILE__
) . '/Maintenance.php' );
26 class CleanupAncientTables
extends Maintenance
{
28 public function __construct() {
29 parent
::__construct();
30 $this->mDescription
= "Cleanup ancient tables and indexes";
31 $this->addOption( 'force', 'Actually run this script' );
34 public function execute() {
35 if( !$this->hasOption( 'force' ) ) {
36 $this->error( "This maintenance script will remove old columns and indexes.\n"
37 . "It is recommended to backup your database first, and ensure all your data has been migrated to newer tables\n"
38 . "If you want to continue, run this script again with the --force \n"
42 $db = wfGetDB( DB_MASTER
);
43 $ancientTables = array(
47 'ip_blocks_old', // Temporary in 1.6
50 // 'math', // 1.18, but don't want to drop if math extension is enabled...
52 'oldwatchlist', // pre 1.1?
58 foreach( $ancientTables as $table ) {
59 if ( $db->tableExists( $table, __METHOD__
) ) {
60 $this->output( "Dropping table $table..." );
61 $db->dropTable( $table, __METHOD__
);
62 $this->output( "done.\n" );
66 $this->output( "Cleaning up text table\n" );
71 'name_title_timestamp',
75 foreach( $oldIndexes as $index ) {
76 if ( $db->indexExists( 'text', $index, __METHOD__
) ) {
77 $this->output( "Dropping index $index from the text table..." );
78 $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index )
79 . " ON " . $db->tableName( 'text' ) );
80 $this->output( "done.\n" );
94 foreach( $oldFields as $field ) {
95 if ( $db->fieldExists( 'text', $field, __METHOD__
) ) {
96 $this->output( "Dropping the $field field from the text table..." );
97 $db->query( "ALTER TABLE " . $db->tableName( 'text' )
98 . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) );
99 $this->output( "done.\n" );
102 $this->output( "Done!\n" );
106 $maintClass = "CleanupAncientTables";
107 require_once( RUN_MAINTENANCE_IF_MAIN
);