mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
Make migration 42 more resilient: don't freak out when user has no prefs object
This commit is contained in:
parent
1118a582d7
commit
24c2b57b4a
1 changed files with 23 additions and 8 deletions
|
|
@ -6,6 +6,7 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
|
|||
change_column :recurring_todos, :end_date, :datetime
|
||||
|
||||
User.all(:include => [:todos, :recurring_todos]).each do |user|
|
||||
if user.prefs
|
||||
user.todos.each do |todo|
|
||||
todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil?
|
||||
todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil?
|
||||
|
|
@ -15,7 +16,21 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
|
|||
todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil?
|
||||
todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil?
|
||||
end
|
||||
else # weird...no preferences for this user
|
||||
user.todos.each do |todo|
|
||||
todo.update_attribute(:show_from, at_midnight(todo.show_from)) unless todo.show_from.nil?
|
||||
todo.update_attribute(:due, at_midnight(todo.due)) unless todo.due.nil?
|
||||
end
|
||||
|
||||
user.recurring_todos.each do |todo|
|
||||
todo.update_attribute(:start_from, at_midnight(todo.start_from)) unless todo.start_from.nil?
|
||||
todo.update_attribute(:end_date, at_midnight(todo.end_date)) unless todo.end_date.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def at_midnight(date)
|
||||
return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue