1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
11 defmodule Pleroma.SpcFixes do
15 where: fragment("? like ?", u.ap_id, "https://shitposter.club/user/%")
18 {:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt")
20 # Mapping of old ap_id to new ap_id and vice reversa
25 |> Enum.map(fn line ->
29 |> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc ->
31 |> Map.put(String.trim(old_ap_id), String.trim(new_ap_id))
32 |> Map.put(String.trim(new_ap_id), String.trim(old_ap_id))
35 # First, refetch all the old users.
39 |> Enum.each(fn user ->
40 with ap_id when is_binary(ap_id) <- mapping[user.ap_id] do
41 # This fetches and updates the user.
42 User.get_or_fetch_by_ap_id(ap_id)
46 # Now, fix follow relationships.
49 where: fragment("? like ?", u.ap_id, "https://shitposter.club/users/%")
54 |> Enum.each(fn user ->
55 old_follower_address = User.ap_followers(user)
60 where: ^old_follower_address in u.following,
62 push: [following: ^user.follower_address]
66 Repo.update_all(query, [])
71 where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]),
76 "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)",
80 ^[user.follower_address]
85 recipients: ^user.follower_address
90 Repo.update_all(query, [])
95 where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]),
100 "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)",
104 ^[user.follower_address]
110 Repo.update_all(query, [])