X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ae142c554b0356aabc11dbe0f93482d361b32e4b..112950ca3afd95c8b63e69f7b580585529b6cbaf:/app/controllers/amf_controller.rb?ds=sidebyside diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 487067545..a2bb1b454 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -582,55 +582,35 @@ class AmfController < ApplicationController # does: deletes way from db and any constituent nodes not used elsewhere # also removes ways/nodes from any relations they're in # out: [0] 0 (success), [1] way id (unchanged) - def deleteway(args) #:doc: - - usertoken,way=args - RAILS_DEFAULT_LOGGER.info(" Message: deleteway, id=#{way}") + def deleteway(args) #:doc: + usertoken,way_id=args + RAILS_DEFAULT_LOGGER.info(" Message: deleteway, id=#{way_id}") uid=getuserid(usertoken) if !uid then return -1,"You are not logged in, so the way could not be deleted." end - way=way.to_i - db_uqn='unin'+(rand*100).to_i.to_s+uid.to_s+way.to_i.abs.to_s+Time.new.to_i.to_s # temp uniquenodes table name, typically 51 chars - db_now='@now'+(rand*100).to_i.to_s+uid.to_s+way.to_i.abs.to_s+Time.new.to_i.to_s # 'now' variable name, typically 51 chars + # FIXME + # the next bit removes the way from any relations + # the delete_with_relations_and_nodes_and_history method should do this, + # but at present it just throws a 'precondition failed' + way=way.to_i + db_now='@now'+(rand*100).to_i.to_s+uid.to_s+id.to_i.abs.to_s+Time.new.to_i.to_s + db_uqn='unin'+(rand*100).to_i.to_s+uid.to_s+way.to_i.abs.to_s+Time.new.to_i.to_s ActiveRecord::Base.connection.execute("SET #{db_now}=NOW()") - - # - delete any otherwise unused nodes - - createuniquenodes(way,db_uqn,[]) - - # unless (preserve.empty?) then - # ActiveRecord::Base.connection.execute("DELETE FROM #{db_uqn} WHERE node_id IN ("+preserve.join(',')+")") - # end - - sql=<<-EOF - INSERT INTO nodes (id,latitude,longitude,timestamp,user_id,visible,tile) - SELECT DISTINCT cn.id,cn.latitude,cn.longitude,#{db_now},#{uid},0,cn.tile - FROM current_nodes AS cn,#{db_uqn} - WHERE cn.id=node_id - EOF - ActiveRecord::Base.connection.insert(sql) - - sql=<<-EOF - UPDATE current_nodes AS cn, #{db_uqn} - SET cn.timestamp=#{db_now},cn.visible=0,cn.user_id=#{uid} - WHERE cn.id=node_id - EOF - ActiveRecord::Base.connection.update(sql) - - deleteuniquenoderelations(db_uqn,uid,db_now) + createuniquenodes(way,db_uqn,[]) + deleteuniquenoderelations(db_uqn,uid,db_now) + deleteitemrelations(way_id,'way',uid,db_now) ActiveRecord::Base.connection.execute("DROP TEMPORARY TABLE #{db_uqn}") + # end of FIXME - # - delete way - - ActiveRecord::Base.connection.insert("INSERT INTO ways (id,user_id,timestamp,visible) VALUES (#{way},#{uid},#{db_now},0)") - ActiveRecord::Base.connection.update("UPDATE current_ways SET user_id=#{uid},timestamp=#{db_now},visible=0 WHERE id=#{way}") - ActiveRecord::Base.connection.execute("DELETE FROM current_way_nodes WHERE id=#{way}") - ActiveRecord::Base.connection.execute("DELETE FROM current_way_tags WHERE id=#{way}") - deleteitemrelations(way,'way',uid,db_now) - [0,way] + # now delete the way + user = User.find(uid) + way = Way.find(way_id) + way.delete_with_relations_and_nodes_and_history(user) + return [0,way_id] end + def readwayquery(id,insistonvisible) #:doc: sql=<<-EOF SELECT latitude*0.0000001 AS latitude,longitude*0.0000001 AS longitude,current_nodes.id,tags,visible