ensure subscriptions are carried over on merge

This commit is contained in:
byte[] 2020-09-06 13:30:28 -04:00
parent 67832f623a
commit ccc788a9da

View file

@ -415,6 +415,9 @@ defmodule Philomena.Images do
|> Multi.run(:migrate_comments, fn _, %{} ->
{:ok, Comments.migrate_comments(image, duplicate_of_image)}
end)
|> Multi.run(:migrate_subscriptions, fn _, %{} ->
{:ok, migrate_subscriptions(image, duplicate_of_image)}
end)
|> Multi.run(:migrate_interactions, fn _, %{} ->
{:ok, Interactions.migrate_interactions(image, duplicate_of_image)}
end)
@ -706,7 +709,7 @@ defmodule Philomena.Images do
end
@doc """
Deletes a Subscription.
Deletes a subscription.
## Examples
@ -724,6 +727,12 @@ defmodule Philomena.Images do
|> Repo.delete()
end
def migrate_subscriptions(source, target) do
Subscription
|> where(image_id: ^source.id)
|> Repo.update_all(set: [image_id: target.id])
end
def clear_notification(_image, nil), do: nil
def clear_notification(image, user) do