1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?php
/**
* Cleans up old database tables, dropping old indexes and fields.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Maintenance
*/
require_once __DIR__ . '/Maintenance.php';
/**
* Maintenance script to cleans up old database tables, dropping old indexes
* and fields.
*
* @ingroup Maintenance
*/
class CleanupAncientTables extends Maintenance {
public function __construct() {
parent::__construct();
$this->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\n"
. "been migrated to newer tables. If you want to continue, run this script again\n"
. "with --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;
|