aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Comments
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-06-20 12:14:57 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-06-20 12:14:57 +0200
commit7aa97dcc2369c421b6d32ad32c33d357e582af4a (patch)
tree74629fc9eb70d832b0dce473626a93e6c04b1587 /lib/private/Comments
parent77355a8a79898a03d4f45e853e3d99c9a633509b (diff)
downloadnextcloud-server-7aa97dcc2369c421b6d32ad32c33d357e582af4a.tar.gz
nextcloud-server-7aa97dcc2369c421b6d32ad32c33d357e582af4a.zip
Throw if creation date is read before inserting into database
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Comments')
-rw-r--r--lib/private/Comments/Comment.php6
-rw-r--r--lib/private/Comments/Manager.php4
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php
index af2c73c770b..35e88c74438 100644
--- a/lib/private/Comments/Comment.php
+++ b/lib/private/Comments/Comment.php
@@ -304,9 +304,13 @@ class Comment implements IComment {
*
* If not explicitly set, it shall default to the time of initialization.
* @since 9.0.0
+ * @throw \LogicException if creation date time is not set yet
*/
public function getCreationDateTime(): \DateTime {
- return $this->data['creationDT'] ?? new \DateTime();
+ if (!isset($this->data['creationDT'])) {
+ throw new \LogicException('Cannot get creation date before setting one or writting to database');
+ }
+ return $this->data['creationDT'];
}
/**
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index ee5b59c98ec..af4fda277d6 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -154,7 +154,9 @@ class Manager implements ICommentsManager {
$comment->setLatestChildDateTime(null);
}
- if (is_null($comment->getCreationDateTime())) {
+ try {
+ $comment->getCreationDateTime();
+ } catch(\LogicException $e) {
$comment->setCreationDateTime(new \DateTime());
}