X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/5d3ecffa28510c867665001a7615559a185869c6..87918595da1e1fad2ddd7aa62f9fc537dff657ff:/app/models/node.rb diff --git a/app/models/node.rb b/app/models/node.rb index a6814405c..edbbbc251 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -49,7 +49,7 @@ class Node < ActiveRecord::Base # Read in xml as text and return it's Node object representation def self.from_xml(xml, create = false) - p = XML::Parser.string(xml) + p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse doc.find("//osm/node").each do |pt| @@ -70,7 +70,7 @@ class Node < ActiveRecord::Base raise OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt["changeset"].nil? node.changeset_id = pt["changeset"].to_i - raise OSM::APIBadUserInput.new("The node is outside this world") unless node.in_world? + raise OSM::APIBadUserInput, "The node is outside this world" unless node.in_world? # version must be present unless creating raise OSM::APIBadXMLError.new("node", pt, "Version is required when updating") unless create || !pt["version"].nil? @@ -81,7 +81,7 @@ class Node < ActiveRecord::Base node.id = pt["id"].to_i # .to_i will return 0 if there is no number that can be parsed. # We want to make sure that there is no id with zero anyway - raise OSM::APIBadUserInput.new("ID of node cannot be zero when updating.") if node.id == 0 + raise OSM::APIBadUserInput, "ID of node cannot be zero when updating." if node.id.zero? end # We don't care about the time, as it is explicitly set on create/update/delete @@ -120,10 +120,10 @@ class Node < ActiveRecord::Base lock! check_consistency(self, new_node, user) ways = Way.joins(:way_nodes).where(:visible => true, :current_way_nodes => { :node_id => id }).order(:id) - raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by ways #{ways.collect(&:id).join(",")}.") unless ways.empty? + raise OSM::APIPreconditionFailedError, "Node #{id} is still used by ways #{ways.collect(&:id).join(',')}." unless ways.empty? rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Node", :member_id => id }).order(:id) - raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty? + raise OSM::APIPreconditionFailedError, "Node #{id} is still used by relations #{rels.collect(&:id).join(',')}." unless rels.empty? self.changeset_id = new_node.changeset_id self.tags = {} @@ -205,7 +205,7 @@ class Node < ActiveRecord::Base attr_writer :tags def add_tag_key_val(k, v) - @tags = {} unless @tags + @tags ||= {} # duplicate tags are now forbidden, so we can't allow values # in the hash to be overwritten. @@ -232,14 +232,18 @@ class Node < ActiveRecord::Base def save_with_history! t = Time.now.getutc + + self.version += 1 + self.timestamp = t + Node.transaction do - self.version += 1 - self.timestamp = t - save! + # clone the object before saving it so that the original is + # still marked as dirty if we retry the transaction + clone.save! # Create a NodeTag tags = self.tags - NodeTag.delete_all(:node_id => id) + NodeTag.where(:node_id => id).delete_all tags.each do |k, v| tag = NodeTag.new tag.node_id = id