]> source.dussan.org Git - nextcloud-server.git/commitdiff
Throw if creation date is read before inserting into database 35424/head
authorCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 20 Jun 2023 10:14:57 +0000 (12:14 +0200)
committerCôme Chilliet <come.chilliet@nextcloud.com>
Tue, 20 Jun 2023 10:14:57 +0000 (12:14 +0200)
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
lib/private/Comments/Comment.php
lib/private/Comments/Manager.php

index af2c73c770bf554f614b4c61a4a28adaefe4ad9a..35e88c74438a31b0ab8ad07bfd4c1abcfc05064b 100644 (file)
@@ -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'];
        }
 
        /**
index ee5b59c98ec683e867ac205033c123638138b4ac..af4fda277d6cf7e237e5f401b8901caf2c5867e7 100644 (file)
@@ -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());
                }