4 * Support functions for cleaning up redundant text records
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 )" );
42 while( $row = $dbw->fetchObject( $res ) ) {
43 $old[] = $row->old_id;
47 # Inform the user of what we're going to do
48 $count = count( $old );
49 echo( "$count inactive items found.\n" );
51 # Delete as appropriate
52 if( $delete && $count ) {
53 echo( "Deleting..." );
54 $set = implode( ', ', $old );
55 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );