public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
Make migration 42 more resilient: don't freak out when user has no prefs object
epall (author)
Sat Oct 04 10:41:37 -0700 2008
commit  24c2b57b4af66176b218f24394421cf4bf8b73f7
tree    f091c564b3b30a41c0ea01f1f1e77a2948b57027
parent  1118a582d7bd18c471821126c49bf8b6e000c76d
...
6
7
8
9
10
11
12
 
 
 
 
 
13
14
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
 
 
 
 
21
22
23
...
6
7
8
 
 
 
 
9
10
11
12
13
14
 
 
 
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -6,18 +6,33 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
0
     change_column :recurring_todos, :end_date, :datetime
0
 
0
     User.all(:include => [:todos, :recurring_todos]).each do |user|
0
-      user.todos.each do |todo|
0
-        todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil?
0
-        todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil?
0
-      end
0
+      if user.prefs
0
+        user.todos.each do |todo|
0
+          todo.update_attribute(:show_from, user.at_midnight(todo.show_from)) unless todo.show_from.nil?
0
+          todo.update_attribute(:due, user.at_midnight(todo.due)) unless todo.due.nil?
0
+        end
0
 
0
-      user.recurring_todos.each do |todo|
0
-        todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil?
0
-        todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil?
0
-      end
0
+        user.recurring_todos.each do |todo|
0
+          todo.update_attribute(:start_from, user.at_midnight(todo.start_from)) unless todo.start_from.nil?
0
+          todo.update_attribute(:end_date, user.at_midnight(todo.end_date)) unless todo.end_date.nil?
0
+        end
0
+      else # weird...no preferences for this user
0
+        user.todos.each do |todo|
0
+          todo.update_attribute(:show_from, at_midnight(todo.show_from)) unless todo.show_from.nil?
0
+          todo.update_attribute(:due, at_midnight(todo.due)) unless todo.due.nil?
0
+        end
0
+
0
+        user.recurring_todos.each do |todo|
0
+          todo.update_attribute(:start_from, at_midnight(todo.start_from)) unless todo.start_from.nil?
0
+          todo.update_attribute(:end_date, at_midnight(todo.end_date)) unless todo.end_date.nil?
0
+        end
0
     end
0
   end
0
 
0
+  def at_midnight(date)
0
+    return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
0
+  end
0
+
0
   def self.down
0
     change_column :todos, :show_from, :date
0
     change_column :todos, :due, :date

Comments