4 * Support functions for cleaning up redundant text records
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
11 function PurgeRedundantText( $delete = false ) {
13 # Data should come off the master, wrapped in a transaction
14 $dbw =& wfGetDB( DB_MASTER );
17 $tbl_arc = $dbw->tableName( 'archive' );
18 $tbl_rev = $dbw->tableName( 'revision' );
19 $tbl_txt = $dbw->tableName( 'text' );
21 # Get "active" text records from the revisions table
22 echo( "Searching for active text records in revisions table..." );
23 $res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" );
24 while( $row = $dbw->fetchObject( $res ) ) {
25 $cur[] = $row->rev_text_id;
29 # Get "active" text records from the archive table
30 echo( "Searching for active text records in archive table..." );
31 $res = $dbw->query( "SELECT DISTINCTROW ar_text_id FROM $tbl_arc" );
32 while( $row = $dbw->fetchObject( $res ) ) {
33 $cur[] = $row->ar_text_id;
37 # Get the IDs of all text records not in these sets
38 echo( "Searching for inactive text records..." );
39 $set = implode( ', ', $cur );
40 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
41 while( $row = $dbw->fetchObject( $res ) ) {
42 $old[] = $row->old_id;
46 # Inform the user of what we're going to do
47 $count = count( $old );
48 echo( "$count inactive items found.\n" );
50 # Delete as appropriate
51 if( $delete && $count ) {
52 echo( "Deleting..." );
53 $set = implode( ', ', $old );
54 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );