Prechádzať zdrojové kódy

Update Post and Topic models

Visman 5 rokov pred
rodič
commit
84fc2cf463
2 zmenil súbory, kde vykonal 14 pridanie a 2 odobranie
  1. 7 1
      app/Models/Post/Model.php
  2. 7 1
      app/Models/Topic/Model.php

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

@@ -22,7 +22,13 @@ class Model extends DataModel
             throw new RuntimeException('Parent is not defined');
         }
 
-        return $this->c->topics->load($this->topic_id);
+        $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}");
+        }
+
+        return $topic;
     }
 
     /**

+ 7 - 1
app/Models/Topic/Model.php

@@ -22,7 +22,13 @@ class Model extends DataModel
             throw new RuntimeException('Parent is not defined');
         }
 
-        return $this->c->forums->get($this->forum_id);
+        $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 $forum;
     }
 
     /**