X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/78b440ffc1e0448f8a6d73c8821dd58634ffb475..06a3213acdaab8d321ecbc4f1af47b9907bb5649:/app/models/way.rb diff --git a/app/models/way.rb b/app/models/way.rb index bb99ba33e..e0a445074 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -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?