1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
9 @autolinker_path %{group: :auto_linker, key: :opts}
10 @linkify_path %{group: :pleroma, key: Pleroma.Formatter}
12 @compat_opts [:class, :rel, :new_window, :truncate, :strip_prefix, :extra]
15 with {:ok, {old, new}} <- maybe_get_params() do
20 defp move_config(%{} = old, %{} = new) do
21 {:ok, _} = ConfigDB.update_or_create(new)
22 {:ok, _} = ConfigDB.delete(old)
26 defp maybe_get_params() do
27 with %ConfigDB{value: opts} <- ConfigDB.get_by_params(@autolinker_path),
28 opts <- transform_opts(opts),
29 %{} = linkify_params <- Map.put(@linkify_path, :value, opts) do
30 {:ok, {@autolinker_path, linkify_params}}
34 def transform_opts(opts) when is_list(opts) do
37 |> Map.take(@compat_opts)