# shouldn't be possible to get race conditions.
Node.transaction do
check_consistency(self, new_node, user)
- if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ])
- raise OSM::APIPreconditionFailedError.new
- elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id])
- raise OSM::APIPreconditionFailedError.new
- else
- self.changeset_id = new_node.changeset_id
- self.visible = false
-
- # update the changeset with the deleted position
- changeset.update_bbox!(bbox)
-
- save_with_history!
- end
+ way = WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id",
+ :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?
+
+ rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id",
+ :conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id])
+ raise OSM::APIPreconditionFailedError.new("Node #{self.id} is still used by way #{way.id}.") unless rel.nil?
+
+ self.changeset_id = new_node.changeset_id
+ self.visible = false
+
+ # update the changeset with the deleted position
+ changeset.update_bbox!(bbox)
+
+ save_with_history!
end
end
Relation.transaction do
check_consistency(self, new_relation, user)
# This will check to see if this relation is used by another relation
- if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
- raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in another relation")
- end
+ rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
+ raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in relation #{rel.id}.") unless rel.nil?
+
self.changeset_id = new_relation.changeset_id
self.tags = {}
self.members = []
def update_from(new_relation, user)
check_consistency(self, new_relation, user)
- if !new_relation.preconditions_ok?
- raise OSM::APIPreconditionFailedError.new
+ unless preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot update relation #{self.id}: data or member data is invalid.")
end
self.changeset_id = new_relation.changeset_id
self.changeset = new_relation.changeset
def create_with_history(user)
check_create_consistency(self, user)
- if !self.preconditions_ok?
- raise OSM::APIPreconditionFailedError.new
+ unless self.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
end
self.version = 0
self.visible = true
def update_from(new_way, user)
check_consistency(self, new_way, user)
- if !new_way.preconditions_ok?
- raise OSM::APIPreconditionFailedError.new
+ unless new_way.preconditions_ok?
+ raise OSM::APIPreconditionFailedError("Cannot update way #{self.id}: data is invalid.")
end
self.changeset_id = new_way.changeset_id
def create_with_history(user)
check_create_consistency(self, user)
- if !self.preconditions_ok?
- raise OSM::APIPreconditionFailedError.new
+ unless self.preconditions_ok?
+ raise OSM::APIPreconditionFailedError("Cannot create way: data is invalid.")
end
self.version = 0
self.visible = true