+ # 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)
+ 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
+ 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
+ end