예제 #1
0
 public static function Set($userId, $params)
 {
     $userId = intval($userId);
     if ($userId <= 0) {
         return false;
     }
     if (isset($params['STATUS'])) {
         $params['IDLE'] = null;
     }
     $needToUpdate = false;
     $params = self::PrepereFields($params);
     $res = IM\StatusTable::getById($userId);
     if ($status = $res->fetch()) {
         foreach ($params as $key => $value) {
             $oldValue = is_object($status[$key]) ? $status[$key]->toString() : $status[$key];
             $newValue = is_object($value) ? $value->toString() : $value;
             if ($oldValue != $newValue) {
                 $status[$key] = $value;
                 $needToUpdate = true;
             }
         }
         if ($needToUpdate) {
             IM\StatusTable::update($userId, $params);
         }
     } else {
         $params['USER_ID'] = $userId;
         IM\StatusTable::add($params);
         $needToUpdate = true;
         $status = $params;
     }
     if ($needToUpdate && self::Enable()) {
         CPullStack::AddShared(array('module_id' => 'online', 'command' => 'user_status', 'params' => self::PrepereToPush($status)));
     }
     return true;
 }
예제 #2
0
 public function handleStatusBindOperation($event, $nodeFrom, $nodeTo)
 {
     if (isset($event["guid"])) {
         $userId = \Bitrix\Replica\Client\User::getId($event["guid"]);
         if ($userId > 0) {
             \Bitrix\Replica\Mapper::getInstance()->add("b_im_status.USER_ID", $userId, $nodeFrom, $event["guid"]);
             $res = \Bitrix\Im\StatusTable::getById($userId);
             if ($res->fetch()) {
                 //Insert operation
                 \Bitrix\Replica\Db\Operation::writeInsert("b_im_status", $this->getPrimary(), array("USER_ID" => $userId));
             }
         }
     }
 }
예제 #3
0
 /**
  * Registers b_im_status record in the replication map
  * and sends the record back as an update operation.
  *
  * @param array $event Event made by OnAfterRecentAdd method.
  * @param string $nodeFrom Source database.
  * @param string $nodeTo Target database.
  *
  * @return void
  * @see \Bitrix\Im\Replica\StatusHandler::OnAfterRecentAdd
  */
 public function handleStatusRebindOperation($event, $nodeFrom, $nodeTo)
 {
     if (!isset($event["guid"])) {
         return;
     }
     list($userGuid, ) = explode('@', $event["guid"]);
     $userId = \Bitrix\Replica\Client\User::getLocalUserId($userGuid);
     if (!$userId) {
         return;
     }
     \Bitrix\Replica\Mapper::getInstance()->add("b_im_status.USER_ID", $userId, $nodeFrom, $event["guid"]);
     $res = \Bitrix\Im\StatusTable::getById($userId);
     if ($res->fetch()) {
         //Update operation
         \Bitrix\Replica\Db\Operation::writeUpdate("b_im_status", $this->getPrimary(), array("USER_ID" => $userId));
     }
 }