- defp update_env(setting) do
- try do
- key = ConfigDB.from_string(setting.key)
- group = ConfigDB.from_string(setting.group)
- value = ConfigDB.from_binary(setting.value)
-
- if group != :phoenix and key != :serve_endpoints do
- default = Pleroma.Config.Holder.config(group, key)
-
- merged_value =
- if can_be_merged?(default, value) do
- DeepMerge.deep_merge(default, value)
- else
- value
- end
-
- :ok = Application.put_env(group, key, merged_value)
- group
+ defp maybe_set_pleroma_last(apps) do
+ # to be ensured that pleroma will be restarted last
+ if :pleroma in apps do
+ apps
+ |> List.delete(:pleroma)
+ |> List.insert_at(-1, :pleroma)
+ else
+ Restarter.Pleroma.rebooted()
+ apps
+ end
+ end
+
+ defp merge_with_default(%{group: group, key: key, value: value} = setting) do
+ default = Config.Holder.default_config(group, key)
+
+ merged =
+ cond do
+ Ecto.get_meta(setting, :state) == :deleted -> default
+ can_be_merged?(default, value) -> ConfigDB.merge_group(group, key, default, value)
+ true -> value
+ end
+
+ {group, key, value, merged}
+ end
+
+ # change logger configuration in runtime, without restart
+ defp configure({:quack, key, _, merged}) do
+ Logger.configure_backend(Quack.Logger, [{key, merged}])
+ :ok = update_env(:quack, key, merged)
+ end
+
+ defp configure({_, :backends, _, merged}) do
+ # removing current backends
+ Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1)
+
+ Enum.each(merged, &Logger.add_backend/1)
+
+ :ok = update_env(:logger, :backends, merged)
+ end
+
+ defp configure({_, key, _, merged}) when key in [:console, :ex_syslogger] do
+ merged =
+ if key == :console do
+ put_in(merged[:format], merged[:format] <> "\n")
+ else
+ merged