X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/2b8bde9055f0cfdf7d261382cd40980d72bae188..c54471ee33f79b7119eb284b03a845813a058876:/app/controllers/amf_controller.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 80472fe25..4103ceda0 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -284,7 +284,13 @@ class AmfController < ApplicationController # 3. hash of tags, # 4. version, # 5. is this the current, visible version? (boolean) - + # + # *** FIXME: + # Should work by timestamp, not version (so that we can recover versions when + # a node has been changed, but not the enclosing way) + # Use strptime (http://www.ruby-doc.org/core/classes/DateTime.html) to + # to turn string back into timestamp. + def getway_old(id, version) #:doc: if version < 0 old_way = OldWay.find(:first, :conditions => ['visible = ? AND id = ?', true, id], :order => 'version DESC') @@ -305,20 +311,49 @@ class AmfController < ApplicationController # Find history of a way. Returns 'way', id, and # an array of previous versions. + # + # *** FIXME: + # Should look for changes in constituent nodes as well, + # and return timestamps. + # Heuristic: Find all nodes that have ever been part of the way; + # get a list of their revision dates; add revision dates of the way; + # sort and collapse list (to within 2 seconds); trim all dates before the + # start dateƊof the way. def getway_history(wayid) #:doc: - begin - history = Way.find(wayid).old_ways.reverse.collect do |old_way| - user_object = old_way.changeset.user - user = user_object.data_public? ? user_object.display_name : 'anonymous' - uid = user_object.data_public? ? user_object.id : 0 - [old_way.version, old_way.timestamp.strftime("%d %b %Y, %H:%M"), old_way.visible ? 1 : 0, user, uid] + + # Find list of revision dates for way and all constituent nodes + revdates=[] + Way.find(wayid).old_ways.collect do |a| + revdates.push(a.timestamp) + a.nds.each do |n| + Node.find(n).old_nodes.collect do |o| + revdates.push(o.timestamp) + end end + end + waycreated=revdates[0] + revdates.uniq! + revdates.sort! - return ['way',wayid,history] - rescue ActiveRecord::RecordNotFound - return ['way', wayid, []] + # Remove any dates (from nodes) before first revision date of way + revdates.delete_if { |d| dversion) - def putway(renumberednodes, usertoken, changeset, version, originalway, pointlist, attributes, nodes) #:doc: + def putway(renumberednodes, usertoken, changeset, wayversion, originalway, pointlist, attributes, nodes) #:doc: # -- Initialise @@ -567,7 +602,7 @@ class AmfController < ApplicationController new_way.tags = attributes new_way.nds = pointlist new_way.changeset_id = changeset - new_way.version = version + new_way.version = wayversion if originalway <= 0 new_way.create_with_history(user) way=new_way # so we can get way.id and way.version