mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 14:17:59 +01:00
Clear deleted posts and topics from listings
This commit is contained in:
parent
e2c94dda6c
commit
b513e66578
2 changed files with 31 additions and 2 deletions
|
@ -222,11 +222,23 @@ defmodule Philomena.Posts do
|
|||
|> select([r], r.id)
|
||||
|> update(set: [open: false, state: "closed", admin_id: ^user.id])
|
||||
|
||||
topics =
|
||||
Topic
|
||||
|> where(last_post_id: ^post.id)
|
||||
|> update(set: [last_post_id: nil])
|
||||
|
||||
forums =
|
||||
Forum
|
||||
|> where(last_post_id: ^post.id)
|
||||
|> update(set: [last_post_id: nil])
|
||||
|
||||
post = Post.hide_changeset(post, attrs, user)
|
||||
|
||||
Multi.new()
|
||||
|> Multi.update(:post, post)
|
||||
|> Multi.update_all(:reports, reports, [])
|
||||
|> Multi.update_all(:topics, topics, [])
|
||||
|> Multi.update_all(:forums, forums, [])
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, %{post: post, reports: {_count, reports}}} ->
|
||||
|
|
|
@ -268,8 +268,25 @@ defmodule Philomena.Topics do
|
|||
end
|
||||
|
||||
def hide_topic(topic, deletion_reason, user) do
|
||||
Topic.hide_changeset(topic, deletion_reason, user)
|
||||
|> Repo.update()
|
||||
topic_changes = Topic.hide_changeset(topic, deletion_reason, user)
|
||||
|
||||
forums =
|
||||
Forum
|
||||
|> join(:inner, [f], _ in assoc(f, :last_post))
|
||||
|> where([f, p], p.topic_id == ^topic.id)
|
||||
|> update(set: [last_post_id: nil])
|
||||
|
||||
Multi.new()
|
||||
|> Multi.update(:topic, topic_changes)
|
||||
|> Multi.update_all(:forums, forums, [])
|
||||
|> Repo.transaction()
|
||||
|> case do
|
||||
{:ok, %{topic: topic}} ->
|
||||
{:ok, topic}
|
||||
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
def unhide_topic(topic) do
|
||||
|
|
Loading…
Reference in a new issue