Browse Source
Throw if creation date is read before inserting into database
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/35424/head
Côme Chilliet
2 years ago
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
2 changed files with
8 additions and
2 deletions
-
lib/private/Comments/Comment.php
-
lib/private/Comments/Manager.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']; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
@ -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()); |
|
|
|
} |
|
|
|
|
|
|
|
|