]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/purgeOldText.inc
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / maintenance / purgeOldText.inc
1 <?php
2
3 /**
4  * Support functions for cleaning up redundant text records
5  *
6  * @addtogroup Maintenance
7  * @author Rob Church <robchur@gmail.com>
8  */
9
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         $old = array();
41         while( $row = $dbw->fetchObject( $res ) ) {
42                 $old[] = $row->old_id;
43         }
44         echo( "done.\n" );
45         
46         # Inform the user of what we're going to do
47         $count = count( $old );
48         echo( "$count inactive items found.\n" );
49         
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 )" );
55                 echo( "done.\n" );
56         }
57         
58         # Done
59         $dbw->commit();
60         
61 }
62
63 ?>