Skip to content

Commit

Permalink
Merge pull request #53 from nishidayuya/refine_migrate_from_vote_on_i…
Browse files Browse the repository at this point in the history
…ssues_task_based_on_redmine6-rails7

Refine redmine_hearts:migrate_from_vote_on_issues task (for redmine6-rails7 branch)
  • Loading branch information
cat-in-136 authored Nov 26, 2024
2 parents 1455710 + 075903d commit 81bc7c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/heart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/redmine_hearts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -100,6 +100,7 @@ namespace :redmine_hearts do
:user => user,
:created_at => datetime,
:updated_at => datetime,
:skip_validate_user => true,
)
end
end
Expand Down

0 comments on commit 81bc7c1

Please sign in to comment.