Merge "Add passing ''italic'''s case to 'Unclosed and unmatched quotes' test"
[lhc/web/wiklou.git] / maintenance / cleanupAncientTables.php
1 <?php
2 /**
3 * Cleans up old database tables, dropping old indexes and fields.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25
26 class CleanupAncientTables extends Maintenance {
27
28 public function __construct() {
29 parent::__construct();
30 $this->mDescription = "Cleanup ancient tables and indexes";
31 $this->addOption( 'force', 'Actually run this script' );
32 }
33
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"
39 );
40 }
41
42 $db = wfGetDB( DB_MASTER );
43 $ancientTables = array(
44 'blobs', // 1.4
45 'brokenlinks', // 1.4
46 'cur', // 1.4
47 'ip_blocks_old', // Temporary in 1.6
48 'links', // 1.4
49 'linkscc', // 1.4
50 // 'math', // 1.18, but don't want to drop if math extension is enabled...
51 'old', // 1.4
52 'oldwatchlist', // pre 1.1?
53 'trackback', // 1.19
54 'user_rights', // 1.5
55 'validate', // 1.6
56 );
57
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" );
63 }
64 }
65
66 $this->output( "Cleaning up text table\n" );
67
68 $oldIndexes = array(
69 'old_namespace',
70 'old_timestamp',
71 'name_title_timestamp',
72 'user_timestamp',
73 'usertext_timestamp',
74 );
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" );
81 }
82 }
83
84 $oldFields = array(
85 'old_namespace',
86 'old_title',
87 'old_comment',
88 'old_user',
89 'old_user_text',
90 'old_timestamp',
91 'old_minor_edit',
92 'inverse_timestamp',
93 );
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" );
100 }
101 }
102 $this->output( "Done!\n" );
103 }
104 }
105
106 $maintClass = "CleanupAncientTables";
107 require_once( RUN_MAINTENANCE_IF_MAIN );