]> git.openstreetmap.org Git - rails.git/commitdiff
Patching better 412 error messages from mis-commit on old api06 branch.
authorMatt Amos <zerebubuth@gmail.com>
Fri, 24 Apr 2009 10:08:15 +0000 (10:08 +0000)
committerMatt Amos <zerebubuth@gmail.com>
Fri, 24 Apr 2009 10:08:15 +0000 (10:08 +0000)
1  2 
app/models/relation.rb
app/models/way.rb

diff --combined app/models/relation.rb
index 464d1646cdedbec5523624fbabba614e2c46855b,2032e677046684067287dddb14e0f7eddecf528c..8a211b84f0498888108754c4b2e1bc70032a906c
@@@ -236,9 -236,9 +236,9 @@@ class Relation < ActiveRecord::Bas
      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?
++    unless new_relation.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
        self.timestamp = t
        self.save!
  
 -      tags = self.tags
 +      tags = self.tags.clone
        self.relation_tags.each do |old_tag|
          key = old_tag.k
          # if we can match the tags we currently have to the list
          # if any are different then set the flag and do the DB 
          # update.
          if tags.has_key? key 
 -          # rails 2.1 dirty handling should take care of making this
 -          # somewhat efficient... hopefully...
 -          old_tag.v = tags[key]
 -          tags_changed |= old_tag.changed?
 -          old_tag.save!
 +          tags_changed |= (old_tag.v != tags[key])
  
            # remove from the map, so that we can expect an empty map
            # at the end if there are no new tags
          else
            # this means a tag was deleted
            tags_changed = true
 -          RelationTag.delete_all ['id = ? and k = ?', self.id, old_tag.k]
          end
        end
        # if there are left-over tags then they are new and will have to
        # be added.
        tags_changed |= (not tags.empty?)
 -      tags.each do |k,v|
 +      RelationTag.delete_all(:id => self.id)
 +      self.tags.each do |k,v|
 +        logger.info "TAG added: #{k} -> #{v}"
          tag = RelationTag.new
          tag.k = k
          tag.v = v
          tag.save!
        end
        
 -      # reload, so that all of the members are accessible in their
 -      # new state.
 -      self.reload
 -
        # same pattern as before, but this time we're collecting the
        # changed members in an array, as the bounding box updates for
        # elements are per-element, not blanked on/off like for tags.
diff --combined app/models/way.rb
index eb4bf48f428d84c981945447700ab38be15a6529,cbbe6ada41f540eca762b22786e6e6aa45da362f..97f44c1171337375bb72166153f86be7f3837fff
@@@ -199,8 -199,8 +199,8 @@@ class Way < ActiveRecord::Bas
  
    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
    def preconditions_ok?
      return false if self.nds.empty?
      if self.nds.length > APP_CONFIG['max_number_of_way_nodes']
 -      raise OSM::APITooManyWayNodesError.new(self.nds.count, APP_CONFIG['max_number_of_way_nodes'])
 +      raise OSM::APITooManyWayNodesError.new(self.nds.length, APP_CONFIG['max_number_of_way_nodes'])
      end
      self.nds.each do |n|
        node = Node.find(:first, :conditions => ["id = ?", n])