Update Post and Topic models 2

This commit is contained in:
Visman 2020-06-06 20:26:40 +07:00
parent 84fc2cf463
commit b4cc13266e
2 changed files with 13 additions and 12 deletions

View file

@ -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;
}
/**

View file

@ -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;
}
/**