logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20201005132900_transparency_exclusions_string_to_tuple.exs (1786B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.TransparencyExclusionsStringToTuple do
  5. use Ecto.Migration
  6. alias Pleroma.ConfigDB
  7. def up,
  8. do:
  9. ConfigDB.get_by_params(%{group: :pleroma, key: :mrf})
  10. |> update_transparency_exclusions_instances_to_tuples
  11. def down,
  12. do:
  13. ConfigDB.get_by_params(%{group: :pleroma, key: :mrf})
  14. |> update_transparency_exclusions_instances_to_strings
  15. defp update_transparency_exclusions_instances_to_tuples(%{value: settings}) do
  16. settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_tuples
  17. end
  18. defp update_transparency_exclusions_instances_to_tuples(nil), do: {:ok, nil}
  19. defp update_to_tuples({:transparency_exclusions, instance_list}) do
  20. new_value =
  21. instance_list
  22. |> Enum.map(fn
  23. {v, r} -> {v, r}
  24. v -> {v, ""}
  25. end)
  26. ConfigDB.update_or_create(%{
  27. group: :pleroma,
  28. key: :mrf,
  29. value: [transparency_exclusions: new_value]
  30. })
  31. end
  32. defp update_to_tuples(nil), do: {:ok, nil}
  33. defp update_transparency_exclusions_instances_to_strings(%{value: settings}) do
  34. settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_strings
  35. end
  36. defp update_transparency_exclusions_instances_to_strings(nil), do: {:ok, nil}
  37. defp update_to_strings({:transparency_exclusions, instance_list}) do
  38. new_value =
  39. instance_list
  40. |> Enum.map(fn
  41. {v, _} -> v
  42. v -> v
  43. end)
  44. ConfigDB.update_or_create(%{
  45. group: :pleroma,
  46. key: :mrf,
  47. value: [transparency_exclusions: new_value]
  48. })
  49. end
  50. defp update_to_strings(nil), do: {:ok, nil}
  51. end