remove images from galleries when they are hidden (derpibooru/philomena#219)

This commit is contained in:
byte[] 2020-10-26 21:58:58 -04:00
parent 9f9a4c1967
commit f771f4a90f

View file

@ -27,6 +27,8 @@ defmodule Philomena.Images do
alias Philomena.Reports alias Philomena.Reports
alias Philomena.Reports.Report alias Philomena.Reports.Report
alias Philomena.Comments alias Philomena.Comments
alias Philomena.Galleries.Gallery
alias Philomena.Galleries.Interaction
@doc """ @doc """
Gets a single image. Gets a single image.
@ -422,9 +424,18 @@ defmodule Philomena.Images 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])
galleries =
Gallery
|> join(:inner, [g], gi in assoc(g, :interactions), on: gi.image_id == ^image.id)
|> update(inc: [image_count: -1])
gallery_interactions = where(Interaction, image_id: ^image.id)
multi multi
|> Multi.update(:image, changeset) |> Multi.update(:image, changeset)
|> Multi.update_all(:reports, reports, []) |> Multi.update_all(:reports, reports, [])
|> Multi.update_all(:galleries, galleries, [])
|> Multi.delete_all(:gallery_interactions, gallery_interactions, [])
|> Multi.run(:tags, fn repo, %{image: image} -> |> Multi.run(:tags, fn repo, %{image: image} ->
image = Repo.preload(image, :tags, force: true) image = Repo.preload(image, :tags, force: true)