Fix group deletion caused by foreign keys issue with comments &

discussions

Closes #1016

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-01 12:09:23 +02:00
parent 7e7eed290f
commit a99d66b68f
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -190,6 +190,29 @@ defmodule Mobilizon.Service.ActorSuspension do
defp delete_discussions(%Multi{} = multi, %Actor{type: :Group, id: actor_id}) do defp delete_discussions(%Multi{} = multi, %Actor{type: :Group, id: actor_id}) do
Logger.debug("Delete group's discussions") Logger.debug("Delete group's discussions")
multi =
Multi.run(multi, :group_discussion_comments, fn _, _ ->
group_comments_ids =
Comment
|> join(:inner, [c], d in Discussion, on: c.discussion_id == d.id)
|> where([_c, d], d.actor_id == ^actor_id)
|> select([c], [c.id])
|> Repo.all()
|> Enum.concat()
{:ok, group_comments_ids}
end)
multi =
Multi.delete_all(
multi,
:delete_discussions_comments,
fn %{group_discussion_comments: group_discussion_comments} ->
where(Comment, [c], c.id in ^group_discussion_comments)
end
)
Multi.delete_all(multi, :delete_discussions, where(Discussion, [e], e.actor_id == ^actor_id)) Multi.delete_all(multi, :delete_discussions, where(Discussion, [e], e.actor_id == ^actor_id))
end end