Tweak message from r88475
[mediawiki.git] / maintenance / purgeOldText.inc
blob743b3fc7fd3d42bb69bc7e32bf44d72881eee78b
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();
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         foreach ( $res as $row ) {
48                 $cur[] = $row->ar_text_id;
49         }
50         echo( "done.\n" );
52         # Get the IDs of all text records not in these sets
53         echo( "Searching for inactive text records..." );
54         $set = implode( ', ', $cur );
55         $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
56         $old = array();
57         foreach ( $res as $row ) {
58                 $old[] = $row->old_id;
59         }
60         echo( "done.\n" );
62         # Inform the user of what we're going to do
63         $count = count( $old );
64         echo( "$count inactive items found.\n" );
66         # Delete as appropriate
67         if ( $delete && $count ) {
68                 echo( "Deleting..." );
69                 $set = implode( ', ', $old );
70                 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
71                 echo( "done.\n" );
72         }
74         # Done
75         $dbw->commit();