public function markRead($userId, $wikiId, $id = 0, $ts = 0)
 {
     $updateDBlist = array();
     // we will update database AFTER unlocking
     $wasUnread = false;
     // function returns True if in fact there was unread
     // notification
     $memcSync = $this->getCache($userId, $wikiId);
     do {
         $count = 0;
         //use to set priority of process
         if ($memcSync->lock()) {
             $data = $this->getData($memcSync, $userId, $wikiId);
             if ($id == 0 && !empty($data['relation'])) {
                 $ids = array_keys($data['relation']);
             } else {
                 $ids = array($id);
             }
             foreach ($ids as $value) {
                 if (!empty($data['relation'][$value])) {
                     if ($data['relation'][$value]['read'] == false) {
                         $wasUnread = true;
                         $data['relation'][$value]['read'] = true;
                         $updateDBlist[] = array('user_id' => $userId, 'wiki_id' => $wikiId, 'unique_id' => $value);
                     }
                 }
             }
         } else {
             $this->sleep($count);
         }
         $count++;
     } while (!isset($data) || !$this->setData($memcSync, $data));
     $memcSync->unlock();
     foreach ($updateDBlist as $value) {
         $this->getDB(true)->update('wall_notification', array('is_read' => 1), $value, __METHOD__);
     }
     if ($id === 0) {
         $user = User::newFromId($userId);
         if ($user instanceof User && (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups()))) {
             $wna = new WallNotificationsAdmin();
             $wasUnread = $wasUnread || $wna->hideAdminNotifications($wikiId, $userId);
         }
         $wno = new WallNotificationsOwner();
         $wasUnread = $wasUnread || $wno->removeAll($wikiId, $userId);
     }
     return $wasUnread;
 }
 public function markRead($userId, $wikiId, $id = 0)
 {
     $updateDBlist = [];
     // we will update database AFTER unlocking
     $wasUnread = false;
     // function returns True if in fact there was unread notification
     $memcSync = $this->getCache($userId, $wikiId);
     $memcSync->lockAndSetData(function () use($memcSync, $userId, $wikiId, $id, &$updateDBlist, &$wasUnread) {
         $data = $this->getData($memcSync, $userId, $wikiId);
         if ($id == 0 && !empty($data['relation'])) {
             $ids = array_keys($data['relation']);
         } else {
             $ids = [$id];
         }
         foreach ($ids as $value) {
             if (!empty($data['relation'][$value])) {
                 if ($data['relation'][$value]['read'] == false) {
                     $wasUnread = true;
                     $data['relation'][$value]['read'] = true;
                     $updateDBlist[] = ['user_id' => $userId, 'wiki_id' => $wikiId, 'unique_id' => $value];
                 }
             }
         }
         return $data;
     }, function () use($memcSync) {
         // Delete the cache if we were unable to update to force a rebuild
         $memcSync->delete();
     });
     $this->purgeCountsCache($userId);
     foreach ($updateDBlist as $value) {
         $this->getDB(true)->update('wall_notification', ['is_read' => 1], $value, __METHOD__);
     }
     if ($id === 0) {
         $user = $this->getUser($userId);
         if ($user instanceof User && (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups()))) {
             $wna = new WallNotificationsAdmin();
             $wasUnread = $wasUnread || $wna->hideAdminNotifications($wikiId, $userId);
         }
         $wno = new WallNotificationsOwner();
         $wasUnread = $wasUnread || $wno->removeAll($wikiId, $userId);
     }
     return $wasUnread;
 }