diff options
| author | lain <lain@soykaf.club> | 2020-07-23 10:28:52 +0000 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-07-23 10:28:52 +0000 | 
| commit | a81581472fed4ca736e71dad11dc29882eca975f (patch) | |
| tree | 9d8cfeb21c25233fe538d3bd0647689fd998c842 /priv | |
| parent | 1c9752cff445ab1f58cea1617d3c7ab73da60e10 (diff) | |
| parent | b6488a4db4accc6cda716c5fdfb03f5a30ddf3d4 (diff) | |
| download | pleroma-a81581472fed4ca736e71dad11dc29882eca975f.tar.gz pleroma-a81581472fed4ca736e71dad11dc29882eca975f.zip | |
Merge branch 'linkify' into 'develop'
Fix Linkify
See merge request pleroma/pleroma!2792
Diffstat (limited to 'priv')
| -rw-r--r-- | priv/repo/migrations/20200716195806_autolinker_to_linkify.exs | 36 | ||||
| -rw-r--r-- | priv/repo/migrations/20200722185515_fix_malformed_formatter_config.exs | 26 | 
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 | 
