dont eager load tags (false primary key fucks all sorts of things up) and move delete way logic to model so that amf_controller can use it (plan is to do this with all of the methods. sigh.)
This commit is contained in:
parent
2ce8177333
commit
bbd769304c
5 changed files with 67 additions and 39 deletions
|
@ -475,21 +475,21 @@ class AmfController < ApplicationController
|
|||
end
|
||||
|
||||
# ----- getpoi
|
||||
# read POI from database
|
||||
# read POI from database
|
||||
# (only called on revert: POIs are usually read by whichways)
|
||||
# in: [0] node id, [1] baselong, [2] basey, [3] masterscale
|
||||
# does: reads POI
|
||||
# out: [0] id (unchanged), [1] projected long, [2] projected lat,
|
||||
# [3] hash of tags
|
||||
def getpoi(args) #:doc:
|
||||
id,baselong,basey,masterscale=args; id=id.to_i
|
||||
poi=ActiveRecord::Base.connection.select_one("SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lng,tags "+
|
||||
"FROM current_nodes WHERE visible=1 AND id=#{id}")
|
||||
if poi.nil? then return [nil,nil,nil,''] end
|
||||
[id,
|
||||
long2coord(poi['lng'].to_f,baselong,masterscale),
|
||||
lat2coord(poi['lat'].to_f,basey,masterscale),
|
||||
tag2array(poi['tags'])]
|
||||
id,baselong,basey,masterscale = args
|
||||
|
||||
n = Node.find(id.to_i)
|
||||
if n
|
||||
return [n.id, n.long_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash]
|
||||
else
|
||||
return [nil,nil,nil,'']
|
||||
end
|
||||
end
|
||||
|
||||
# ----- deleteway
|
||||
|
|
|
@ -69,30 +69,21 @@ class WayController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# This is the API call to delete a way
|
||||
def delete
|
||||
begin
|
||||
way = Way.find(params[:id])
|
||||
way.delete_with_relations_and_history(@user)
|
||||
|
||||
if way.visible
|
||||
# omg FIXME
|
||||
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='way' and member_id=?", params[:id]])
|
||||
render :text => "", :status => :precondition_failed
|
||||
else
|
||||
way.user_id = @user.id
|
||||
way.tags = []
|
||||
way.nds = []
|
||||
way.visible = false
|
||||
way.save_with_history!
|
||||
|
||||
render :nothing => true
|
||||
end
|
||||
else
|
||||
render :text => "", :status => :gone
|
||||
end
|
||||
# if we get here, all is fine, otherwise something will catch below.
|
||||
render :nothing => true
|
||||
return
|
||||
rescue OSM::APIAlreadyDeletedError
|
||||
render :text => "", :status => :gone
|
||||
rescue OSM::APIPreconditionFailedError
|
||||
render :text => "", :status => :precondition_failed
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :nothing => true, :status => :not_found
|
||||
rescue => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue