private function disconnect($memberId, $esId) { $member = new Db\Member(); $member->loadBy('member_id', $memberId); if ($esId && $member->hasData()) { if ($member->getEsId() === $esId && $member->getStatus() == Db\Member::MEMBER_STATUS_ACTIVE) { $member->deactivate(array($memberId)); $op = new Db\Op(); $op->removeMember($esId, $memberId); } } return array('status' => 'success'); }
/** * @NoAdminRequired * @PublicPage */ public function poll($command, $args) { $response = new JSONResponse(); try { $esId = isset($args['es_id']) ? $args['es_id'] : null; $session = new Db\Session(); $session->load($esId); $memberId = isset($args['member_id']) ? $args['member_id'] : null; $member = new Db\Member(); $member->load($memberId); if (!$member->getIsGuest()) { \OCP\JSON::checkLoggedIn(); } try { new File($session->getFileId()); } catch (\Exception $e) { $this->logger->warning('Error. Session no longer exists. ' . $e->getMessage(), array('app' => $this->appName)); $ex = new BadRequestException(); $ex->setBody(implode(',', $this->request->getParams())); throw $ex; } switch ($command) { case 'sync_ops': $seqHead = (string) isset($args['seq_head']) ? $args['seq_head'] : null; if (!is_null($seqHead)) { $ops = isset($args['client_ops']) ? $args['client_ops'] : array(); $op = new Db\Op(); $currentHead = $op->getHeadSeq($esId); try { $member->updateActivity($memberId); } catch (\Exception $e) { //Db error. Not critical } $response->setData($session->syncOps($memberId, $currentHead, $seqHead, $ops)); $inactiveMembers = $member->updateByTimeout($esId); foreach ($inactiveMembers as $inactive) { $op->removeCursor($esId, $inactive); $op->removeMember($esId, $inactive); } } else { // Error - no seq_head passed throw new BadRequestException(); } break; default: $ex = new BadRequestException(); $ex->setBody(implode(',', $this->request->getParams())); throw $ex; } } catch (BadRequestException $e) { $response->setStatus(Http::STATUS_BAD_REQUEST); $response->setData(array('err' => 'bad request:[' . $e->getBody() . ']')); } return $response; }
/** * @NoAdminRequired */ public function poll($command, $args) { $response = new JSONResponse(); try { $esId = isset($args['es_id']) ? $args['es_id'] : null; $session = $this->loadSession($esId); $memberId = isset($args['member_id']) ? $args['member_id'] : null; $member = $this->loadMember($memberId); $this->validateSession($session); switch ($command) { case 'sync_ops': $seqHead = (string) isset($args['seq_head']) ? $args['seq_head'] : null; if (!is_null($seqHead)) { $ops = isset($args['client_ops']) ? $args['client_ops'] : []; $op = new Db\Op(); $currentHead = $op->getHeadSeq($esId); try { $member->updateActivity($memberId); } catch (\Exception $e) { //Db error. Not critical } $response->setData($session->syncOps($memberId, $currentHead, $seqHead, $ops)); $inactiveMembers = $member->updateByTimeout($esId); foreach ($inactiveMembers as $inactive) { $op->removeCursor($esId, $inactive); $op->removeMember($esId, $inactive); } } else { // Error - no seq_head passed throw new BadRequestException(); } break; default: $ex = new BadRequestException(); $ex->setBody(implode(',', $this->request->getParams())); throw $ex; } } catch (BadRequestException $e) { $response->setStatus(Http::STATUS_BAD_REQUEST); $response->setData(['err' => 'bad request:[' . $e->getBody() . ']']); } return $response; }