private function saveBadges()
 {
     wfProfileIn(__METHOD__);
     if (count($this->mNewBadges) > 0) {
         $dbw = wfGetDB(DB_MASTER);
         // Doing replace instead of insert prevents dupes in case of slave lag or other errors
         foreach ($this->mNewBadges as $key => $val) {
             $this->mNewBadges[$key]['user_id'] = $this->mUser->getId();
             $dbw->replace('ach_user_badges', null, $this->mNewBadges[$key], __METHOD__);
         }
         $dbw->commit();
         //notify the user only if he wants to be notified
         if (!$this->mUser->getGlobalPreference('hidepersonalachievements')) {
             $_SESSION['achievementsNewBadges'] = true;
             $achNotificationService = new AchNotificationService($this->mUser);
             $achNotificationService->addBadges($this->mNewBadges);
             // Hook to give backend stuff something to latch onto at award-time rather than notifcation-time.
             // NOTE: This has the limitation that it is only called for a max of one badge per page.
             // If the user earned multiple badges on the same page, the hook will only be run on the badge which getBadgeToNotify() determines is more important.
             global $wgWikiaForceAIAFdebug;
             Wikia::log(__METHOD__, "", "Saving a new badge. About to run hook if badge can be re-loaded.", $wgWikiaForceAIAFdebug);
             $badge = $achNotificationService->getBadge(false);
             if ($badge !== null) {
                 wfRunHooks('AchievementEarned', array($this->mUser, $badge));
             }
         }
         //touch user when badges are given
         $this->mUser->invalidateCache();
         //purge the user page to update counters/ranking/badges/score, FB#2872
         $this->mUser->getUserPage()->purgeSquid();
         //run a hook to let other extensions know when Achievements-related cache should be purged
         wfRunHooks('AchievementsInvalidateCache', array($this->mUser));
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * Save user groups changes in the database.
  *
  * @param User|UserRightsProxy $user
  * @param array $add Array of groups to add
  * @param array $remove Array of groups to remove
  * @param string $reason Reason for group change
  * @return array Tuple of added, then removed groups
  */
 function doSaveUserGroups($user, $add, $remove, $reason = '')
 {
     global $wgAuth;
     // Validate input set...
     $isself = $user->getName() == $this->getUser()->getName();
     $groups = $user->getGroups();
     $changeable = $this->changeableGroups();
     $addable = array_merge($changeable['add'], $isself ? $changeable['add-self'] : array());
     $removable = array_merge($changeable['remove'], $isself ? $changeable['remove-self'] : array());
     $remove = array_unique(array_intersect((array) $remove, $removable, $groups));
     $add = array_unique(array_diff(array_intersect((array) $add, $addable), $groups));
     $oldGroups = $user->getGroups();
     $newGroups = $oldGroups;
     // Remove then add groups
     if ($remove) {
         foreach ($remove as $index => $group) {
             if (!$user->removeGroup($group)) {
                 unset($remove[$index]);
             }
         }
         $newGroups = array_diff($newGroups, $remove);
     }
     if ($add) {
         foreach ($add as $index => $group) {
             if (!$user->addGroup($group)) {
                 unset($add[$index]);
             }
         }
         $newGroups = array_merge($newGroups, $add);
     }
     $newGroups = array_unique($newGroups);
     // Ensure that caches are cleared
     $user->invalidateCache();
     // update groups in external authentication database
     Hooks::run('UserGroupsChanged', array($user, $add, $remove, $this->getUser()));
     $wgAuth->updateExternalDBGroups($user, $add, $remove);
     wfDebug('oldGroups: ' . print_r($oldGroups, true) . "\n");
     wfDebug('newGroups: ' . print_r($newGroups, true) . "\n");
     // Deprecated in favor of UserGroupsChanged hook
     Hooks::run('UserRights', array(&$user, $add, $remove), '1.26');
     if ($newGroups != $oldGroups) {
         $this->addLogEntry($user, $oldGroups, $newGroups, $reason);
     }
     return array($add, $remove);
 }
Example #3
0
 /**
  * Recalculates the number of notifications that a user has.
  * @param $dbSource int use master or slave database to pull count
  */
 public function resetNotificationCount($dbSource = DB_SLAVE)
 {
     $this->getNotificationCount(false, $dbSource);
     $this->mUser->invalidateCache();
 }