Add a few @since to mediawiki.api
[lhc/web/wiklou.git] / maintenance / purgeOldText.inc
1 <?php
2
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 */
25
26 function PurgeRedundantText( $delete = false ) {
27
28 # Data should come off the master, wrapped in a transaction
29 $dbw = wfGetDB( DB_MASTER );
30 $dbw->begin( __METHOD__ );
31
32 $tbl_arc = $dbw->tableName( 'archive' );
33 $tbl_rev = $dbw->tableName( 'revision' );
34 $tbl_txt = $dbw->tableName( 'text' );
35
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";
43
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";
52
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";
62
63 # Inform the user of what we're going to do
64 $count = count( $old );
65 echo "$count inactive items found.\n";
66
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 }
74
75 # Done
76 $dbw->commit( __METHOD__ );
77
78 }