mirror of
https://github.com/flarum/core.git
synced 2025-08-13 03:44:32 +02:00
Delete associated notifications when deleting discussions, posts, and users. fixes #1380
This commit is contained in:
@@ -169,6 +169,35 @@ class Notification extends AbstractModel
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope the query to include only notifications that have the given
|
||||
* subject.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param object $model
|
||||
*/
|
||||
public function scopeWhereSubject(Builder $query, $model)
|
||||
{
|
||||
$query->whereSubjectModel(get_class($model))
|
||||
->where('subject_id', $model->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope the query to include only notification types that use the given
|
||||
* subject model.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param string $class
|
||||
*/
|
||||
public function scopeWhereSubjectModel(Builder $query, string $class)
|
||||
{
|
||||
$notificationTypes = array_filter(Notification::getSubjectModels(), function ($modelClass) use ($class) {
|
||||
return $modelClass === $class or is_subclass_of($class, $modelClass);
|
||||
});
|
||||
|
||||
$query->whereIn('type', array_keys($notificationTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type-to-subject-model map.
|
||||
*
|
||||
|
Reference in New Issue
Block a user