mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-18 12:52:52 +00:00
642528f455
* Update fix-duplicates task to 2022_02_10_153119 Also add support for Appeal to AccountMerging#merge_with! * Update fix-duplicates task to 2022_03_07_094650 * Update fix-duplicates task to 2022_03_09_213005 * Update fix-duplicates task to 2022_03_07_083603 * Update fix-duplicates task to 2022_03_10_060626 * Update fix-duplicates script to 2022_03_07_083603 * Update fix-duplicates task to 2022_03_10_060706 * Update fix-duplicates task to 2022_03_10_060959 * Silence CodeClimate
61 lines
2 KiB
Ruby
61 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module AccountMerging
|
|
extend ActiveSupport::Concern
|
|
|
|
def merge_with!(other_account)
|
|
# Since it's the same remote resource, the remote resource likely
|
|
# already believes we are following/blocking, so it's safe to
|
|
# re-attribute the relationships too. However, during the presence
|
|
# of the index bug users could have *also* followed the reference
|
|
# account already, therefore mass update will not work and we need
|
|
# to check for (and skip past) uniqueness errors
|
|
|
|
owned_classes = [
|
|
Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite,
|
|
Follow, FollowRequest, Block, Mute,
|
|
AccountModerationNote, AccountPin, AccountStat, ListAccount,
|
|
PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression,
|
|
Appeal
|
|
]
|
|
|
|
owned_classes.each do |klass|
|
|
klass.where(account_id: other_account.id).find_each do |record|
|
|
begin
|
|
record.update_attribute(:account_id, id)
|
|
rescue ActiveRecord::RecordNotUnique
|
|
next
|
|
end
|
|
end
|
|
end
|
|
|
|
target_classes = [
|
|
Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin,
|
|
AccountNote
|
|
]
|
|
|
|
target_classes.each do |klass|
|
|
klass.where(target_account_id: other_account.id).find_each do |record|
|
|
begin
|
|
record.update_attribute(:target_account_id, id)
|
|
rescue ActiveRecord::RecordNotUnique
|
|
next
|
|
end
|
|
end
|
|
end
|
|
|
|
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
|
|
record.update_attribute(:reference_account_id, id)
|
|
end
|
|
|
|
Appeal.where(account_warning_id: other_account.id).find_each do |record|
|
|
record.update_attribute(:account_warning_id, id)
|
|
end
|
|
|
|
# Some follow relationships have moved, so the cache is stale
|
|
Rails.cache.delete_matched("followers_hash:#{id}:*")
|
|
Rails.cache.delete_matched("relationships:#{id}:*")
|
|
Rails.cache.delete_matched("relationships:*:#{id}")
|
|
end
|
|
end
|