mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 23:53:43 +08:00
Fix entity deletion
Foreign keys take care of most of this for us!
This commit is contained in:
parent
bcd74ff09b
commit
e8cd2d4111
|
@ -37,8 +37,8 @@ return [
|
|||
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
|
||||
$table->foreign('last_posted_user_id')->references('id')->on('users')->onDelete('set null');
|
||||
$table->foreign('hidden_user_id')->references('id')->on('users')->onDelete('set null');
|
||||
$table->foreign('first_post_id')->references('id')->on('posts');
|
||||
$table->foreign('last_post_id')->references('id')->on('posts');
|
||||
$table->foreign('first_post_id')->references('id')->on('posts')->onDelete('set null');
|
||||
$table->foreign('last_post_id')->references('id')->on('posts')->onDelete('set null');
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -100,21 +100,6 @@ class Discussion extends AbstractModel
|
|||
|
||||
static::deleted(function (Discussion $discussion) {
|
||||
$discussion->raise(new Deleted($discussion));
|
||||
|
||||
// Delete all of the posts in the discussion. Before we delete them
|
||||
// in a big batch query, we will loop through them and raise a
|
||||
// PostWasDeleted event for each post.
|
||||
$posts = $discussion->posts()->allTypes();
|
||||
|
||||
foreach ($posts->cursor() as $post) {
|
||||
$discussion->raise(new PostDeleted($post));
|
||||
}
|
||||
|
||||
$posts->delete();
|
||||
|
||||
// Delete all of the 'state' records for all of the users who have
|
||||
// read the discussion.
|
||||
$discussion->readers()->detach();
|
||||
});
|
||||
|
||||
static::saving(function (Discussion $discussion) {
|
||||
|
|
|
@ -64,8 +64,6 @@ class Group extends AbstractModel
|
|||
|
||||
static::deleted(function (Group $group) {
|
||||
$group->raise(new Deleted($group));
|
||||
|
||||
$group->permissions()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -126,22 +126,6 @@ class User extends AbstractModel
|
|||
|
||||
static::deleted(function (User $user) {
|
||||
$user->raise(new Deleted($user));
|
||||
|
||||
// Delete all of the posts by the user. Before we delete them
|
||||
// in a big batch query, we will loop through them and raise a
|
||||
// PostWasDeleted event for each post.
|
||||
$posts = $user->posts()->allTypes();
|
||||
|
||||
foreach ($posts->cursor() as $post) {
|
||||
$user->raise(new PostDeleted($post));
|
||||
}
|
||||
|
||||
$posts->delete();
|
||||
|
||||
$user->read()->detach();
|
||||
$user->groups()->detach();
|
||||
$user->accessTokens()->delete();
|
||||
$user->notifications()->delete();
|
||||
});
|
||||
|
||||
static::$dispatcher->fire(
|
||||
|
|
Loading…
Reference in New Issue
Block a user