Skip save callback when migrating data.

This commit is contained in:
Robert Waltemath 2013-06-24 10:36:14 +02:00
parent d081a2c66b
commit 3d1faa9ed3
2 changed files with 4 additions and 5 deletions

View file

@ -20,7 +20,7 @@ class Task < ActiveRecord::Base
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
before_save :exclude_from_periodic_task_group
before_save :exclude_from_periodic_task_group, if: :changed?, unless: :new_record?
after_save :update_ordergroup_stats
# Find all tasks, for which the current user should be responsible
@ -110,9 +110,8 @@ class Task < ActiveRecord::Base
end
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
end
self.periodic_task_group = nil
true
end
end

View file

@ -4,7 +4,7 @@ class MoveWeeklyTasks < ActiveRecord::Migration
task_group = PeriodicTaskGroup.create
puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}"
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
tasks = task_group.tasks.order(:due_date)
task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty?