diff options
author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-12-23 17:43:21 +0000 |
---|---|---|
committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2022-12-23 17:43:21 +0000 |
commit | f76c1d4f70fdda6da621a46fb75891e68e266946 (patch) | |
tree | 328aec763c24b6426decd30fe3b6a4674510bbee /priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs | |
parent | d8e326467c30b95c5164f6e29512057dce3c2077 (diff) | |
parent | 91c22637de5f1683a32207a606c33e7ef3b84676 (diff) | |
download | pleroma-f76c1d4f70fdda6da621a46fb75891e68e266946.tar.gz pleroma-f76c1d4f70fdda6da621a46fb75891e68e266946.zip |
Merge branch 'release/2.5.0' into 'stable'
Release 2.5.0
See merge request pleroma/pleroma!3816
Diffstat (limited to 'priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs')
-rw-r--r-- | priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs b/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs new file mode 100644 index 000000000..53b73ea2f --- /dev/null +++ b/priv/repo/migrations/20201005132900_transparency_exclusions_string_to_tuple.exs @@ -0,0 +1,65 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.TransparencyExclusionsStringToTuple do + use Ecto.Migration + + alias Pleroma.ConfigDB + + def up, + do: + ConfigDB.get_by_params(%{group: :pleroma, key: :mrf}) + |> update_transparency_exclusions_instances_to_tuples + + def down, + do: + ConfigDB.get_by_params(%{group: :pleroma, key: :mrf}) + |> update_transparency_exclusions_instances_to_strings + + defp update_transparency_exclusions_instances_to_tuples(%{value: settings}) do + settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_tuples + end + + defp update_transparency_exclusions_instances_to_tuples(nil), do: {:ok, nil} + + defp update_to_tuples({:transparency_exclusions, instance_list}) do + new_value = + instance_list + |> Enum.map(fn + {v, r} -> {v, r} + v -> {v, ""} + end) + + ConfigDB.update_or_create(%{ + group: :pleroma, + key: :mrf, + value: [transparency_exclusions: new_value] + }) + end + + defp update_to_tuples(nil), do: {:ok, nil} + + defp update_transparency_exclusions_instances_to_strings(%{value: settings}) do + settings |> List.keyfind(:transparency_exclusions, 0) |> update_to_strings + end + + defp update_transparency_exclusions_instances_to_strings(nil), do: {:ok, nil} + + defp update_to_strings({:transparency_exclusions, instance_list}) do + new_value = + instance_list + |> Enum.map(fn + {v, _} -> v + v -> v + end) + + ConfigDB.update_or_create(%{ + group: :pleroma, + key: :mrf, + value: [transparency_exclusions: new_value] + }) + end + + defp update_to_strings(nil), do: {:ok, nil} +end |