Explorar o código

Update Post and Topic models 2

Visman %!s(int64=5) %!d(string=hai) anos
pai
achega
b4cc13266e
Modificáronse 2 ficheiros con 13 adicións e 12 borrados
  1. 8 7
      app/Models/Post/Model.php
  2. 5 5
      app/Models/Topic/Model.php

+ 8 - 7
app/Models/Post/Model.php

@@ -3,8 +3,9 @@
 namespace ForkBB\Models\Post;
 
 use ForkBB\Models\DataModel;
-use ForkBB\Models\User\Model as User;
+use ForkBB\Models\Forum\Model as Forum;
 use ForkBB\Models\Topic\Model as Topic;
+use ForkBB\Models\User\Model as User;
 use RuntimeException;
 
 class Model extends DataModel
@@ -14,9 +15,9 @@ class Model extends DataModel
      *
      * @throws RuntimeException
      *
-     * @return Topic\Model
+     * @return Topic|null
      */
-    protected function getparent(): Topic
+    protected function getparent(): ?Topic
     {
         if ($this->topic_id < 1) {
             throw new RuntimeException('Parent is not defined');
@@ -24,11 +25,11 @@ class Model extends DataModel
 
         $topic = $this->c->topics->load($this->topic_id);
 
-        if (! $topic instanceof Topic || $topic->moved_to || ! $topic->parent) {
-            throw new RuntimeException("Parent({$this->topic_id}) is broken for post number {$this->id}");
+        if (! $topic instanceof Topic || $topic->moved_to || ! $topic->parent instanceof Forum) {
+            return null;
+        } else {
+            return $topic;
         }
-
-        return $topic;
     }
 
     /**

+ 5 - 5
app/Models/Topic/Model.php

@@ -14,9 +14,9 @@ class Model extends DataModel
      *
      * @throws RuntimeException
      *
-     * @return Forum\Model
+     * @return Forum|null
      */
-    protected function getparent(): Forum
+    protected function getparent(): ?Forum
     {
         if ($this->forum_id < 1) {
             throw new RuntimeException('Parent is not defined');
@@ -25,10 +25,10 @@ class Model extends DataModel
         $forum = $this->c->forums->get($this->forum_id);
 
         if (! $forum instanceof Forum || $forum->redirect_url) {
-            throw new RuntimeException("Parent({$this->forum_id}) is broken for topic number {$this->id}");
+            return null;
+        } else {
+            return $forum;
         }
-
-        return $forum;
     }
 
     /**