From d71d26a3c90ba196dfc41043b73c53d4ca8f2398 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 22 Mar 2024 17:21:53 +0100 Subject: [PATCH] Reattribute notification-related records if possible when merging accounts (#29694) --- app/models/concerns/account/merging.rb | 10 ++++++++++ lib/mastodon/cli/maintenance.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/concerns/account/merging.rb b/app/models/concerns/account/merging.rb index e6b147482..bd8b16223 100644 --- a/app/models/concerns/account/merging.rb +++ b/app/models/concerns/account/merging.rb @@ -27,6 +27,16 @@ module Account::Merging end end + [ + Notification, NotificationPermission, NotificationRequest + ].each do |klass| + klass.where(from_account_id: other_account.id).reorder(nil).find_each do |record| + record.update_attribute(:from_account_id, id) + rescue ActiveRecord::RecordNotUnique + next + end + end + target_classes = [ Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin, AccountNote diff --git a/lib/mastodon/cli/maintenance.rb b/lib/mastodon/cli/maintenance.rb index 2e7c85707..d16d55eae 100644 --- a/lib/mastodon/cli/maintenance.rb +++ b/lib/mastodon/cli/maintenance.rb @@ -26,6 +26,9 @@ module Mastodon::CLI class ListAccount < ApplicationRecord; end class PollVote < ApplicationRecord; end class Mention < ApplicationRecord; end + class Notification < ApplicationRecord; end + class NotificationPermission < ApplicationRecord; end + class NotificationRequest < ApplicationRecord; end class AccountDomainBlock < ApplicationRecord; end class AnnouncementReaction < ApplicationRecord; end class FeaturedTag < ApplicationRecord; end @@ -108,6 +111,18 @@ module Mastodon::CLI end end + from_classes = [Notification] + from_classes << NotificationPermission if db_table_exists?(:notification_permissions) + from_classes << NotificationRequest if db_table_exists?(:notification_requests) + + from_classes.each do |klass| + klass.where(from_account_id: other_account.id).find_each do |record| + record.update_attribute(:from_account_id, id) + rescue ActiveRecord::RecordNotUnique + next + end + end + target_classes = [Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin] target_classes << AccountNote if db_table_exists?(:account_notes)