- # 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, version, 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
-
- Way.transaction do
- 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]
- end
- if 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
- end
- end
-
- if savenode
- new_node.changeset_id = changeset
- new_node.lat = lat
- new_node.lon = lon
- new_node.tags = n[4]
- new_node.version = version
+ # 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 changed node versions (node=>version)
+ # 7. hash of deleted 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)
+ return -1, "You are not logged in, so the way could not be saved." unless user
+ return -1, t("application.setup_user_auth.blocked") if user.blocks.active.exists?
+ return -1, "You must accept the contributor terms before you can edit." if REQUIRE_TERMS_AGREED && user.terms_agreed.nil?
+
+ return -2, "Server error - way is only #{pointlist.length} points long." if pointlist.length < 2
+
+ return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." unless tags_ok(attributes)
+ attributes = strip_non_xml_chars attributes
+
+ originalway = originalway.to_i
+ pointlist.collect!(&: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
+
+ return -2, "Server error - node with id 0 found in way #{originalway}." if id.zero?
+ return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90
+
+ id = renumberednodes[id] if renumberednodes[id]
+
+ 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
+ return -1, "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." unless tags_ok(node.tags)
+ node.tags = strip_non_xml_chars node.tags
+
+ node.tags.delete("created_by")
+ node.version = version