def create
if request.put?
node = Node.from_xml(request.raw_post, true)
+ # FIXME remove debug
+ logger.debug request.raw_post
+ logger.debug node
if node
node.version = 0
- node.user_id = @user.id
+ #node.changeset_id = node.changeset
node.visible = true
node.save_with_history!
way = Way.from_xml(request.raw_post, true)
if way
- if !way.preconditions_ok?
+ unless way.preconditions_ok?
render :text => "", :status => :precondition_failed
else
way.version = 0
- way.user_id = @user.id
way.save_with_history!
render :text => way.id.to_s, :content_type => "text/plain"
set_table_name 'current_nodes'
- validates_presence_of :user_id, :timestamp
+ validates_presence_of :changeset_id, :timestamp
validates_inclusion_of :visible, :in => [ true, false ]
validates_numericality_of :latitude, :longitude
validate :validate_position
node.version = pt['version']
node.lat = pt['lat'].to_f
node.lon = pt['lon'].to_f
+ node.changeset_id = pt['changeset'].to_i
return nil unless node.in_world?
raise OSM::APIVersionMismatchError.new(new_node.version, version)
end
- self.user_id = user.id
+ # FIXME logic need looked at
+ self.changeset_id = user.id
self.latitude = new_node.latitude
self.longitude = new_node.longitude
self.tags = new_node.tags
user_display_name_cache = {} if user_display_name_cache.nil?
- if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+ if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
# use the cache if available
- elsif self.user.data_public?
- user_display_name_cache[self.user_id] = self.user.display_name
+ elsif self.changeset.user.data_public?
+ user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
else
- user_display_name_cache[self.user_id] = nil
+ user_display_name_cache[self.changeset.user_id] = nil
end
- el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+ el1['user'] = user_display_name_cache[self.changeset.user_id] unless user_display_name_cache[self.changeset.user_id].nil?
self.tags.each do |k,v|
el2 = XML::Node.new('tag')
@tags[k] = v
end
-
-
end
set_table_name 'nodes'
- validates_presence_of :user_id, :timestamp
+ validates_presence_of :changeset_id, :timestamp
validates_inclusion_of :visible, :in => [ true, false ]
validates_numericality_of :latitude, :longitude
validate :validate_position
old_node.visible = node.visible
old_node.tags = node.tags
old_node.timestamp = node.timestamp
- old_node.user_id = node.user_id
+ old_node.changeset_id = node.changeset_id
old_node.id = node.id
old_node.version = node.version
return old_node
el1['id'] = self.id.to_s
el1['lat'] = self.lat.to_s
el1['lon'] = self.lon.to_s
- el1['user'] = self.user.display_name if self.user.data_public?
+ el1['user'] = self.changeset.user.display_name if self.changeset.user.data_public?
self.tags.each do |k,v|
el2 = XML::Node.new('tag')
def self.from_way(way)
old_way = OldWay.new
old_way.visible = way.visible
- old_way.user_id = way.user_id
+ old_way.changeset_id = way.changeset_id
old_way.timestamp = way.timestamp
old_way.id = way.id
old_way.version = way.version
set_table_name 'current_ways'
+ validates_presence_of :changeset_id, :timestamp
+ validates_inclusion_of :visible, :in => [ true, false ]
+
belongs_to :changeset
has_many :old_ways, :foreign_key => 'id', :order => 'version'
end
way.version = pt['version']
+ way.changeset_id = pt['changeset']
if create
way.timestamp = Time.now
way.visible = true
else
if pt['timestamp']
- way.timestamp = Time.parse(pt['timestamp'])
+ way.timestamp = Time.parse(pt['timestamp'])
end
end
user_display_name_cache = {} if user_display_name_cache.nil?
- if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+ if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
# use the cache if available
- elsif self.user.data_public?
- user_display_name_cache[self.user_id] = self.user.display_name
+ elsif self.changeset.user.data_public?
+ user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
else
- user_display_name_cache[self.user_id] = nil
+ user_display_name_cache[self.changeset.user_id] = nil
end
- el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+ el1['user'] = user_display_name_cache[self.changeset.user_id] unless user_display_name_cache[self.changeset.user_id].nil?
# make sure nodes are output in sequence_id order
ordered_nodes = []
@@conv_user_tables.each { |tbl|
rename_column tbl, :user_id, :changeset_id
#foreign keys too
- add_foreign_key tbl, [:changeset_id], :users, [:id]
+ add_foreign_key tbl, [:changeset_id], :changesets, [:id]
}
end