]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/purgeOldText.inc
MediaWiki 1.5.8 (initial commit)
[autoinstalls/mediawiki.git] / maintenance / purgeOldText.inc
1 <?php
2
3 /**
4  * Support functions for cleaning up redundant text records
5  *
6  * @package MediaWiki
7  * @subpackage 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         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 ?>