User: Add raw_bio, storing unformatted bio
Related: https://git.pleroma.social/pleroma/pleroma/issues/1643
This commit is contained in:
parent
d74985af23
commit
e1b07402ab
8 changed files with 61 additions and 19 deletions
9
priv/repo/migrations/20200322174133_user_raw_bio.exs
Normal file
9
priv/repo/migrations/20200322174133_user_raw_bio.exs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Pleroma.Repo.Migrations.UserRawBio do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add_if_not_exists(:raw_bio, :text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue