X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/bf31791f65fee149b660c1395d59204309f906fa..af1da641da1beec07e58c85330dfe836e83a7d26:/app/models/node.rb?ds=sidebyside diff --git a/app/models/node.rb b/app/models/node.rb index bd51d6c50..01b0f220e 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -130,14 +130,15 @@ class Node < ActiveRecord::Base # provide repeatable reads for the used-by checks. this means it # shouldn't be possible to get race conditions. Node.transaction do + self.lock! check_consistency(self, new_node, user) - way = WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", + way = WayNode.find(:first, :joins => :way, :conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ]) - raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by way #{way.id}.") unless way.nil? + raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by way #{way.way.id}.") unless way.nil? - rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", + rel = RelationMember.find(:first, :joins => :relation, :conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id]) - raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by relation #{rel.id}.") unless rel.nil? + raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by relation #{rel.relation.id}.") unless rel.nil? self.changeset_id = new_node.changeset_id self.visible = false @@ -150,25 +151,28 @@ class Node < ActiveRecord::Base end def update_from(new_node, user) - check_consistency(self, new_node, user) - - # update changeset first - self.changeset_id = new_node.changeset_id - self.changeset = new_node.changeset - - # update changeset bbox with *old* position first - changeset.update_bbox!(bbox); - - # FIXME logic needs to be double checked - self.latitude = new_node.latitude - self.longitude = new_node.longitude - self.tags = new_node.tags - self.visible = true - - # update changeset bbox with *new* position - changeset.update_bbox!(bbox); - - save_with_history! + Node.transaction do + self.lock! + check_consistency(self, new_node, user) + + # update changeset first + self.changeset_id = new_node.changeset_id + self.changeset = new_node.changeset + + # update changeset bbox with *old* position first + changeset.update_bbox!(bbox); + + # FIXME logic needs to be double checked + self.latitude = new_node.latitude + self.longitude = new_node.longitude + self.tags = new_node.tags + self.visible = true + + # update changeset bbox with *new* position + changeset.update_bbox!(bbox); + + save_with_history! + end end def create_with_history(user) @@ -267,7 +271,7 @@ class Node < ActiveRecord::Base ## # dummy method to make the interfaces of node, way and relation # more consistent. - def fix_placeholders!(id_map) + def fix_placeholders!(id_map, placeholder_id = nil) # nodes don't refer to anything, so there is nothing to do here end