SpecialLinkSearch: clean up munged query variable handling
[mediawiki.git] / includes / jobqueue / jobs / RecentChangesUpdateJob.php
blobb54ecfdc164accb178e67f3c4e10060bf59bf475
1 <?php
2 /**
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
18 * @file
19 * @author Aaron Schulz
22 /**
23 * Job for pruning recent changes
25 * @ingroup JobQueue
26 * @since 1.25
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;
39 /**
40 * @return RecentChangesUpdateJob
42 final public static function newPurgeJob() {
43 return new self(
44 SpecialPage::getTitleFor( 'Recentchanges' ), array( 'type' => 'purge' )
48 public function run() {
49 if ( $this->params['type'] === 'purge' ) {
50 $this->purgeExpiredRows();
51 } else {
52 throw new Exception( "Invalid 'type' parameter '{$this->params['type']}'." );
55 return true;
58 protected function purgeExpiredRows() {
59 global $wgRCMaxAge;
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 );
69 do {
70 $rcIds = $dbw->selectFieldValues( 'recentchanges',
71 'rc_id',
72 array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
73 __METHOD__,
74 array( 'LIMIT' => 100 ) // avoid slave lag
76 if ( $rcIds ) {
77 $dbw->delete( 'recentchanges', array( 'rc_id' => $rcIds ), __METHOD__ );
79 // No need for this to be in a transaction.
80 $dbw->commit( __METHOD__, 'flush' );
81 } while ( $rcIds );
83 $dbw->unlock( $lockKey, __METHOD__ );