/** * Creates a new comment * * @param string $objectType e.g. "files" * @param string $objectId e.g. the file id * @param string $data JSON encoded string containing the properties of the tag to create * @param string $contentType content type of the data * @return IComment newly created comment * * @throws BadRequest if a field was missing * @throws UnsupportedMediaType if the content type is not supported */ private function createComment($objectType, $objectId, $data, $contentType = 'application/json') { if (explode(';', $contentType)[0] === 'application/json') { $data = json_decode($data, true); } else { throw new UnsupportedMediaType(); } $actorType = $data['actorType']; $actorId = null; if ($actorType === 'users') { $user = $this->userSession->getUser(); if (!is_null($user)) { $actorId = $user->getUID(); } } if (is_null($actorId)) { throw new BadRequest('Invalid actor "' . $actorType . '"'); } try { $comment = $this->commentsManager->create($actorType, $actorId, $objectType, $objectId); $comment->setMessage($data['message']); $comment->setVerb($data['verb']); $this->commentsManager->save($comment); return $comment; } catch (\InvalidArgumentException $e) { throw new BadRequest('Invalid input values', 0, $e); } }
/** * update the comment's message * * @param $propertyValue * @return bool */ public function updateComment($propertyValue) { try { $this->comment->setMessage($propertyValue); $this->commentsManager->save($this->comment); return true; } catch (\Exception $e) { $this->logger->logException($e, ['app' => 'dav/comments']); return false; } }
/** * update the comment's message * * @param $propertyValue * @return bool * @throws BadRequest * @throws Forbidden */ public function updateComment($propertyValue) { $this->checkWriteAccessOnComment(); try { $this->comment->setMessage($propertyValue); $this->commentsManager->save($this->comment); return true; } catch (\Exception $e) { $this->logger->logException($e, ['app' => 'dav/comments']); if ($e instanceof MessageTooLongException) { $msg = 'Message exceeds allowed character limit of '; throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); } throw $e; } }