Verified Commit 613e0963 authored by Alex Gleason's avatar Alex Gleason
Browse files

Migrate :auto_linker --> Pleroma.Formatter in ConfigDB

parent 88030198
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
use Ecto.Migration
alias Pleroma.Repo
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
defp transform_opts(opts) when is_list(opts) do
opts
|> Enum.into(%{})
|> Map.take(@compat_opts)
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment