Fix entity deletion

Foreign keys take care of most of this for us!
This commit is contained in:
Toby Zerner 2018-07-21 17:18:40 +09:30
parent bcd74ff09b
commit e8cd2d4111
4 changed files with 2 additions and 35 deletions

View File

@ -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');
});
},

View File

@ -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) {

View File

@ -64,8 +64,6 @@ class Group extends AbstractModel
static::deleted(function (Group $group) {
$group->raise(new Deleted($group));
$group->permissions()->delete();
});
}

View File

@ -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(