Merge "Do not require iiurlwidth when getting thumbnails."
[mediawiki.git] / maintenance / purgeOldText.inc
blob5093cb391b7c9a3da61522f6e426675e70cba3f1
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 /**
27  * @param bool $delete
28  */
29 function PurgeRedundantText( $delete = false ) {
31         # Data should come off the master, wrapped in a transaction
32         $dbw = wfGetDB( DB_MASTER );
33         $dbw->begin( __METHOD__ );
35         $tbl_arc = $dbw->tableName( 'archive' );
36         $tbl_rev = $dbw->tableName( 'revision' );
37         $tbl_txt = $dbw->tableName( 'text' );
39         # Get "active" text records from the revisions table
40         echo "Searching for active text records in revisions table...";
41         $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
42         foreach ( $res as $row ) {
43                 $cur[] = $row->rev_text_id;
44         }
45         echo "done.\n";
47         # Get "active" text records from the archive table
48         echo "Searching for active text records in archive table...";
49         $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
50         $cur = array();
51         foreach ( $res as $row ) {
52                 $cur[] = $row->ar_text_id;
53         }
54         echo "done.\n";
56         # Get the IDs of all text records not in these sets
57         echo "Searching for inactive text records...";
58         $set = implode( ', ', $cur );
59         $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
60         $old = array();
61         foreach ( $res as $row ) {
62                 $old[] = $row->old_id;
63         }
64         echo "done.\n";
66         # Inform the user of what we're going to do
67         $count = count( $old );
68         echo "$count inactive items found.\n";
70         # Delete as appropriate
71         if ( $delete && $count ) {
72                 echo "Deleting...";
73                 $set = implode( ', ', $old );
74                 $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
75                 echo "done.\n";
76         }
78         # Done
79         $dbw->commit( __METHOD__ );