00001 <?php 00002 00011 function PurgeRedundantText( $delete = false ) { 00012 00013 # Data should come off the master, wrapped in a transaction 00014 $dbw = wfGetDB( DB_MASTER ); 00015 $dbw->begin(); 00016 00017 $tbl_arc = $dbw->tableName( 'archive' ); 00018 $tbl_rev = $dbw->tableName( 'revision' ); 00019 $tbl_txt = $dbw->tableName( 'text' ); 00020 00021 # Get "active" text records from the revisions table 00022 echo( "Searching for active text records in revisions table..." ); 00023 $res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" ); 00024 while( $row = $dbw->fetchObject( $res ) ) { 00025 $cur[] = $row->rev_text_id; 00026 } 00027 echo( "done.\n" ); 00028 00029 # Get "active" text records from the archive table 00030 echo( "Searching for active text records in archive table..." ); 00031 $res = $dbw->query( "SELECT DISTINCTROW ar_text_id FROM $tbl_arc" ); 00032 while( $row = $dbw->fetchObject( $res ) ) { 00033 $cur[] = $row->ar_text_id; 00034 } 00035 echo( "done.\n" ); 00036 00037 # Get the IDs of all text records not in these sets 00038 echo( "Searching for inactive text records..." ); 00039 $set = implode( ', ', $cur ); 00040 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" ); 00041 $old = array(); 00042 while( $row = $dbw->fetchObject( $res ) ) { 00043 $old[] = $row->old_id; 00044 } 00045 echo( "done.\n" ); 00046 00047 # Inform the user of what we're going to do 00048 $count = count( $old ); 00049 echo( "$count inactive items found.\n" ); 00050 00051 # Delete as appropriate 00052 if( $delete && $count ) { 00053 echo( "Deleting..." ); 00054 $set = implode( ', ', $old ); 00055 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" ); 00056 echo( "done.\n" ); 00057 } 00058 00059 # Done 00060 $dbw->commit(); 00061 00062 }