File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,9 +98,19 @@ def attach_alias!(alias_record, user: nil)
9898 def cleanup_orphaned_person ( person )
9999 return if person . user . present?
100100 return if Alias . where ( person_id : person . id ) . exists?
101+ reassign_authored_records ( person )
101102 person . destroy!
102103 end
103104
105+ def reassign_authored_records ( old_person )
106+ Topic . where ( creator_person_id : old_person . id ) . update_all ( creator_person_id : id )
107+ Topic . where ( last_sender_person_id : old_person . id ) . update_all ( last_sender_person_id : id )
108+ Message . where ( sender_person_id : old_person . id ) . update_all ( sender_person_id : id )
109+ Mention . where ( person_id : old_person . id ) . update_all ( person_id : id )
110+ TopicParticipant . where ( person_id : old_person . id ) . where . not ( topic_id : TopicParticipant . where ( person_id : id ) . select ( :topic_id ) ) . update_all ( person_id : id )
111+ TopicParticipant . where ( person_id : old_person . id ) . delete_all
112+ end
113+
104114 def merge_contributor_memberships_from ( other_person )
105115 other_person . contributor_memberships . find_each do |membership |
106116 ContributorMembership . find_or_create_by! ( person_id : id , contributor_type : membership . contributor_type ) do |record |
You can’t perform that action at this time.
0 commit comments