diff options
author | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2019-06-14 15:45:05 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-06-14 15:45:05 +0000 |
commit | c2ca1f22a25d22d6d863406ed05b08c643e5824c (patch) | |
tree | bf75fc306788d784d74fb6ca617f3ddd27b75fd2 /lib/pleroma/config/transfer_task.ex | |
parent | b7fc722a2e9e93341229cb122aac605421782295 (diff) | |
download | pleroma-c2ca1f22a25d22d6d863406ed05b08c643e5824c.tar.gz |
it is changed in compile time
we can't change module attributes and endpoint settings in runtime
Diffstat (limited to 'lib/pleroma/config/transfer_task.ex')
-rw-r--r-- | lib/pleroma/config/transfer_task.ex | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex new file mode 100644 index 000000000..0d6ece807 --- /dev/null +++ b/lib/pleroma/config/transfer_task.ex @@ -0,0 +1,41 @@ +defmodule Pleroma.Config.TransferTask do + use Task + alias Pleroma.Web.AdminAPI.Config + + def start_link do + load_and_update_env() + if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Pleroma.Repo) + :ignore + end + + def load_and_update_env do + if Pleroma.Config.get([:instance, :dynamic_configuration]) do + Pleroma.Repo.all(Config) + |> Enum.each(&update_env(&1)) + end + end + + defp update_env(setting) do + try do + key = + if String.starts_with?(setting.key, "Pleroma.") do + "Elixir." <> setting.key + else + setting.key + end + + Application.put_env( + :pleroma, + String.to_existing_atom(key), + Config.from_binary(setting.value) + ) + rescue + e -> + require Logger + + Logger.warn( + "updating env causes error, key: #{inspect(setting.key)}, error: #{inspect(e)}" + ) + end + end +end |