aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2020-07-23 16:36:27 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2020-07-23 16:36:27 +0300
commit67ab9a792868ea4ef38ecd59abb6b193140eaf10 (patch)
treed744f1baa74b3b7b6ef08bfd97af5fdd6671c949 /priv
parent7991ddad582537f34b4964125195961e596b8687 (diff)
parent76aa49a0c5be0d1d51e99fd30683b12c8edc653d (diff)
downloadpleroma-67ab9a792868ea4ef38ecd59abb6b193140eaf10.tar.gz
Merge branch 'develop' into issue/1934-welcome-email
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20200716195806_autolinker_to_linkify.exs36
-rw-r--r--priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs26
2 files changed, 62 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
new file mode 100644
index 000000000..570acba84
--- /dev/null
+++ b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs
@@ -0,0 +1,36 @@
+defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
+ use Ecto.Migration
+ alias Pleroma.ConfigDB
+
+ @autolinker_path %{group: :auto_linker, key: :opts}
+ @linkify_path %{group: :pleroma, key: Pleroma.Formatter}
+
+ @compat_opts [:class, :rel, :new_window, :truncate, :strip_prefix, :extra]
+
+ def change do
+ with {:ok, {old, new}} <- maybe_get_params() do
+ move_config(old, new)
+ end
+ end
+
+ defp move_config(%{} = old, %{} = new) do
+ {:ok, _} = ConfigDB.update_or_create(new)
+ {:ok, _} = ConfigDB.delete(old)
+ :ok
+ end
+
+ defp maybe_get_params() do
+ with %ConfigDB{value: opts} <- ConfigDB.get_by_params(@autolinker_path),
+ opts <- transform_opts(opts),
+ %{} = linkify_params <- Map.put(@linkify_path, :value, opts) do
+ {:ok, {@autolinker_path, linkify_params}}
+ end
+ end
+
+ def transform_opts(opts) when is_list(opts) do
+ opts
+ |> Enum.into(%{})
+ |> Map.take(@compat_opts)
+ |> Map.to_list()
+ end
+end
diff --git a/priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs b/priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs
new file mode 100644
index 000000000..77b760825
--- /dev/null
+++ b/priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs
@@ -0,0 +1,26 @@
+defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfig do
+ use Ecto.Migration
+ alias Pleroma.ConfigDB
+
+ @config_path %{group: :pleroma, key: Pleroma.Formatter}
+
+ def change do
+ with %ConfigDB{value: %{} = opts} <- ConfigDB.get_by_params(@config_path),
+ fixed_opts <- Map.to_list(opts) do
+ fix_config(fixed_opts)
+ else
+ _ -> :skipped
+ end
+ end
+
+ defp fix_config(fixed_opts) when is_list(fixed_opts) do
+ {:ok, _} =
+ ConfigDB.update_or_create(%{
+ group: :pleroma,
+ key: Pleroma.Formatter,
+ value: fixed_opts
+ })
+
+ :ok
+ end
+end