]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/purgeOldText.inc
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / maintenance / purgeOldText.inc
1 <?php
2
3 /**
4  * Support functions for cleaning up redundant text records
5  *
6  * @file
7  * @ingroup Maintenance
8  * @author Rob Church <robchur@gmail.com>
9  */
10
11 function PurgeRedundantText( $delete = false ) {
12         
13         # Data should come off the master, wrapped in a transaction
14         $dbw = wfGetDB( DB_MASTER );
15         $dbw->begin();
16         
17         $tbl_arc = $dbw->tableName( 'archive' );
18         $tbl_rev = $dbw->tableName( 'revision' );
19         $tbl_txt = $dbw->tableName( 'text' );
20         
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;
26         }
27         echo( "done.\n" );
28         
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;
34         }
35         echo( "done.\n" );
36         
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 )" );
41         $old = array();
42         while( $row = $dbw->fetchObject( $res ) ) {
43                 $old[] = $row->old_id;
44         }
45         echo( "done.\n" );
46         
47         # Inform the user of what we're going to do
48         $count = count( $old );
49         echo( "$count inactive items found.\n" );
50         
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 )" );
56                 echo( "done.\n" );
57         }
58         
59         # Done
60         $dbw->commit();
61         
62 }