- # 1. original way id (unchanged),
- # 2. new way id,
- # 3. hash of renumbered nodes (old id=>new id),
- # 4. version
-
- def putway(renumberednodes, usertoken, changeset, originalway, points, attributes) #:doc:
-
- # -- Initialise and carry out checks
-
- user = getuser(usertoken)
- if !user then return -1,"You are not logged in, so the way could not be saved." end
-
- originalway = originalway.to_i
-
- points.each do |a|
- if a[2] == 0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end
- if a[1] == 90 then return -2,"Server error - node with lat -90 found in way #{originalway}." end
- end
-
- if points.length < 2 then return -2,"Server error - way is only #{points.length} points long." end
-
- # -- Get unique nodes
-
- if originalway <= 0
- uniques = []
- else
- way = Way.find(originalway)
- uniques = way.unshared_node_ids
- end
- new_way = Way.new
-
- # -- Compare nodes and save changes to any that have changed
-
- nodes = []
-
- points.each do |n|
- lon = n[0].to_f
- lat = n[1].to_f
- id = n[2].to_i
- version = n[3].to_i # FIXME which index does the version come in on????
- savenode = false
- # We always need a new node if we are saving it
- new_node = Node.new
-
-
- if renumberednodes[id]
- id = renumberednodes[id]
- elsif id <= 0
- # Create new node
- savenode = true
- else
- # Don't modify this node, make any changes you want to the new_node above
- node = Node.find(id)
- nodetags=node.tags
- nodetags.delete('created_by')
- if !fpcomp(lat, node.lat) or !fpcomp(lon, node.lon) or
- n[4] != nodetags or !node.visible?
- savenode = true
+ # 1. message,
+ # 2. original way id (unchanged),
+ # 3. new way id,
+ # 4. hash of renumbered nodes (old id=>new id),
+ # 5. way version,
+ # 6. hash of node versions (node=>version)
+
+ def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, pointlist, attributes, nodes, deletednodes) #:doc:
+ amf_handle_error("'putway' #{originalway}" ,'way',originalway) do
+ # -- Initialise
+
+ user = getuser(usertoken)
+ if !user then return -1,"You are not logged in, so the way could not be saved." end
+ unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
+ if pointlist.length < 2 then return -2,"Server error - way is only #{points.length} points long." end
+ if !tags_ok(attributes) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
+ attributes = strip_non_xml_chars attributes
+
+ originalway = originalway.to_i
+ pointlist.collect! {|a| a.to_i }
+
+ way=nil # this is returned, so scope it outside the transaction
+ nodeversions = {}
+ Way.transaction do
+
+ # -- Update each changed node
+
+ nodes.each do |a|
+ lon = a[0].to_f
+ lat = a[1].to_f
+ id = a[2].to_i
+ version = a[3].to_i
+
+ if id == 0 then return -2,"Server error - node with id 0 found in way #{originalway}." end
+ if lat== 90 then return -2,"Server error - node with latitude -90 found in way #{originalway}." end
+ if renumberednodes[id] then id = renumberednodes[id] end
+
+ node = Node.new
+ node.changeset_id = changeset_id
+ node.lat = lat
+ node.lon = lon
+ node.tags = a[4]
+
+ # fixup node tags in a way as well
+ if !tags_ok(node.tags) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
+ node.tags = strip_non_xml_chars node.tags
+
+ node.tags.delete('created_by')
+ node.version = version
+ if id <= 0
+ # We're creating the node
+ node.create_with_history(user)
+ renumberednodes[id] = node.id
+ nodeversions[node.id] = node.version
+ else
+ # We're updating an existing node
+ previous=Node.find(id)
+ node.id=id
+ previous.update_from(node, user)
+ nodeversions[previous.id] = previous.version
+ end