]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
attempt fix for anon users
[rails.git] / app / models / way.rb
index bb99ba33e36e468bb214006637cb7b1da494f57d..e0a4450741202b2ed5f39e9c6a672f9abb1f8a48 100644 (file)
@@ -37,7 +37,7 @@ class Way < ActiveRecord::Base
         end
 
         pt.find('nd').each do |nd|
-          way.add_nd_num(nd['id'])
+          way.add_nd_num(nd['ref'])
         end
       end
     rescue
@@ -90,7 +90,7 @@ class Way < ActiveRecord::Base
     ordered_nodes.each do |nd_id|
       if nd_id and nd_id != '0'
         e = XML::Node.new 'nd'
-        e['id'] = nd_id
+        e['ref'] = nd_id
         el1 << e
       end
     end
@@ -142,49 +142,47 @@ 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])
 
-        nds = self.nds
+      tags.each do |k,v|
+        tag = WayTag.new
+        tag.k = k
+        tag.v = v
+        tag.id = self.id
+        tag.save!
+      end
+    end
 
-        WayNode.delete_all(['id = ?', self.id])
+    WayNode.transaction do
+      nds = self.nds
 
-        i = 1
-        nds.each do |n|
-          nd = WayNode.new
-          nd.id = self.id
-          nd.node_id = n
-          nd.sequence_id = i
-          nd.save!
-          i += 1
-        end
+      WayNode.delete_all(['id = ?', self.id])
 
-        old_way = OldWay.from_way(self)
-        old_way.timestamp = t
-        old_way.save_with_dependencies!
+      i = 1
+      nds.each do |n|
+        nd = WayNode.new
+        nd.id = self.id
+        nd.node_id = n
+        nd.sequence_id = i
+        nd.save!
+        i += 1
       end
-
-      return true
-    rescue => ex
-      puts ex
-      return nil
     end
+
+    old_way = OldWay.from_way(self)
+    old_way.timestamp = t
+    old_way.save_with_dependencies!
   end
 
   def preconditions_ok?