aboutsummaryrefslogtreecommitdiff
path: root/lib/mix/tasks
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-11-25 12:44:06 -0600
committerMark Felder <feld@FreeBSD.org>2020-12-02 10:43:22 -0600
commit6dcc36baa9b19d18785d6f7ab8ceb7dd941c6180 (patch)
treef7d1e13390dab367c34182316d23203ce0d34ab9 /lib/mix/tasks
parent57d0379b89bd323dacf4959b03c55519de173ec0 (diff)
downloadpleroma-6dcc36baa9b19d18785d6f7ab8ceb7dd941c6180.tar.gz
Add mix tasks to give additional recovery and debugging options
- pleroma.config dump: prints the entire config as it would be exported to the filesystem - pleroma.config dump KEY: prints the configuration under a specific ConfigDB key in the database - pleroma.config keylist: lists the available keys in ConfigDB - pleroma.config keydel KEY: deletes ConfigDB entry stored under the key This should prevent the need for users to manually execute SQL queries.
Diffstat (limited to 'lib/mix/tasks')
-rw-r--r--lib/mix/tasks/pleroma/config.ex89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex
index 18f99318d..b49854528 100644
--- a/lib/mix/tasks/pleroma/config.ex
+++ b/lib/mix/tasks/pleroma/config.ex
@@ -30,6 +30,83 @@ defmodule Mix.Tasks.Pleroma.Config do
migrate_from_db(opts)
end
+ def run(["dump"]) do
+ with true <- Pleroma.Config.get([:configurable_from_database]) do
+ start_pleroma()
+
+ header = config_header()
+
+ shell_info("#{header}")
+
+ ConfigDB
+ |> Repo.all()
+ |> Enum.each(&dump(&1))
+ else
+ _ -> configdb_not_enabled()
+ end
+ end
+
+ def run(["dump" | dbkey]) do
+ with true <- Pleroma.Config.get([:configurable_from_database]) do
+ start_pleroma()
+
+ dbkey = dbkey |> List.first() |> String.to_atom()
+
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.key == dbkey do
+ x |> dump
+ end
+ end)
+ else
+ _ -> configdb_not_enabled()
+ end
+ end
+
+ def run(["keylist"]) do
+ with true <- Pleroma.Config.get([:configurable_from_database]) do
+ start_pleroma()
+
+ keys =
+ ConfigDB
+ |> Repo.all()
+ |> Enum.map(fn x -> x.key end)
+
+ if length(keys) > 0 do
+ shell_info("The following configuration keys are set in ConfigDB:\r\n")
+ keys |> Enum.each(fn x -> shell_info("- #{x}") end)
+ shell_info("\r\n")
+ end
+ else
+ _ -> configdb_not_enabled()
+ end
+ end
+
+ def run(["keydel" | dbkey]) do
+ unless [] == dbkey do
+ with true <- Pleroma.Config.get([:configurable_from_database]) do
+ start_pleroma()
+
+ dbkey = dbkey |> List.first() |> String.to_atom()
+
+ ConfigDB
+ |> Repo.all()
+ |> Enum.filter(fn x ->
+ if x.key == dbkey do
+ x |> delete(true)
+ end
+ end)
+ else
+ _ -> configdb_not_enabled()
+ end
+ else
+ shell_error(
+ "You must provide a key to delete. Use the keylist command to get a list of valid keys."
+ )
+ end
+ end
+
@spec migrate_to_db(Path.t() | nil) :: any()
def migrate_to_db(file_path \\ nil) do
with true <- Pleroma.Config.get([:configurable_from_database]),
@@ -154,4 +231,16 @@ defmodule Mix.Tasks.Pleroma.Config do
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
end