MediaWiki
REL1_19
|
00001 <?php 00002 00026 function PurgeRedundantText( $delete = false ) { 00027 00028 # Data should come off the master, wrapped in a transaction 00029 $dbw = wfGetDB( DB_MASTER ); 00030 $dbw->begin(); 00031 00032 $tbl_arc = $dbw->tableName( 'archive' ); 00033 $tbl_rev = $dbw->tableName( 'revision' ); 00034 $tbl_txt = $dbw->tableName( 'text' ); 00035 00036 # Get "active" text records from the revisions table 00037 echo( "Searching for active text records in revisions table..." ); 00038 $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" ); 00039 foreach ( $res as $row ) { 00040 $cur[] = $row->rev_text_id; 00041 } 00042 echo( "done.\n" ); 00043 00044 # Get "active" text records from the archive table 00045 echo( "Searching for active text records in archive table..." ); 00046 $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" ); 00047 $cur = array(); 00048 foreach ( $res as $row ) { 00049 $cur[] = $row->ar_text_id; 00050 } 00051 echo( "done.\n" ); 00052 00053 # Get the IDs of all text records not in these sets 00054 echo( "Searching for inactive text records..." ); 00055 $set = implode( ', ', $cur ); 00056 $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" ); 00057 $old = array(); 00058 foreach ( $res as $row ) { 00059 $old[] = $row->old_id; 00060 } 00061 echo( "done.\n" ); 00062 00063 # Inform the user of what we're going to do 00064 $count = count( $old ); 00065 echo( "$count inactive items found.\n" ); 00066 00067 # Delete as appropriate 00068 if ( $delete && $count ) { 00069 echo( "Deleting..." ); 00070 $set = implode( ', ', $old ); 00071 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" ); 00072 echo( "done.\n" ); 00073 } 00074 00075 # Done 00076 $dbw->commit(); 00077 00078 }