X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpurgeOldText.inc;h=111c786aa922f8ba0d454c7a2a8c1f26a9de748c;hb=da953994c843ba2782949d66c006631944ee5aaf;hp=c4732e97fa02201f171f76b32a2737e29d576119;hpb=fd340c67c4489db575f88a06d9b1c70bc689a45c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/purgeOldText.inc b/maintenance/purgeOldText.inc index c4732e97fa..111c786aa9 100644 --- a/maintenance/purgeOldText.inc +++ b/maintenance/purgeOldText.inc @@ -3,61 +3,76 @@ /** * Support functions for cleaning up redundant text records * - * @addtogroup Maintenance + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Maintenance * @author Rob Church */ function PurgeRedundantText( $delete = false ) { - + # Data should come off the master, wrapped in a transaction $dbw = wfGetDB( DB_MASTER ); - $dbw->begin(); - + $dbw->begin( __METHOD__ ); + $tbl_arc = $dbw->tableName( 'archive' ); $tbl_rev = $dbw->tableName( 'revision' ); $tbl_txt = $dbw->tableName( 'text' ); - + # Get "active" text records from the revisions table echo( "Searching for active text records in revisions table..." ); - $res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" ); - while( $row = $dbw->fetchObject( $res ) ) { + $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" ); + foreach ( $res as $row ) { $cur[] = $row->rev_text_id; } echo( "done.\n" ); - + # Get "active" text records from the archive table echo( "Searching for active text records in archive table..." ); - $res = $dbw->query( "SELECT DISTINCTROW ar_text_id FROM $tbl_arc" ); - while( $row = $dbw->fetchObject( $res ) ) { + $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" ); + $cur = array(); + foreach ( $res as $row ) { $cur[] = $row->ar_text_id; } echo( "done.\n" ); - + # Get the IDs of all text records not in these sets echo( "Searching for inactive text records..." ); $set = implode( ', ', $cur ); $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" ); $old = array(); - while( $row = $dbw->fetchObject( $res ) ) { + foreach ( $res as $row ) { $old[] = $row->old_id; } echo( "done.\n" ); - + # Inform the user of what we're going to do $count = count( $old ); echo( "$count inactive items found.\n" ); - + # Delete as appropriate - if( $delete && $count ) { + if ( $delete && $count ) { echo( "Deleting..." ); $set = implode( ', ', $old ); $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" ); echo( "done.\n" ); } - + # Done - $dbw->commit(); - -} + $dbw->commit( __METHOD__ ); -?> +}