+ # assign new contents
+ new_relation.members = typedmembers
+ new_relation.tags = tags
+ new_relation.visible = visible
+ new_relation.changeset_id = changeset_id
+ new_relation.version = version
+
+ # NOTE: id or relid here? id doesn't seem to be set above
+ if relid <= 0
+ # We're creating the node
+ new_relation.create_with_history(user)
+ elsif visible
+ # We're updating the node
+ relation.update_from(new_relation, user)
+ else
+ # We're deleting the node
+ relation.delete_with_history!(new_relation, user)
+ end
+ end # transaction
+
+ if id <= 0
+ return [0, relid, new_relation.id, new_relation.version]
+ else
+ return [0, relid, relation.id, relation.version]
+ end
+ rescue OSM::APIChangesetAlreadyClosedError => ex
+ return [-1, "The changeset #{ex.changeset.id} was closed at #{ex.changeset.closed_at}."]
+ rescue OSM::APIVersionMismatchError => ex
+ # Really need to check to see whether this is a server load issue, and the
+ # last version was in the same changeset, or belongs to the same user, then
+ # we can return something different
+ return [-3, "Sorry, someone else has changed this relation since you started editing. Please click the 'Edit' tab to reload the area."]
+ rescue OSM::APIAlreadyDeletedError => ex
+ return [-1, "The relation has already been deleted."]
+ rescue OSM::APIError => ex
+ # Some error that we don't specifically catch
+ return [-2, "Something really bad happened :-( ."]