+ defp write(config, file) do
+ value = inspect(config.value, limit: :infinity)
+
+ IO.write(file, "config #{inspect(config.group)}, #{inspect(config.key)}, #{value}\r\n\r\n")
+
+ config
+ end
+
+ defp delete(config, true) do
+ {:ok, _} = Repo.delete(config)
+
+ shell_info(
+ "config #{inspect(config.group)}, #{inspect(config.key)} deleted from the ConfigDB."
+ )
+ end
+
+ defp delete(_config, _), do: :ok
+
+ defp dump(%Pleroma.ConfigDB{} = config) do
+ value = inspect(config.value, limit: :infinity)
+
+ shell_info("config #{inspect(config.group)}, #{inspect(config.key)}, #{value}\r\n\r\n")
+ end
+
+ defp configdb_not_enabled do
+ shell_error(
+ "ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
+ )
+ end
+
+ defp dump_key(group, key) when is_atom(group) and is_atom(key) do
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.group == group && x.key == key do
+ x |> dump
+ end
+ end)
+ end
+
+ defp dump_group(group) when is_atom(group) do
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.group == group do
+ x |> dump
+ end
+ end)
+ end
+
+ defp group_exists?(group) when is_atom(group) do
+ result =
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.group == group do
+ x
+ end
+ end)
+
+ unless result == [] do
+ true
+ else
+ false
+ end
+ end
+
+ def maybe_atomize(arg) when is_atom(arg), do: arg
+
+ def maybe_atomize(arg) when is_binary(arg) do
+ chars = String.codepoints(arg)
+
+ if "." in chars do
+ :"Elixir.#{arg}"
+ else
+ String.to_atom(arg)