Centralize check that configdb is enabled which now raises an exception
This commit is contained in:
parent
53a5ec1952
commit
a7b5280b5b
|
@ -14,11 +14,13 @@ defmodule Mix.Tasks.Pleroma.Config do
|
||||||
@moduledoc File.read!("docs/administration/CLI_tasks/config.md")
|
@moduledoc File.read!("docs/administration/CLI_tasks/config.md")
|
||||||
|
|
||||||
def run(["migrate_to_db"]) do
|
def run(["migrate_to_db"]) do
|
||||||
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
migrate_to_db()
|
migrate_to_db()
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["migrate_from_db" | options]) do
|
def run(["migrate_from_db" | options]) do
|
||||||
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
{opts, _} =
|
{opts, _} =
|
||||||
|
@ -31,7 +33,7 @@ def run(["migrate_from_db" | options]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump"]) do
|
def run(["dump"]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
header = config_header()
|
header = config_header()
|
||||||
|
@ -48,38 +50,29 @@ def run(["dump"]) do
|
||||||
else
|
else
|
||||||
shell_error("No settings in ConfigDB.")
|
shell_error("No settings in ConfigDB.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump", group, key]) do
|
def run(["dump", group, key]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = maybe_atomize(group)
|
group = maybe_atomize(group)
|
||||||
key = maybe_atomize(key)
|
key = maybe_atomize(key)
|
||||||
|
|
||||||
dump_key(group, key)
|
dump_key(group, key)
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump", group]) do
|
def run(["dump", group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = maybe_atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
|
||||||
dump_group(group)
|
dump_group(group)
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["groups"]) do
|
def run(["groups"]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
groups =
|
groups =
|
||||||
|
@ -94,13 +87,10 @@ def run(["groups"]) do
|
||||||
groups |> Enum.each(fn x -> shell_info("- #{x}") end)
|
groups |> Enum.each(fn x -> shell_info("- #{x}") end)
|
||||||
shell_info("\r\n")
|
shell_info("\r\n")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["reset"]) do
|
def run(["reset"]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
shell_info("The following settings will be permanently removed:")
|
shell_info("The following settings will be permanently removed:")
|
||||||
|
@ -120,13 +110,10 @@ def run(["reset"]) do
|
||||||
else
|
else
|
||||||
shell_error("No changes made.")
|
shell_error("No changes made.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["delete", group]) do
|
def run(["delete", group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = maybe_atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
@ -150,13 +137,10 @@ def run(["delete", group]) do
|
||||||
else
|
else
|
||||||
shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
|
shell_error("No settings in ConfigDB for #{inspect(group)}. Aborting.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["delete", group, key]) do
|
def run(["delete", group, key]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
check_configdb()
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
group = maybe_atomize(group)
|
group = maybe_atomize(group)
|
||||||
|
@ -173,15 +157,11 @@ def run(["delete", group, key]) do
|
||||||
else
|
else
|
||||||
shell_error("No changes made.")
|
shell_error("No changes made.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
_ -> configdb_not_enabled()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec migrate_to_db(Path.t() | nil) :: any()
|
@spec migrate_to_db(Path.t() | nil) :: any()
|
||||||
def migrate_to_db(file_path \\ nil) do
|
def migrate_to_db(file_path \\ nil) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]),
|
with :ok <- Pleroma.Config.DeprecationWarnings.warn() do
|
||||||
:ok <- Pleroma.Config.DeprecationWarnings.warn() do
|
|
||||||
config_file =
|
config_file =
|
||||||
if file_path do
|
if file_path do
|
||||||
file_path
|
file_path
|
||||||
|
@ -195,8 +175,7 @@ def migrate_to_db(file_path \\ nil) do
|
||||||
|
|
||||||
do_migrate_to_db(config_file)
|
do_migrate_to_db(config_file)
|
||||||
else
|
else
|
||||||
:error -> deprecation_error()
|
_ -> deprecation_error()
|
||||||
_ -> migration_error()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -232,7 +211,6 @@ defp create(group, settings) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp migrate_from_db(opts) do
|
defp migrate_from_db(opts) do
|
||||||
if Pleroma.Config.get([:configurable_from_database]) do
|
|
||||||
env = opts[:env] || Pleroma.Config.get(:env)
|
env = opts[:env] || Pleroma.Config.get(:env)
|
||||||
|
|
||||||
config_path =
|
config_path =
|
||||||
|
@ -259,15 +237,6 @@ defp migrate_from_db(opts) do
|
||||||
shell_info(
|
shell_info(
|
||||||
"Database configuration settings have been exported to config/#{env}.exported_from_db.secret.exs"
|
"Database configuration settings have been exported to config/#{env}.exported_from_db.secret.exs"
|
||||||
)
|
)
|
||||||
else
|
|
||||||
migration_error()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp migration_error do
|
|
||||||
shell_error(
|
|
||||||
"Migration is not allowed in config. You can change this behavior by setting `config :pleroma, configurable_from_database: true`"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp deprecation_error do
|
defp deprecation_error do
|
||||||
|
@ -313,7 +282,7 @@ defp dump(%Pleroma.ConfigDB{} = config) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp configdb_not_enabled do
|
defp configdb_not_enabled do
|
||||||
shell_error(
|
raise(
|
||||||
"ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
|
"ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -366,4 +335,12 @@ defp maybe_atomize(arg) when is_binary(arg) do
|
||||||
String.to_atom(arg)
|
String.to_atom(arg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp check_configdb() do
|
||||||
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
_ -> configdb_not_enabled()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue