mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
Another shot at fixing migration 42. Actually tested to work.
This commit is contained in:
parent
b36ed96813
commit
a9a02896a0
1 changed files with 19 additions and 23 deletions
|
|
@ -6,32 +6,28 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
|
||||||
change_column :recurring_todos, :end_date, :datetime
|
change_column :recurring_todos, :end_date, :datetime
|
||||||
|
|
||||||
User.all(:include => [:todos, :recurring_todos]).each do |user|
|
User.all(:include => [:todos, :recurring_todos]).each do |user|
|
||||||
if user.prefs
|
if !user.prefs ## ugly hack for strange edge-case of not having preferences object
|
||||||
user.todos.each do |todo|
|
user.instance_eval do
|
||||||
todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil?
|
def at_midnight(date)
|
||||||
todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil?
|
return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
|
||||||
end
|
end
|
||||||
|
def time
|
||||||
user.recurring_todos.each do |todo|
|
Time.zone.now
|
||||||
todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil?
|
end
|
||||||
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
|
end
|
||||||
end
|
user.todos.each do |todo|
|
||||||
end
|
todo[:show_from] = user.at_midnight(todo.show_from) unless todo.show_from.nil?
|
||||||
|
todo[:due] = user.at_midnight(todo.due) unless todo.due.nil?
|
||||||
|
todo.save_with_validation(false)
|
||||||
|
end
|
||||||
|
|
||||||
def at_midnight(date)
|
user.recurring_todos.each do |todo|
|
||||||
return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
|
todo[:start_from] = user.at_midnight(todo.start_from) unless todo.start_from.nil?
|
||||||
|
todo[:end_date] = user.at_midnight(todo.end_date) unless todo.end_date.nil?
|
||||||
|
todo.save_with_validation(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def self.down
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue