aboutsummaryrefslogtreecommitdiffstats
path: root/includes/WatchedItem.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/WatchedItem.php')
-rw-r--r--includes/WatchedItem.php30
1 files changed, 19 insertions, 11 deletions
diff --git a/includes/WatchedItem.php b/includes/WatchedItem.php
index 5b4a4fcfe1ad..0495536a2641 100644
--- a/includes/WatchedItem.php
+++ b/includes/WatchedItem.php
@@ -179,23 +179,31 @@ class WatchedItem {
*/
public static function batchAddWatch( array $items ) {
// wfDeprecated( __METHOD__, '1.27' );
- $userTargetCombinations = [];
+ if ( !$items ) {
+ return false;
+ }
+
+ $targets = [];
+ $users = [];
/** @var WatchedItem $watchedItem */
foreach ( $items as $watchedItem ) {
- if ( $watchedItem->checkRights && !$watchedItem->getUser()->isAllowed( 'editmywatchlist' ) ) {
+ $user = $watchedItem->getUser();
+ if ( $watchedItem->checkRights && !$user->isAllowed( 'editmywatchlist' ) ) {
continue;
}
- $userTargetCombinations[] = [
- $watchedItem->getUser(),
- $watchedItem->getTitle()->getSubjectPage()
- ];
- $userTargetCombinations[] = [
- $watchedItem->getUser(),
- $watchedItem->getTitle()->getTalkPage()
- ];
+ $userId = $user->getId();
+ $users[$userId] = $user;
+ $targets[$userId][] = $watchedItem->getTitle()->getSubjectPage();
+ $targets[$userId][] = $watchedItem->getTitle()->getTalkPage();
}
+
$store = WatchedItemStore::getDefaultInstance();
- return $store->addWatchBatch( $userTargetCombinations );
+ $success = true;
+ foreach ( $users as $userId => $user ) {
+ $success &= $store->addWatchBatchForUser( $user, $targets[$userId] );
+ }
+
+ return $success;
}
/**