@ -98,26 +98,22 @@ module Mastodon
owned_classes . each do | klass |
owned_classes . each do | klass |
klass . where ( account_id : other_account . id ) . find_each do | record |
klass . where ( account_id : other_account . id ) . find_each do | record |
begin
record . update_attribute ( :account_id , id )
record . update_attribute ( :account_id , id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
target_classes = [ Follow , FollowRequest , Block , Mute , AccountModerationNote , AccountPin ]
target_classes = [ Follow , FollowRequest , Block , Mute , AccountModerationNote , AccountPin ]
target_classes << AccountNote if ActiveRecord :: Base . connection . table_exists? ( :account_notes )
target_classes << AccountNote if ActiveRecord :: Base . connection . table_exists? ( :account_notes )
target_classes . each do | klass |
target_classes . each do | klass |
klass . where ( target_account_id : other_account . id ) . find_each do | record |
klass . where ( target_account_id : other_account . id ) . find_each do | record |
begin
record . update_attribute ( :target_account_id , id )
record . update_attribute ( :target_account_id , id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
if ActiveRecord :: Base . connection . table_exists? ( :canonical_email_blocks )
if ActiveRecord :: Base . connection . table_exists? ( :canonical_email_blocks )
CanonicalEmailBlock . where ( reference_account_id : other_account . id ) . find_each do | record |
CanonicalEmailBlock . where ( reference_account_id : other_account . id ) . find_each do | record |
@ -601,14 +597,12 @@ module Mastodon
owned_classes = [ ConversationMute , AccountConversation ]
owned_classes = [ ConversationMute , AccountConversation ]
owned_classes . each do | klass |
owned_classes . each do | klass |
klass . where ( conversation_id : duplicate_conv . id ) . find_each do | record |
klass . where ( conversation_id : duplicate_conv . id ) . find_each do | record |
begin
record . update_attribute ( :account_id , main_conv . id )
record . update_attribute ( :account_id , main_conv . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
end
end
def merge_custom_emojis! ( main_emoji , duplicate_emoji )
def merge_custom_emojis! ( main_emoji , duplicate_emoji )
owned_classes = [ AnnouncementReaction ]
owned_classes = [ AnnouncementReaction ]
@ -629,50 +623,40 @@ module Mastodon
owned_classes << Bookmark if ActiveRecord :: Base . connection . table_exists? ( :bookmarks )
owned_classes << Bookmark if ActiveRecord :: Base . connection . table_exists? ( :bookmarks )
owned_classes . each do | klass |
owned_classes . each do | klass |
klass . where ( status_id : duplicate_status . id ) . find_each do | record |
klass . where ( status_id : duplicate_status . id ) . find_each do | record |
begin
record . update_attribute ( :status_id , main_status . id )
record . update_attribute ( :status_id , main_status . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
StatusPin . where ( account_id : main_status . account_id , status_id : duplicate_status . id ) . find_each do | record |
StatusPin . where ( account_id : main_status . account_id , status_id : duplicate_status . id ) . find_each do | record |
begin
record . update_attribute ( :status_id , main_status . id )
record . update_attribute ( :status_id , main_status . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
Status . where ( in_reply_to_id : duplicate_status . id ) . find_each do | record |
Status . where ( in_reply_to_id : duplicate_status . id ) . find_each do | record |
begin
record . update_attribute ( :in_reply_to_id , main_status . id )
record . update_attribute ( :in_reply_to_id , main_status . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
Status . where ( reblog_of_id : duplicate_status . id ) . find_each do | record |
Status . where ( reblog_of_id : duplicate_status . id ) . find_each do | record |
begin
record . update_attribute ( :reblog_of_id , main_status . id )
record . update_attribute ( :reblog_of_id , main_status . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
def merge_tags! ( main_tag , duplicate_tag )
def merge_tags! ( main_tag , duplicate_tag )
[ FeaturedTag ] . each do | klass |
[ FeaturedTag ] . each do | klass |
klass . where ( tag_id : duplicate_tag . id ) . find_each do | record |
klass . where ( tag_id : duplicate_tag . id ) . find_each do | record |
begin
record . update_attribute ( :tag_id , main_tag . id )
record . update_attribute ( :tag_id , main_tag . id )
rescue ActiveRecord :: RecordNotUnique
rescue ActiveRecord :: RecordNotUnique
next
next
end
end
end
end
end
end
end
def find_duplicate_accounts
def find_duplicate_accounts
ActiveRecord :: Base . connection . select_all ( " SELECT string_agg(id::text, ',') AS ids FROM accounts GROUP BY lower(username), COALESCE(lower(domain), '') HAVING count(*) > 1 " )
ActiveRecord :: Base . connection . select_all ( " SELECT string_agg(id::text, ',') AS ids FROM accounts GROUP BY lower(username), COALESCE(lower(domain), '') HAVING count(*) > 1 " )