diff --git a/Changelog.md b/Changelog.md index 4d0a518a5..05094101b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -26,6 +26,7 @@ * Fix local migration run without old private key [#7558](https://github.com/diaspora/diaspora/pull/7558) * Fix export not downloadable because the filename was resetted on access [#7622](https://github.com/diaspora/diaspora/pull/7622) * Delete invalid oEmbed caches with binary titles [#7620](https://github.com/diaspora/diaspora/pull/7620) +* Delete invalid diaspora IDs from friendica [#7630](https://github.com/diaspora/diaspora/pull/7630) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) diff --git a/app/models/aspect_membership.rb b/app/models/aspect_membership.rb index f7d042a99..18c5869bb 100644 --- a/app/models/aspect_membership.rb +++ b/app/models/aspect_membership.rb @@ -5,7 +5,6 @@ # the COPYRIGHT file. class AspectMembership < ApplicationRecord - belongs_to :aspect belongs_to :contact has_one :user, :through => :contact diff --git a/app/models/notification_actor.rb b/app/models/notification_actor.rb index 6bdfe48bd..9b1f30796 100644 --- a/app/models/notification_actor.rb +++ b/app/models/notification_actor.rb @@ -5,8 +5,6 @@ # the COPYRIGHT file. class NotificationActor < ApplicationRecord - belongs_to :notification belongs_to :person - end diff --git a/db/migrate/20170928233609_cleanup_invalid_diaspora_ids.rb b/db/migrate/20170928233609_cleanup_invalid_diaspora_ids.rb new file mode 100644 index 000000000..f88fec22b --- /dev/null +++ b/db/migrate/20170928233609_cleanup_invalid_diaspora_ids.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class CleanupInvalidDiasporaIds < ActiveRecord::Migration[5.1] + def up + ids = Person.where("diaspora_handle LIKE '%@%/%'").ids + return if ids.empty? + + AspectMembership.joins(:contact).where(contacts: {person_id: ids}).delete_all + + Person.where(id: ids).each do |person| + destroy_notifications_for_person(person) + person.destroy + end + end + + def destroy_notifications_for_person(person) + Notification.joins(:notification_actors).where(notification_actors: {person_id: person.id}).each do |notification| + if notification.notification_actors.count > 1 + notification.notification_actors.where(person_id: person.id).delete_all + else + notification.destroy + end + end + end +end