Merge branch 'develop' into stable
[akkoma] / lib / mix / tasks / pleroma / config.ex
index 22502a522a332a0df28e55ec947ca559cfe0d3be..8661d8d7c312e2bfff69cf5a6353756bd0904268 100644 (file)
@@ -12,7 +12,7 @@ defmodule Mix.Tasks.Pleroma.Config do
   alias Pleroma.Repo
 
   @shortdoc "Manages the location of the config"
-  @moduledoc File.read!("docs/administration/CLI_tasks/config.md")
+  @moduledoc File.read!("docs/docs/administration/CLI_tasks/config.md")
 
   def run(["migrate_to_db"]) do
     check_configdb(fn ->
@@ -79,6 +79,45 @@ defmodule Mix.Tasks.Pleroma.Config do
     end)
   end
 
+  def run(["dump_to_file", group, key, fname]) do
+    check_configdb(fn ->
+      start_pleroma()
+
+      group = maybe_atomize(group)
+      key = maybe_atomize(key)
+
+      config = ConfigDB.get_by_group_and_key(group, key)
+
+      json =
+        %{
+          group: ConfigDB.to_json_types(config.group),
+          key: ConfigDB.to_json_types(config.key),
+          value: ConfigDB.to_json_types(config.value)
+        }
+        |> Jason.encode!()
+        |> Jason.Formatter.pretty_print()
+
+      File.write(fname, json)
+      shell_info("Wrote #{group}_#{key}.json")
+    end)
+  end
+
+  def run(["load_from_file", fname]) do
+    check_configdb(fn ->
+      start_pleroma()
+
+      json = File.read!(fname)
+      config = Jason.decode!(json)
+      group = ConfigDB.to_elixir_types(config["group"])
+      key = ConfigDB.to_elixir_types(config["key"])
+      value = ConfigDB.to_elixir_types(config["value"])
+      params = %{group: group, key: key, value: value}
+
+      ConfigDB.update_or_create(params)
+      shell_info("Loaded #{config["group"]}, #{config["key"]}")
+    end)
+  end
+
   def run(["groups"]) do
     check_configdb(fn ->
       start_pleroma()
@@ -286,9 +325,7 @@ defmodule Mix.Tasks.Pleroma.Config do
         file = File.open!(tmp_config_path)
 
         shell_info(
-          "Saving database configuration settings to #{tmp_config_path}. Copy it to the #{
-            Path.dirname(config_path)
-          } manually."
+          "Saving database configuration settings to #{tmp_config_path}. Copy it to the #{Path.dirname(config_path)} manually."
         )
 
         write_config(file, tmp_config_path, opts)