From 193e8a750e6499dc8f1278a248b7d355262a2d9b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 26 Jun 2019 10:11:46 +0200 Subject: [PATCH] Allow apps to store longer messages in the comments API Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 7 ++++--- lib/public/Comments/IComment.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 76c6e1d1f6..c7cafa0524 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -188,17 +188,18 @@ class Comment implements IComment { * sets the message of the comment and returns itself * * @param string $message + * @param int $maxLength * @return IComment * @throws MessageTooLongException * @since 9.0.0 */ - public function setMessage($message) { + public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH) { if(!is_string($message)) { throw new \InvalidArgumentException('String expected.'); } $message = trim($message); - if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { - throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); + if ($maxLength && mb_strlen($message, 'UTF-8') > $maxLength) { + throw new MessageTooLongException('Comment message must not exceed ' . $maxLength. ' characters'); } $this->data['message'] = $message; return $this; diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index e364d42fe8..c7c846bbe9 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -127,11 +127,12 @@ interface IComment { * MessageTooLongException shall be thrown. * * @param string $message + * @param int $maxLength * @return IComment * @throws MessageTooLongException - * @since 9.0.0 + * @since 9.0.0 - $maxLength added in 16.0.2 */ - public function setMessage($message); + public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH); /** * returns an array containing mentions that are included in the comment