+ # ----- getrelation
+ # Get a relation with all of it's tags, and member IDs
+ # The input is an array with the following components, in order:
+ # 0. relid - the ID of the relation to get
+ #
+ # The output is an array which contains:
+ # [0] relation id, [1] hash of tags, [2] list of members
+ def getrelation(args) #:doc:
+ relid = args[0]
+ relid = relid.to_i
+
+ RAILS_DEFAULT_LOGGER.info(" Message: getrel, id=#{relid}")
+
+ rel = Relation.find(relid)
+
+ [relid,rel.tags,rel.members]#nodes,ways]
+ end
+
+ # ----- getrelation
+ # save relation to the database
+ # in: [0] user token (string),
+ # [1] original relation id (may be negative),
+ # [2] hash of tags, [3] list of members,
+ # [4] visible
+ # out: [0] 0 (success), [1] original relation id (unchanged),
+ # [2] new relation id
+ def putrelation(args, renumberednodes, renumberedways) #:doc:
+ usertoken,relid,tags,members,visible=args
+ uid=getuserid(usertoken)
+ if !uid then return -1,"You are not logged in, so the point could not be saved." end
+
+ relid = relid.to_i
+ visible = visible.to_i
+
+ # create a new relation, or find the existing one
+ if relid <= 0
+ rel = Relation.new
+ else
+ rel = Relation.find(relid)
+ end
+
+ # check the members are all positive, and correctly type
+ typedmembers = []
+ members.each do |m|
+ mid = m[1].to_i
+ if mid < 0
+ mid = renumberednodes[mid] if m[0] == 'node'
+ mid = renumberedways[mid] if m[0] == 'way'
+ if mid < 0
+ return -2, "Negative ID unresolved"
+ end
+ end
+ typedmembers << [m[0], mid, m[2]]
+ end
+
+ # assign new contents
+ rel.members = typedmembers
+ rel.tags = tags
+ rel.visible = visible
+ rel.user_id = uid
+
+ # check it then save it
+ # BUG: the following is commented out because it always fails on my
+ # install. I think it's a Rails bug.
+
+ #if !rel.preconditions_ok?
+ # return -2, "Relation preconditions failed"
+ #else
+ rel.save_with_history!
+ #end
+
+ [0,relid,rel.id]
+ end
+