- 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)
- ActiveRecord::Base.connection.execute("DROP TEMPORARY TABLE #{db_uqn}")
-
- # - 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]
- end
-
- def readwayquery(id,insistonvisible) #:doc:
- sql=<<-EOF
- SELECT latitude*0.0000001 AS latitude,longitude*0.0000001 AS longitude,current_nodes.id,tags,visible
- FROM current_way_nodes,current_nodes
- WHERE current_way_nodes.id=#{id}
- AND current_way_nodes.node_id=current_nodes.id
- EOF
- if insistonvisible then sql+=" AND current_nodes.visible=1 " end
- sql+=" ORDER BY sequence_id"
- ActiveRecord::Base.connection.select_all(sql)
- end
-
- # Get the latest version id of a way
- def getlastversion(id,version) #:doc:
- old_way = OldWay.find(:first, :conditions => ['visible=1 AND id=?' , id], :order => 'version DESC')
- old_way.version
- end
-
- def readwayquery_old(id,version,historic) #:doc:
- # Node handling on undelete (historic=false):
- # - always use the node specified, even if it's moved
-
- # Node handling on revert (historic=true):
- # - if it's a visible node, use a new node id (i.e. not mucking up the old one)
- # 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
-
- row=ActiveRecord::Base.connection.select_one("SELECT timestamp FROM ways WHERE version=#{version} AND id=#{id}")
- waytime=row['timestamp']
-
- sql=<<-EOF
- SELECT cn.id,visible,latitude*0.0000001 AS latitude,longitude*0.0000001 AS longitude,tags
- FROM way_nodes wn,current_nodes cn
- WHERE wn.version=#{version}
- AND wn.id=#{id}
- AND wn.node_id=cn.id
- ORDER BY sequence_id
- 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 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
- WHERE n.id=#{rows[i]['id']}
- AND n.timestamp<="#{waytime}"
- AND cwn.id!=#{id}
- 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
- 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