X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6d07f5661a4530b334ab752044536e8bdb201b02..0c90905495a5d9fd40282456b4d4098da6adda48:/app/models/way.rb diff --git a/app/models/way.rb b/app/models/way.rb index b564a3317..e0a445074 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -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?