forked from AkkomaGang/akkoma
Improve dumping groups and specific keys; add prompts for delete and reset
This commit is contained in:
parent
67437feafc
commit
c6a0ca2213
1 changed files with 27 additions and 21 deletions
|
@ -47,17 +47,21 @@ def run(["dump"]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump" | args]) when is_list(args) and length(args) < 3 do
|
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()
|
||||||
|
|
||||||
if length(args) > 1 do
|
|
||||||
[group, key] = args
|
|
||||||
dump_key(group, key)
|
dump_key(group, key)
|
||||||
else
|
else
|
||||||
[group] = args
|
_ -> configdb_not_enabled()
|
||||||
dump_group(group)
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["dump", group]) do
|
||||||
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
dump_group(group)
|
||||||
else
|
else
|
||||||
_ -> configdb_not_enabled()
|
_ -> configdb_not_enabled()
|
||||||
end
|
end
|
||||||
|
@ -114,36 +118,38 @@ def run(["reset"]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
|
if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
|
||||||
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
|
Ecto.Adapters.SQL.query!(Repo, "TRUNCATE config;")
|
||||||
Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
|
Ecto.Adapters.SQL.query!(Repo, "ALTER SEQUENCE config_id_seq RESTART;")
|
||||||
|
|
||||||
shell_info("The ConfigDB settings have been removed from the database.")
|
shell_info("The ConfigDB settings have been removed from the database.")
|
||||||
|
else
|
||||||
|
shell_info("No changes made.")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
_ -> configdb_not_enabled()
|
_ -> configdb_not_enabled()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["groupdel" | dbkey]) do
|
def run(["delete" | args]) when is_list(args) and length(args) == 2 do
|
||||||
unless [] == dbkey do
|
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
dbkey = dbkey |> List.first() |> String.to_atom()
|
[group, key] = args
|
||||||
|
|
||||||
|
if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do
|
||||||
ConfigDB
|
ConfigDB
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.filter(fn x ->
|
|> Enum.filter(fn x ->
|
||||||
if x.key == dbkey do
|
if x.group == group and x.key == key do
|
||||||
x |> delete(true)
|
x |> delete(true)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
_ -> configdb_not_enabled()
|
shell_info("No changes made.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
shell_error(
|
_ -> configdb_not_enabled()
|
||||||
"You must provide a group to delete. Use the groups command to get a list of valid configDB groups."
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue