forked from AkkomaGang/akkoma
Transform strings to atoms for all cases, including when the atom is a module like Pleroma.Emails.Mailer
This commit is contained in:
parent
3df115b2b0
commit
4bdfcf1682
1 changed files with 19 additions and 10 deletions
|
@ -57,8 +57,8 @@ def run(["dump", group, key]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = atomize(group)
|
group = maybe_atomize(group)
|
||||||
key = atomize(key)
|
key = maybe_atomize(key)
|
||||||
|
|
||||||
dump_key(group, key)
|
dump_key(group, key)
|
||||||
else
|
else
|
||||||
|
@ -70,7 +70,7 @@ def run(["dump", group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
|
||||||
dump_group(group)
|
dump_group(group)
|
||||||
else
|
else
|
||||||
|
@ -103,7 +103,7 @@ def run(["keys", group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
|
||||||
keys =
|
keys =
|
||||||
ConfigDB
|
ConfigDB
|
||||||
|
@ -148,7 +148,7 @@ def run(["delete", group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
|
||||||
if group_exists?(group) do
|
if group_exists?(group) do
|
||||||
shell_info("The following settings will be removed from ConfigDB:\n")
|
shell_info("The following settings will be removed from ConfigDB:\n")
|
||||||
|
@ -178,8 +178,8 @@ def run(["delete", group, key]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = atomize(group)
|
group = maybe_atomize(group)
|
||||||
key = atomize(key)
|
key = maybe_atomize(key)
|
||||||
|
|
||||||
if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
|
if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
|
||||||
ConfigDB
|
ConfigDB
|
||||||
|
@ -337,7 +337,7 @@ defp configdb_not_enabled do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp dump_key(group, key) when is_atom(group) and is_atom(key) do
|
defp dump_key(group, key) when is_atom(group) and is_atom(key) do
|
||||||
ConfigDB
|
ConfigDB
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(fn x ->
|
|> Enum.filter(fn x ->
|
||||||
|
@ -374,6 +374,15 @@ defp group_exists?(group) when is_atom(group) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp atomize(x) when is_atom(x), do: x
|
def maybe_atomize(arg) when is_atom(arg), do: arg
|
||||||
defp atomize(x) when is_binary(x), do: String.to_atom(x)
|
|
||||||
|
def maybe_atomize(arg) when is_binary(arg) do
|
||||||
|
chars = String.codepoints(arg)
|
||||||
|
|
||||||
|
if "." in chars do
|
||||||
|
:"Elixir.#{arg}"
|
||||||
|
else
|
||||||
|
String.to_atom(arg)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue