| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Watchlist; |
| 22 |
|
| 23 |
use InvalidArgumentException; |
| 24 |
use Job; |
| 25 |
use MediaWiki\Linker\LinkTarget; |
| 26 |
use MediaWiki\MediaWikiServices; |
| 27 |
use MediaWiki\Page\PageReference; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
class ActivityUpdateJob extends Job { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function __construct( $title, array $params ) { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
$params['namespace'] = $title->getNamespace(); |
| 51 |
$params['title'] = $title->getDBkey(); |
| 52 |
|
| 53 |
parent::__construct( 'activityUpdateJob', $params ); |
| 54 |
|
| 55 |
static $required = [ 'type', 'userid', 'notifTime', 'curTime' ]; |
| 56 |
$missing = implode( ', ', array_diff( $required, array_keys( $this->params ) ) ); |
| 57 |
if ( $missing != '' ) { |
| 58 |
throw new InvalidArgumentException( "Missing parameter(s) $missing" ); |
| 59 |
} |
| 60 |
|
| 61 |
$this->removeDuplicates = true; |
| 62 |
} |
| 63 |
|
| 64 |
public function run() { |
| 65 |
if ( $this->params['type'] === 'updateWatchlistNotification' ) { |
| 66 |
$this->updateWatchlistNotification(); |
| 67 |
} else { |
| 68 |
throw new InvalidArgumentException( "Invalid 'type' '{$this->params['type']}'." ); |
| 69 |
} |
| 70 |
|
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
protected function updateWatchlistNotification() { |
| 75 |
$casTimestamp = $this->params['notifTime'] ?? $this->params['curTime']; |
| 76 |
|
| 77 |
|
| 78 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
$casTimeCond = $dbw->expr( 'wl_notificationtimestamp', '<', $dbw->timestamp( $casTimestamp ) ); |
| 86 |
|
| 87 |
|
| 88 |
$wlId = $dbw->newSelectQueryBuilder() |
| 89 |
->select( 'wl_id' ) |
| 90 |
->from( 'watchlist' ) |
| 91 |
->where( [ |
| 92 |
'wl_user' => $this->params['userid'], |
| 93 |
'wl_namespace' => $this->title->getNamespace(), |
| 94 |
'wl_title' => $this->title->getDBkey(), |
| 95 |
$casTimeCond |
| 96 |
] )->caller( __METHOD__ )->fetchField(); |
| 97 |
|
| 98 |
if ( !$wlId ) { |
| 99 |
return; |
| 100 |
} |
| 101 |
$dbw->newUpdateQueryBuilder() |
| 102 |
->update( 'watchlist' ) |
| 103 |
->set( [ 'wl_notificationtimestamp' => $dbw->timestampOrNull( $this->params['notifTime'] ) ] ) |
| 104 |
->where( [ 'wl_id' => (int)$wlId, $casTimeCond ] ) |
| 105 |
->caller( __METHOD__ )->execute(); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
class_alias( ActivityUpdateJob::class, 'ActivityUpdateJob' ); |