1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Config.TransferTask do
7 alias Pleroma.Web.AdminAPI.Config
11 if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Pleroma.Repo)
15 def load_and_update_env do
16 if Pleroma.Config.get([:instance, :dynamic_configuration]) and
17 Ecto.Adapters.SQL.table_exists?(Pleroma.Repo, "config") do
19 Pleroma.Repo.all(Config)
20 |> Enum.map(&update_env(&1))
22 # We need to restart applications for loaded settings take effect
24 |> Enum.reject(&(&1 in [:pleroma, :ok]))
25 |> Enum.each(fn app ->
27 :ok = Application.start(app)
32 defp update_env(setting) do
35 if String.starts_with?(setting.key, "Pleroma.") do
36 "Elixir." <> setting.key
38 String.trim_leading(setting.key, ":")
41 group = String.to_existing_atom(setting.group)
45 String.to_existing_atom(key),
46 Config.from_binary(setting.value)
55 "updating env causes error, key: #{inspect(setting.key)}, error: #{inspect(e)}"