a43f751 removed the usage of $wgMiserMode
[mediawiki.git] / maintenance / purgeOldText.inc
blob111c786aa922f8ba0d454c7a2a8c1f26a9de748c
1 <?php
3 /**
4  * Support functions for cleaning up redundant text records
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  * http://www.gnu.org/copyleft/gpl.html
20  *
21  * @file
22  * @ingroup Maintenance
23  * @author Rob Church <robchur@gmail.com>
24  */
26 function PurgeRedundantText( $delete = false ) {
28         # Data should come off the master, wrapped in a transaction
29         $dbw = wfGetDB( DB_MASTER );
30         $dbw->begin( __METHOD__ );
32         $tbl_arc = $dbw->tableName( 'archive' );
33         $tbl_rev = $dbw->tableName( 'revision' );
34         $tbl_txt = $dbw->tableName( 'text' );
36         # Get "active" text records from the revisions table
37         echo( "Searching for active text records in revisions table..." );
38         $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
39         foreach ( $res as $row ) {
40                 $cur[] = $row->rev_text_id;
41         }
42         echo( "done.\n" );
44         # Get "active" text records from the archive table
45         echo( "Searching for active text records in archive table..." );
46         $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
47         $cur = array();
48         foreach ( $res as $row ) {
49                 $cur[] = $row->ar_text_id;
50         }
51         echo( "done.\n" );
53         # Get the IDs of all text records not in these sets
54         echo( "Searching for inactive text records..." );
55         $set = implode( ', ', $cur );
56         $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
57         $old = array();
58         foreach ( $res as $row ) {
59                 $old[] = $row->old_id;
60         }
61         echo( "done.\n" );
63         # Inform the user of what we're going to do
64         $count = count( $old );
65         echo( "$count inactive items found.\n" );
67         # Delete as appropriate
68         if ( $delete && $count ) {
69                 echo( "Deleting..." );
70                 $set = implode( ', ', $old );
71                 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
72                 echo( "done.\n" );
73         }
75         # Done
76         $dbw->commit( __METHOD__ );