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 !
Another shot at fixing migration 42. Actually tested to work.
epall (author)
Thu Oct 09 07:14:26 -0700 2008
commit  a9a02896a021b652904990db3a60156193031e64
tree    4a606a95cb6d560418f6766b4c2f867fb07d7133
parent  b36ed968137183bb24b62c23236be9119da17547
...
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
39
...
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
0
@@ -6,34 +6,30 @@ class ChangeDatesToDatetimes < ActiveRecord::Migration
0
     change_column :recurring_todos, :end_date, :datetime
0
 
0
     User.all(:include => [:todos, :recurring_todos]).each do |user|
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
-      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
+      if !user.prefs ## ugly hack for strange edge-case of not having preferences object
0
+        user.instance_eval do
0
+          def at_midnight(date)
0
+            return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
0
+          end
0
+          def time
0
+            Time.zone.now
0
+          end
0
         end
0
+      end
0
+      user.todos.each do |todo|
0
+        todo[:show_from] = user.at_midnight(todo.show_from) unless todo.show_from.nil?
0
+        todo[:due] = user.at_midnight(todo.due) unless todo.due.nil?
0
+        todo.save_with_validation(false)
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
+      user.recurring_todos.each do |todo|
0
+        todo[:start_from] = user.at_midnight(todo.start_from) unless todo.start_from.nil?
0
+        todo[:end_date] = user.at_midnight(todo.end_date) unless todo.end_date.nil?
0
+        todo.save_with_validation(false)
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