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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user