4 * Support functions for cleaning up redundant text records
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.
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.
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
22 * @ingroup Maintenance
23 * @author Rob Church <robchur@gmail.com>
26 function PurgeRedundantText( $delete = false ) {
28 # Data should come off the master, wrapped in a transaction
29 $dbw = wfGetDB( DB_MASTER );
30 $dbw->begin( __METHOD__ );
32 $tbl_arc = $dbw->tableName( 'archive' );
33 $tbl_rev = $dbw->tableName( 'revision' );
34 $tbl_txt = $dbw->tableName( 'text' );
36 # Get "active" text records from the revisions table
37 echo( "Searching for active text records in revisions table..." );
38 $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
39 foreach ( $res as $row ) {
40 $cur[] = $row->rev_text_id;
44 # Get "active" text records from the archive table
45 echo( "Searching for active text records in archive table..." );
46 $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
48 foreach ( $res as $row ) {
49 $cur[] = $row->ar_text_id;
53 # Get the IDs of all text records not in these sets
54 echo( "Searching for inactive text records..." );
55 $set = implode( ', ', $cur );
56 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
58 foreach ( $res as $row ) {
59 $old[] = $row->old_id;
63 # Inform the user of what we're going to do
64 $count = count( $old );
65 echo( "$count inactive items found.\n" );
67 # Delete as appropriate
68 if ( $delete && $count ) {
69 echo( "Deleting..." );
70 $set = implode( ', ', $old );
71 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
76 $dbw->commit( __METHOD__ );