Example #1
0
 /**
  * @NoAdminRequired
  * @PublicPage
  * @param int $memberId
  * @param string $name
  */
 public function rename($memberId, $name)
 {
     $member = new Db\Member();
     $member->load($memberId);
     if ($member->getEsId() && $member->getStatus() == Db\Member::MEMBER_STATUS_ACTIVE && $member->getIsGuest()) {
         $guestMark = Db\Member::getGuestPostfix();
         if (substr($name, -strlen($guestMark)) !== $guestMark) {
             $name = $name . ' ' . $guestMark;
         }
         $op = new Db\Op();
         $op->changeNick($member->getEsId(), $memberId, $name);
     }
     return array('status' => 'success');
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 public function syncOps($memberId, $currentHead, $clientHead, $clientOps)
 {
     $hasOps = count($clientOps) > 0;
     $op = new \OCA\Documents\Db\Op();
     // TODO handle the case ($currentHead == "") && ($seqHead != "")
     if ($clientHead == $currentHead) {
         // matching heads
         if ($hasOps) {
             // incoming ops without conflict
             // Add incoming ops, respond with a new head
             $newHead = \OCA\Documents\Db\Op::addOpsArray($this->getEsId(), $memberId, $clientOps);
             $result = array('result' => 'added', 'head_seq' => $newHead ? $newHead : $currentHead);
         } else {
             // no incoming ops (just checking for new ops...)
             $result = array('result' => 'new_ops', 'ops' => array(), 'head_seq' => $currentHead);
         }
     } else {
         // HEADs do not match
         $result = array('result' => $hasOps ? 'conflict' : 'new_ops', 'ops' => $op->getOpsAfterJson($this->getEsId(), $clientHead), 'head_seq' => $currentHead);
     }
     return $result;
 }
 /**
  * @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;
 }