]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/amf_controller.rb
some more progress towards making amf_controller do version checking of nodes before...
[rails.git] / app / controllers / amf_controller.rb
index 45dbea4db0b797b2f6c06d0f5abc221b25e02615..14ad2147a299700bb270a43b5125bcdca3adf04a 100644 (file)
@@ -171,7 +171,7 @@ class AmfController < ApplicationController
   # return is of the form: 
   # [error_code, 
   #  [[way_id, way_version], ...],
-  #  [[node_id, lat, lon, [tags, ...]], ...],
+  #  [[node_id, lat, lon, [tags, ...], node_version], ...],
   #  [[rel_id, rel_version], ...]]
   # where the ways are any visible ways which refer to any visible
   # nodes in the bbox, nodes are any visible nodes in the bbox but not
@@ -200,7 +200,7 @@ class AmfController < ApplicationController
 
       # find the node ids in an area that aren't part of ways
       nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? }
-      points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags] }
+      points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags, n.version] }
 
       # find the relations used by those nodes and ways
       relations = Relation.find_for_nodes(nodes_in_area.collect { |n| n.id }, :conditions => {:visible => true}) +
@@ -678,9 +678,16 @@ class AmfController < ApplicationController
   end
 
   # Delete way and all constituent nodes. Also removes from any relations.
+  # Params:
+  # * The user token
+  # * the changeset id
+  # * the id of the way to change
+  # * the version of the way that was downloaded
+  # * a hash of the id and versions of all the nodes that are in the way, if any 
+  # of the nodes have been changed by someone else then, there is a problem!
   # Returns 0 (success), unchanged way id.
 
-  def deleteway(usertoken, changeset_id, way_id, version_id) #:doc:
+  def deleteway(usertoken, changeset_id, way_id, version_id, node_id_version) #:doc:
     user = getuser(usertoken)
     if user then return -1,"You are not logged in, so the way could not be deleted." end
     # Need a transaction so that if one item fails to delete, the whole delete fails.
@@ -695,7 +702,17 @@ class AmfController < ApplicationController
       end
       deleteitemrelations(way_id, 'way')
 
-      way.delete_with_relations_and_nodes_and_history(changeset_id.to_i)
+   
+      #way.delete_with_relations_and_nodes_and_history(changeset_id.to_i)
+      way.unshared_node_ids.each do |node_id|
+        # delete the node
+        node = Node.find(node_id)
+        delete_node = Node.new
+        delete_node.id = node_id
+        delete_node.version = node_id_version[node_id]
+        node.delete_with_history!(delete_node, user)
+      end
+      # delete the way
     end
     [0, way_id]
   end
@@ -704,16 +721,21 @@ class AmfController < ApplicationController
   # ====================================================================
   # Support functions
 
+  # delete a way and its nodes that aren't part of other ways
+  # this functionality used to be in the model, however it is specific to amf
+  # controller
+  #def delete_unshared_nodes(changeset_id, way_id)
+  
   # Remove a node or way from all relations
   # FIXME needs version, changeset, and user
-  def deleteitemrelations(objid, type) #:doc:
+  def deleteitemrelations(objid, type, version) #:doc:
     relations = RelationMember.find(:all, 
                                                                        :conditions => ['member_type = ? and member_id = ?', type, objid], 
                                                                        :include => :relation).collect { |rm| rm.relation }.uniq
 
     relations.each do |rel|
       rel.members.delete_if { |x| x[0] == type and x[1] == objid }
-      # FIXME need to create the new node/way based on the type.
+      # FIXME need to create the new relation
       new_rel = Relation.new
       new_rel.version = version
       new_rel.members = members