3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @author Aaron Schulz
23 * Job for pruning recent changes
28 class RecentChangesUpdateJob
extends Job
{
29 function __construct( $title, $params ) {
30 parent
::__construct( 'recentChangesUpdate', $title, $params );
32 if ( !isset( $params['type'] ) ) {
33 throw new Exception( "Missing 'type' parameter." );
36 $this->removeDuplicates
= true;
40 * @return RecentChangesUpdateJob
42 final public static function newPurgeJob() {
44 SpecialPage
::getTitleFor( 'Recentchanges' ), array( 'type' => 'purge' )
48 public function run() {
49 if ( $this->params
['type'] === 'purge' ) {
50 $this->purgeExpiredRows();
52 throw new Exception( "Invalid 'type' parameter '{$this->params['type']}'." );
58 protected function purgeExpiredRows() {
61 $lockKey = wfWikiID() . ':recentchanges-prune';
63 $dbw = wfGetDB( DB_MASTER
);
64 if ( !$dbw->lock( $lockKey, __METHOD__
, 1 ) ) {
65 return; // already in progress
68 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
70 $rcIds = $dbw->selectFieldValues( 'recentchanges',
72 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
74 array( 'LIMIT' => 100 ) // avoid slave lag
77 $dbw->delete( 'recentchanges', array( 'rc_id' => $rcIds ), __METHOD__
);
79 // No need for this to be in a transaction.
80 $dbw->commit( __METHOD__
, 'flush' );
83 $dbw->unlock( $lockKey, __METHOD__
);