mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
fix gallery notification deletion (#183)
This commit is contained in:
parent
0090797074
commit
e0dc9c79f2
1 changed files with 18 additions and 2 deletions
|
@ -15,6 +15,7 @@ defmodule Philomena.Galleries do
|
||||||
alias Philomena.GalleryReorderWorker
|
alias Philomena.GalleryReorderWorker
|
||||||
alias Philomena.Notifications
|
alias Philomena.Notifications
|
||||||
alias Philomena.NotificationWorker
|
alias Philomena.NotificationWorker
|
||||||
|
alias Philomena.Notifications.{Notification, UnreadNotification}
|
||||||
alias Philomena.Images
|
alias Philomena.Images
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -90,9 +91,24 @@ defmodule Philomena.Galleries do
|
||||||
|> select([i], i.image_id)
|
|> select([i], i.image_id)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
Repo.delete(gallery)
|
unread_notifications =
|
||||||
|
UnreadNotification
|
||||||
|
|> join(:inner, [un], _ in assoc(un, :notification))
|
||||||
|
|> where([_, n], n.actor_type == "Gallery")
|
||||||
|
|> where([_, n], n.actor_id == ^gallery.id)
|
||||||
|
|
||||||
|
notifications =
|
||||||
|
Notification
|
||||||
|
|> where(actor_type: "Gallery")
|
||||||
|
|> where(actor_id: ^gallery.id)
|
||||||
|
|
||||||
|
Multi.new()
|
||||||
|
|> Multi.delete(:gallery, gallery)
|
||||||
|
|> Multi.delete_all(:unread_notifications, unread_notifications)
|
||||||
|
|> Multi.delete_all(:notifications, notifications)
|
||||||
|
|> Repo.transaction()
|
||||||
|> case do
|
|> case do
|
||||||
{:ok, gallery} ->
|
{:ok, %{gallery: gallery}} ->
|
||||||
unindex_gallery(gallery)
|
unindex_gallery(gallery)
|
||||||
Images.reindex_images(images)
|
Images.reindex_images(images)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue