]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
Fill in the tile ID before saving a trace point. Also add appropriate
[rails.git] / app / models / way.rb
index c6316d330809992df17afad252f77922445ab4b3..c65119235372875d120c28f816e27dd3beb76ac6 100644 (file)
@@ -142,54 +142,53 @@ class Way < ActiveRecord::Base
     @tags[k] = v
   end
 
-  def save_with_history
-    begin
-      Way.transaction do
-        t = Time.now
-        self.timestamp = t
-        self.save!
+  def save_with_history!
+    t = Time.now
 
-        tags = self.tags
+    Way.transaction do
+      self.timestamp = t
+      self.save!
+    end
 
-        WayTag.delete_all(['id = ?', self.id])
+    WayTag.transaction do
+      tags = self.tags
 
-        tags.each do |k,v|
-          tag = WayTag.new
-          tag.k = k
-          tag.v = v
-          tag.id = self.id
-          tag.save!
-        end
+      WayTag.delete_all(['id = ?', self.id])
 
-        segs = self.segs
+      tags.each do |k,v|
+        tag = WayTag.new
+        tag.k = k
+        tag.v = v
+        tag.id = self.id
+        tag.save!
+      end
+    end
 
-        WaySegment.delete_all(['id = ?', self.id])
+    WaySegment.transaction do
+      segs = self.segs
 
-        i = 0
-        segs.each do |n|
-          seg = WaySegment.new
-          seg.id = self.id
-          seg.segment_id = n
-          seg.sequence_id = i
-          seg.save!
-          i += 1
-        end
+      WaySegment.delete_all(['id = ?', self.id])
 
-        old_way = OldWay.from_way(self)
-        old_way.timestamp = t
-        old_way.save_with_dependencies!
+      i = 1
+      segs.each do |n|
+        seg = WaySegment.new
+        seg.id = self.id
+        seg.segment_id = n
+        seg.sequence_id = i
+        seg.save!
+        i += 1
       end
-
-      return true
-    rescue
-      return nil
     end
+
+    old_way = OldWay.from_way(self)
+    old_way.timestamp = t
+    old_way.save_with_dependencies!
   end
 
   def preconditions_ok?
     return false if self.segs.empty?
     self.segs.each do |n|
-      segment = Segment.find(n)
+      segment = Segment.find(:first, :conditions => ["id = ?", n])
       unless segment and segment.visible and segment.preconditions_ok?
         return false
       end