1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 08:24:28 +02:00

Only get posts with registered types.

This is so that if an extension adds a post type, and the database gets
populated with posts of that type, but then if the extension is
disabled, we wouldn’t want those posts to display because we would have
no knowledge about how to deal with/render them.
This commit is contained in:
Toby Zerner
2015-03-28 12:13:19 +10:30
parent 38ebb15334
commit afa4b98c4a
3 changed files with 75 additions and 1 deletions

View File

@@ -65,6 +65,8 @@ class Post extends Model
static::deleted(function ($post) {
$post->raise(new PostWasDeleted($post));
});
static::addGlobalScope(new RegisteredTypesScope);
}
/**
@@ -119,6 +121,18 @@ class Post extends Model
return array_map('intval', $query->get(['id'])->fetch('id')->all());
}
/**
* Get all posts, regardless of their type, by removing the
* `RegisteredTypesScope` global scope constraints applied on this model.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAllTypes($query)
{
return $this->removeGlobalScopes($query);
}
/**
* Create a new model instance according to the post's type.
*
@@ -155,4 +169,9 @@ class Post extends Model
{
static::$types[$type] = $class;
}
public static function getTypes()
{
return static::$types;
}
}