it is changed in compile time
we can't change module attributes and endpoint settings in runtime
This commit is contained in:
parent
b7fc722a2e
commit
c2ca1f22a2
32 changed files with 940 additions and 52 deletions
41
lib/pleroma/config/transfer_task.ex
Normal file
41
lib/pleroma/config/transfer_task.ex
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue