From a20e81f0f34389ef9c9e1a4df3ec2b514968b19f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 11 Mar 2020 12:11:01 +0100 Subject: [PATCH] Allow to set and get the reference id Signed-off-by: Joas Schilling --- lib/private/Comments/Comment.php | 31 +++++++++++++++++++++++++++++++ lib/private/Comments/Manager.php | 1 + lib/public/Comments/IComment.php | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 71687c7a609..3b4a523b884 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -42,6 +42,7 @@ class Comment implements IComment { 'actorId' => '', 'objectType' => '', 'objectId' => '', + 'referenceId' => null, 'creationDT' => null, 'latestChildDT' => null, ]; @@ -395,6 +396,36 @@ class Comment implements IComment { return $this; } + /** + * returns the reference id of the comment + * + * @return string|null + * @since 19.0.0 + */ + public function getReferenceId(): ?string { + return $this->data['referenceId']; + } + + /** + * sets (overwrites) the reference id of the comment + * + * @param string $referenceId e.g. sha256 hash sum + * @return IComment + * @since 19.0.0 + */ + public function setReferenceId(?string $referenceId): IComment { + if ($referenceId === null) { + $this->data['referenceId'] = $referenceId; + } else { + $referenceId = trim($referenceId); + if ($referenceId === '') { + throw new \InvalidArgumentException('Non empty string expected.'); + } + $this->data['referenceId'] = $referenceId; + } + return $this; + } + /** * sets the comment data based on an array with keys as taken from the * database. diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index f1c72243597..aad7cad0200 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -96,6 +96,7 @@ class Manager implements ICommentsManager { $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); } $data['children_count'] = (int)$data['children_count']; + $data['reference_id'] = $data['reference_id'] ?? null; return $data; } diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php index aac68a4036b..b98a015a30e 100644 --- a/lib/public/Comments/IComment.php +++ b/lib/public/Comments/IComment.php @@ -263,4 +263,21 @@ interface IComment { */ public function setObject($objectType, $objectId); + /** + * returns the reference id of the comment + * + * @return string|null + * @since 19.0.0 + */ + public function getReferenceId(): ?string; + + /** + * sets (overwrites) the reference id of the comment + * + * @param string|null $referenceId e.g. sha256 hash sum + * @return IComment + * @since 19.0.0 + */ + public function setReferenceId(?string $referenceId): IComment; + } -- 2.39.5