logo

pleroma

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

20200328193433_populate_user_raw_bio.exs (786B)


  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.PopulateUserRawBio do
  5. use Ecto.Migration
  6. import Ecto.Query
  7. alias Pleroma.User
  8. alias Pleroma.Repo
  9. def change do
  10. {:ok, _} = Application.ensure_all_started(:fast_sanitize)
  11. User.Query.build(%{local: true})
  12. |> select([u], struct(u, [:id, :ap_id, :bio]))
  13. |> Repo.stream()
  14. |> Enum.each(fn %{bio: bio} = user ->
  15. if bio do
  16. raw_bio =
  17. bio
  18. |> String.replace(~r(<br */?>), "\n")
  19. |> Pleroma.HTML.strip_tags()
  20. Ecto.Changeset.cast(user, %{raw_bio: raw_bio}, [:raw_bio])
  21. |> Repo.update()
  22. end
  23. end)
  24. end
  25. end