points = nodes_not_used_in_area.collect { |n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] }
# find the relations used by those nodes and ways
- relation_ids = Relation.find_for_nodes_and_ways(nodes_in_area.collect {|n| n.id}, way_ids).collect {|n| n.id}.uniq
+ relation_ids = (Relation.find_for_nodes_and_ways(nodes_in_area.collect {|n| n.id}, way_ids)).collect {|n| n.id}.uniq
[way_ids,points,relation_ids]
end
RAILS_DEFAULT_LOGGER.info(" Message: putway, id=#{originalway}")
- # -- Check for null IDs or short ways
+ # -- Check for null IDs, short ways or lats=90
points.each do |a|
if a[2]==0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end
+ if coord2lat(a[1],masterscale,basey)==90 then return -2,"Server error - node with lat -90 found in way #{originalway}." end
end
if points.length<2 then return -2,"Server error - way is only #{points.length} points long." end
# 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+way.abs.to_s+Time.new.to_i.to_s
+ db_uqn='unin'+(rand*100).to_i.to_s+uid.to_s+way.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
# which means the SWF needs to allocate new ids
# - if it's an invisible node, we can reuse the old node id
- # get node list from specified version of way,
- # and the _current_ lat/long/tags of each node
+ # ----- get node list from specified version of way,
+ # and the _current_ lat/long/tags of each node
row=ActiveRecord::Base.connection.select_one("SELECT timestamp FROM ways WHERE version=#{version} AND id=#{id}")
waytime=row['timestamp']
EOF
rows=ActiveRecord::Base.connection.select_all(sql)
- # if historic (full revert), get the old version of each node
- # - if it's in another way now, generate a new id
- # - if it's not in another way, use the old ID
+ # ----- if historic (full revert), get the old version of each node
+ # - if it's in another way now, generate a new id
+ # - if it's not in another way, use the old ID
+
if historic then
rows.each_index do |i|
sql=<<-EOF
SELECT latitude*0.0000001 AS latitude,longitude*0.0000001 AS longitude,tags,cwn.id AS currentway
FROM nodes n
- LEFT JOIN current_way_nodes cwn
- ON cwn.node_id=n.id
+ LEFT JOIN current_way_nodes cwn
+ ON cwn.node_id=n.id AND cwn.id!=#{id}
WHERE n.id=#{rows[i]['id']}
AND n.timestamp<="#{waytime}"
- AND cwn.id!=#{id}
- ORDER BY n.timestamp DESC
+ ORDER BY n.timestamp DESC
LIMIT 1
EOF
row=ActiveRecord::Base.connection.select_one(sql)
- unless row.nil? then
- nx=row['longitude'].to_f
- ny=row['latitude'].to_f
+ nx=row['longitude'].to_f
+ ny=row['latitude'].to_f
+ if (!row.nil?)
if (row['currentway'] && (nx!=rows[i]['longitude'].to_f or ny!=rows[i]['latitude'].to_f or row['tags']!=rows[i]['tags'])) then rows[i]['id']=-1 end
- rows[i]['longitude']=nx
- rows[i]['latitude' ]=ny
- rows[i]['tags' ]=row['tags']
- end
+ end
+ rows[i]['longitude']=nx
+ rows[i]['latitude' ]=ny
+ rows[i]['tags' ]=row['tags']
end
end
rows