diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Comments/Comment.php | 16 | ||||
-rw-r--r-- | lib/private/Comments/Manager.php | 21 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php index 2b338efc75f..0128dc8defd 100644 --- a/lib/private/Comments/Comment.php +++ b/lib/private/Comments/Comment.php @@ -45,6 +45,7 @@ class Comment implements IComment { 'creationDT' => null, 'latestChildDT' => null, 'reactions' => null, + 'expire_date' => null, ]; /** @@ -447,6 +448,21 @@ class Comment implements IComment { } /** + * @inheritDoc + */ + public function setExpireDate(?\DateTime $dateTime): IComment { + $this->data['expire_date'] = $dateTime; + return $this; + } + + /** + * @inheritDoc + */ + public function getExpireDate(): ?\DateTime { + return $this->data['expire_date']; + } + + /** * 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 b7532222c33..f21f9ec76b2 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -107,6 +107,9 @@ class Manager implements ICommentsManager { if (!is_null($data['latest_child_timestamp'])) { $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); } + if (!is_null($data['expire_date'])) { + $data['expire_date'] = new \DateTime($data['expire_date']); + } $data['children_count'] = (int)$data['children_count']; $data['reference_id'] = $data['reference_id'] ?? null; if ($this->supportReactions()) { @@ -1203,6 +1206,7 @@ class Manager implements ICommentsManager { 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'), 'object_type' => $qb->createNamedParameter($comment->getObjectType()), 'object_id' => $qb->createNamedParameter($comment->getObjectId()), + 'expire_date' => $qb->createNamedParameter($comment->getExpireDate(), 'datetime'), ]; if ($tryWritingReferenceId) { @@ -1642,4 +1646,21 @@ class Manager implements ICommentsManager { $this->initialStateService->provideInitialState('comments', 'max-message-length', IComment::MAX_MESSAGE_LENGTH); Util::addScript('comments', 'comments-app'); } + + /** + * @inheritDoc + */ + public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool { + $qb = $this->dbConn->getQueryBuilder(); + $affectedRows = $qb->delete('comments') + ->where($qb->expr()->lt('expire_date', + $qb->createNamedParameter($this->timeFactory->getDateTime(), IQueryBuilder::PARAM_DATE))) + ->andWhere($qb->expr()->eq('object_type', $qb->createNamedParameter($objectType))) + ->andWhere($qb->expr()->eq('object_id', $qb->createNamedParameter($objectId))) + ->executeStatement(); + + $this->commentsCache = []; + + return $affectedRows > 0; + } } |