From a358fa4d7427a9274e1350fbb6914cb79259dd8f Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Fri, 1 Nov 2024 13:23:12 +0900 Subject: [PATCH 1/2] skip Heart#validate_user validation when importing from vote_on_issues plugin --- app/models/heart.rb | 4 +++- lib/tasks/redmine_hearts.rake | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/heart.rb b/app/models/heart.rb index c811f80..f598d1c 100644 --- a/app/models/heart.rb +++ b/app/models/heart.rb @@ -24,9 +24,11 @@ class Heart < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecord : A belongs_to :heartable, :polymorphic => true belongs_to :user + attribute :skip_validate_user, :boolean + validates_presence_of :user validates_uniqueness_of :user_id, :scope => [:heartable_type, :heartable_id] - validate :validate_user + validate :validate_user, :unless => :skip_validate_user def self.of_projects(*args) projects = args.size > 0 ? args.shift : Project.none diff --git a/lib/tasks/redmine_hearts.rake b/lib/tasks/redmine_hearts.rake index 891fbf5..4b41498 100644 --- a/lib/tasks/redmine_hearts.rake +++ b/lib/tasks/redmine_hearts.rake @@ -100,6 +100,7 @@ namespace :redmine_hearts do :user => user, :created_at => datetime, :updated_at => datetime, + :skip_validate_user => true, ) end end From 075903dccd6abca2b8edaefa35f62c8da8b876ff Mon Sep 17 00:00:00 2001 From: "Yuya.Nishida" Date: Fri, 1 Nov 2024 13:47:54 +0900 Subject: [PATCH 2/2] skip invalid record data migration on VoteOnIssue --- lib/tasks/redmine_hearts.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/redmine_hearts.rake b/lib/tasks/redmine_hearts.rake index 4b41498..7d16227 100644 --- a/lib/tasks/redmine_hearts.rake +++ b/lib/tasks/redmine_hearts.rake @@ -88,7 +88,7 @@ namespace :redmine_hearts do num_of_heart_before_processing = Heart.count - VoteOnIssue.where('vote_val > 0').each do |vote| + VoteOnIssue.where('vote_val > 0').where.not(issue: nil, user: nil).each do |vote| issue = vote.issue user = vote.user datetime = vote.created_at || Time.now