X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/71606b34f0fa50ab340c85034f69e7357479b93c..d19ca7c44bc4811cb0cca046a10af31d534de86f:/app/models/way.rb diff --git a/app/models/way.rb b/app/models/way.rb index fe16e98c3..c65119235 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -61,7 +61,7 @@ class Way < ActiveRecord::Base user_display_name_cache = {} if user_display_name_cache.nil? - if user_display_name_cache and user_display_name_cache[self.user_id] + if user_display_name_cache and user_display_name_cache.key?(self.user_id) # use the cache if available elsif self.user.data_public? user_display_name_cache[self.user_id] = self.user.display_name @@ -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