Skip save callback when migrating data.
This commit is contained in:
parent
d081a2c66b
commit
3d1faa9ed3
2 changed files with 4 additions and 5 deletions
|
@ -20,7 +20,7 @@ class Task < ActiveRecord::Base
|
||||||
validates_length_of :description, maximum: 250
|
validates_length_of :description, maximum: 250
|
||||||
validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic?, on: :create
|
validates :done, exclusion: { in: [true], message: 'erledigte Aufgaben können nicht wöchentlich wiederholt werden' }, if: :periodic?, on: :create
|
||||||
|
|
||||||
before_save :exclude_from_periodic_task_group
|
before_save :exclude_from_periodic_task_group, if: :changed?, unless: :new_record?
|
||||||
after_save :update_ordergroup_stats
|
after_save :update_ordergroup_stats
|
||||||
|
|
||||||
# Find all tasks, for which the current user should be responsible
|
# Find all tasks, for which the current user should be responsible
|
||||||
|
@ -110,9 +110,8 @@ class Task < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def exclude_from_periodic_task_group
|
def exclude_from_periodic_task_group
|
||||||
if changed? and not new_record? and not changed.include? 'periodic_task_group_id'
|
|
||||||
self.periodic_task_group = nil
|
self.periodic_task_group = nil
|
||||||
end
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ class MoveWeeklyTasks < ActiveRecord::Migration
|
||||||
task_group = PeriodicTaskGroup.create
|
task_group = PeriodicTaskGroup.create
|
||||||
puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}"
|
puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}"
|
||||||
workgroup.tasks.undone.each do |task|
|
workgroup.tasks.undone.each do |task|
|
||||||
task_group.tasks << task if weekly_task?(workgroup, task)
|
task.update_column(:periodic_task_group_id, task_group.id) if weekly_task?(workgroup, task)
|
||||||
end
|
end
|
||||||
tasks = task_group.tasks.order(:due_date)
|
tasks = task_group.tasks.order(:due_date)
|
||||||
task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty?
|
task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty?
|
||||||
|
|
Loading…
Reference in a new issue