1
0
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:
Toby Zerner
2018-11-11 16:59:24 +10:30
parent 6d14d0c39b
commit bf8bc0222f
4 changed files with 45 additions and 0 deletions

View File

@@ -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.
*