1 class Changeset < ActiveRecord::Base
6 has_many :changeset_tags, :foreign_key => 'id'
8 def self.from_xml(xml, create=false)
16 doc.find('//osm/changeset').each do |pt|
18 cs.created_at = Time.now
21 pt.find('tag').each do |tag|
22 cs.add_tag_keyval(tag['k'], tag['v'])
25 rescue Exception => ex
26 print "noes "+ ex.to_s + "\n"
36 self.changeset_tags.each do |tag|
47 def add_tag_keyval(k, v)
48 @tags = Hash.new unless @tags
55 Changeset.transaction do
56 # fixme update modified_at time?
60 ChangesetTag.transaction do
62 ChangesetTag.delete_all(['id = ?', self.id])
65 tag = ChangesetTag.new
75 doc = OSM::API.new.get_xml_doc
76 doc.root << to_xml_node()
79 def to_xml_node(user_display_name_cache = nil)
80 el1 = XML::Node.new 'changeset'
81 el1['id'] = self.id.to_s
83 user_display_name_cache = {} if user_display_name_cache.nil?
85 if user_display_name_cache and user_display_name_cache.key?(self.user_id)
86 # use the cache if available
87 elsif self.user.data_public?
88 user_display_name_cache[self.user_id] = self.user.display_name
90 user_display_name_cache[self.user_id] = nil
93 el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
95 self.tags.each do |k,v|
96 el2 = XML::Node.new('tag')
102 el1['created_at'] = self.created_at.xmlschema
103 el1['open'] = self.open.to_s
105 # FIXME FIXME FIXME: This does not include changes yet! There is
106 # currently no changeset_id column in the tables as far as I can tell,
107 # so this is just a scaffold to build on, not a complete to_xml