mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27: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)
|
|> select([r], r.id)
|
||||||
|> update(set: [open: false, state: "closed", admin_id: ^user.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)
|
post = Post.hide_changeset(post, attrs, user)
|
||||||
|
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|> Multi.update(:post, post)
|
|> Multi.update(:post, post)
|
||||||
|> Multi.update_all(:reports, reports, [])
|
|> Multi.update_all(:reports, reports, [])
|
||||||
|
|> Multi.update_all(:topics, topics, [])
|
||||||
|
|> Multi.update_all(:forums, forums, [])
|
||||||
|> Repo.transaction()
|
|> Repo.transaction()
|
||||||
|> case do
|
|> case do
|
||||||
{:ok, %{post: post, reports: {_count, reports}}} ->
|
{:ok, %{post: post, reports: {_count, reports}}} ->
|
||||||
|
|
|
@ -268,8 +268,25 @@ defmodule Philomena.Topics do
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_topic(topic, deletion_reason, user) do
|
def hide_topic(topic, deletion_reason, user) do
|
||||||
Topic.hide_changeset(topic, deletion_reason, user)
|
topic_changes = Topic.hide_changeset(topic, deletion_reason, user)
|
||||||
|> Repo.update()
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def unhide_topic(topic) do
|
def unhide_topic(topic) do
|
||||||
|
|
Loading…
Reference in a new issue