1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
10 defmodule Pleroma.SpcFixes do
14 where: fragment("? like ?", u.ap_id, "https://shitposter.club/user/%")
17 {:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt")
19 # Mapping of old ap_id to new ap_id and vice reversa
24 |> Enum.map(fn line ->
28 |> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc ->
30 |> Map.put(String.trim(old_ap_id), String.trim(new_ap_id))
31 |> Map.put(String.trim(new_ap_id), String.trim(old_ap_id))
34 # First, refetch all the old users.
38 |> Enum.each(fn user ->
39 with ap_id when is_binary(ap_id) <- mapping[user.ap_id] do
40 # This fetches and updates the user.
41 User.get_or_fetch_by_ap_id(ap_id)
45 # Now, fix follow relationships.
48 where: fragment("? like ?", u.ap_id, "https://shitposter.club/users/%")
53 |> Enum.each(fn user ->
54 old_follower_address = User.ap_followers(user)
59 where: ^old_follower_address in u.following,
61 push: [following: ^user.follower_address]
65 Repo.update_all(query, [])
70 where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]),
75 "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)",
79 ^[user.follower_address]
84 recipients: ^user.follower_address
89 Repo.update_all(query, [])