From c9203f125c3ce44bc7b7273fedca089aadfb6b86 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 15 Jul 2024 15:21:16 -0400 Subject: [PATCH] Added a Mix task "pleroma.config fix_mrf_policies" which will remove erroneous MRF policies from ConfigDB --- changelog.d/fix-mrfs.add | 1 + lib/mix/tasks/pleroma/config.ex | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 changelog.d/fix-mrfs.add diff --git a/changelog.d/fix-mrfs.add b/changelog.d/fix-mrfs.add new file mode 100644 index 000000000..a38830109 --- /dev/null +++ b/changelog.d/fix-mrfs.add @@ -0,0 +1 @@ +Added a Mix task "pleroma.config fix_mrf_policies" which will remove erroneous MRF policies from ConfigDB diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 3a2ea44f8..8b3b2f18b 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -205,6 +205,35 @@ def run(["delete", group]) do end end + # Removes any policies that are not a real module + # as they will prevent the server from starting + def run(["fix_mrf_policies"]) do + check_configdb(fn -> + start_pleroma() + + group = :pleroma + key = :mrf + + %{value: value} = + group + |> ConfigDB.get_by_group_and_key(key) + + policies = + Keyword.get(value, :policies, []) + |> Enum.filter(&is_atom(&1)) + |> Enum.filter(fn mrf -> + case Code.ensure_compiled(mrf) do + {:module, _} -> true + {:error, _} -> false + end + end) + + value = Keyword.put(value, :policies, policies) + + ConfigDB.update_or_create(%{group: group, key: key, value: value}) + end) + end + @spec migrate_to_db(Path.t() | nil) :: any() def migrate_to_db(file_path \\ nil) do with :ok <- Pleroma.Config.DeprecationWarnings.warn() do