2022-02-25 23:11:42 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 04:11:47 -07:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2022-02-25 23:11:42 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-03-23 15:52:25 -06:00
|
|
|
defmodule Pleroma.Repo.Migrations.PopulateUserRawBio do
|
|
|
|
use Ecto.Migration
|
|
|
|
import Ecto.Query
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
|
|
|
def change do
|
|
|
|
{:ok, _} = Application.ensure_all_started(:fast_sanitize)
|
|
|
|
|
|
|
|
User.Query.build(%{local: true})
|
|
|
|
|> select([u], struct(u, [:id, :ap_id, :bio]))
|
|
|
|
|> Repo.stream()
|
|
|
|
|> Enum.each(fn %{bio: bio} = user ->
|
|
|
|
if bio do
|
|
|
|
raw_bio =
|
|
|
|
bio
|
|
|
|
|> String.replace(~r(<br */?>), "\n")
|
|
|
|
|> Pleroma.HTML.strip_tags()
|
|
|
|
|
|
|
|
Ecto.Changeset.cast(user, %{raw_bio: raw_bio}, [:raw_bio])
|
|
|
|
|> Repo.update()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|