logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20200716195806_autolinker_to_linkify.exs (1129B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do
  5. use Ecto.Migration
  6. alias Pleroma.ConfigDB
  7. @autolinker_path %{group: :auto_linker, key: :opts}
  8. @linkify_path %{group: :pleroma, key: Pleroma.Formatter}
  9. @compat_opts [:class, :rel, :new_window, :truncate, :strip_prefix, :extra]
  10. def change do
  11. with {:ok, {old, new}} <- maybe_get_params() do
  12. move_config(old, new)
  13. end
  14. end
  15. defp move_config(%{} = old, %{} = new) do
  16. {:ok, _} = ConfigDB.update_or_create(new)
  17. {:ok, _} = ConfigDB.delete(old)
  18. :ok
  19. end
  20. defp maybe_get_params() do
  21. with %ConfigDB{value: opts} <- ConfigDB.get_by_params(@autolinker_path),
  22. opts <- transform_opts(opts),
  23. %{} = linkify_params <- Map.put(@linkify_path, :value, opts) do
  24. {:ok, {@autolinker_path, linkify_params}}
  25. end
  26. end
  27. def transform_opts(opts) when is_list(opts) do
  28. opts
  29. |> Enum.into(%{})
  30. |> Map.take(@compat_opts)
  31. |> Map.to_list()
  32. end
  33. end