Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / includes / jobqueue / jobs / ActivityUpdateJob.php
blobf146e6e8bc7bf4a088f327bebdcb08d62e498592
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
20 * @ingroup JobQueue
23 /**
24 * Job for updating user activity like "last viewed" timestamps
26 * @ingroup JobQueue
27 * @since 1.26
29 class ActivityUpdateJob extends Job {
30 function __construct( Title $title, array $params ) {
31 parent::__construct( 'activityUpdateJob', $title, $params );
33 if ( !isset( $params['type'] ) ) {
34 throw new InvalidArgumentException( "Missing 'type' parameter." );
37 $this->removeDuplicates = true;
40 public function run() {
41 if ( $this->params['type'] === 'updateWatchlistNotification' ) {
42 $this->updateWatchlistNotification();
43 } else {
44 throw new Exception( "Invalid 'type' parameter '{$this->params['type']}'." );
47 return true;
50 protected function updateWatchlistNotification() {
51 $casTimestamp = ( $this->params['notifTime'] !== null )
52 ? $this->params['notifTime']
53 : $this->params['curTime'];
55 $dbw = wfGetDB( DB_MASTER );
56 $dbw->update( 'watchlist',
57 array(
58 'wl_notificationtimestamp' => $dbw->timestampOrNull( $this->params['notifTime'] )
60 array(
61 'wl_user' => $this->params['userid'],
62 'wl_namespace' => $this->title->getNamespace(),
63 'wl_title' => $this->title->getDBkey(),
64 // Add a "check and set" style comparison to handle conflicts.
65 // The inequality always avoids updates when the current value
66 // is already NULL per ANSI SQL. This is desired since NULL means
67 // that the user is "caught up" on edits already. When the field
68 // is non-NULL, make sure not to set it back in time or set it to
69 // NULL when newer revisions were in fact added to the page.
70 'wl_notificationtimestamp < ' . $dbw->addQuotes( $dbw->timestamp( $casTimestamp ) )
72 __METHOD__