*Add bitfields to various tables for revisiondelete
[mediawiki.git] / maintenance / purgeOldText.inc
blob8938cc0d854e2e51d6c5acf8ec4271ced9bb0a59
1 <?php
3 /**
4  * Support functions for cleaning up redundant text records
5  *
6  * @addtogroup Maintenance
7  * @author Rob Church <robchur@gmail.com>
8  */
10 function PurgeRedundantText( $delete = false ) {
11         
12         # Data should come off the master, wrapped in a transaction
13         $dbw = wfGetDB( DB_MASTER );
14         $dbw->begin();
15         
16         $tbl_arc = $dbw->tableName( 'archive' );
17         $tbl_rev = $dbw->tableName( 'revision' );
18         $tbl_txt = $dbw->tableName( 'text' );
19         
20         # Get "active" text records from the revisions table
21         echo( "Searching for active text records in revisions table..." );
22         $res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" );
23         while( $row = $dbw->fetchObject( $res ) ) {
24                 $cur[] = $row->rev_text_id;
25         }
26         echo( "done.\n" );
27         
28         # Get "active" text records from the archive table
29         echo( "Searching for active text records in archive table..." );
30         $res = $dbw->query( "SELECT DISTINCTROW ar_text_id FROM $tbl_arc" );
31         while( $row = $dbw->fetchObject( $res ) ) {
32                 $cur[] = $row->ar_text_id;
33         }
34         echo( "done.\n" );
35         
36         # Get the IDs of all text records not in these sets
37         echo( "Searching for inactive text records..." );
38         $set = implode( ', ', $cur );
39         $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
40         while( $row = $dbw->fetchObject( $res ) ) {
41                 $old[] = $row->old_id;
42         }
43         echo( "done.\n" );
44         
45         # Inform the user of what we're going to do
46         $count = count( $old );
47         echo( "$count inactive items found.\n" );
48         
49         # Delete as appropriate
50         if( $delete && $count ) {
51                 echo( "Deleting..." );
52                 $set = implode( ', ', $old );
53                 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
54                 echo( "done.\n" );
55         }
56         
57         # Done
58         $dbw->commit();
59