- # [0] version, [1] db timestamp, [2] visible 0 or 1,
- # [3] username or 'anonymous')
-
- def getway_history(wayid)
- history=[]
- sql=<<-EOF
- SELECT version,timestamp,visible,display_name,data_public
- FROM ways,users
- WHERE ways.id=#{wayid}
- AND ways.user_id=users.id
- AND ways.visible=1
- ORDER BY version DESC
- EOF
- histlist=ActiveRecord::Base.connection.select_all(sql)
- histlist.each { |row|
- if row['data_public'].to_i==1 then user=row['display_name'] else user='anonymous' end
- history<<[row['version'],row['timestamp'],row['visible'],user]
- }
- [history]
+ # [0] version, [1] db timestamp (string),
+ # [2] visible 0 or 1,
+ # [3] username or 'anonymous' (string))
+ def getway_history(args) #:doc:
+ wayid=args[0]
+ history=[]
+ sql=<<-EOF
+ SELECT version,timestamp,visible,display_name,data_public
+ FROM ways,users
+ WHERE ways.id=#{wayid}
+ AND ways.user_id=users.id
+ AND ways.visible=1
+ ORDER BY version DESC
+ EOF
+ histlist=ActiveRecord::Base.connection.select_all(sql)
+ histlist.each { |row|
+ if row['data_public'].to_i==1 then user=row['display_name'] else user='anonymous' end
+ history<<[row['version'],row['timestamp'],row['visible'],user]
+ }
+ [history]
+ end
+
+ # ----- 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]