1 class Changeset < ActiveRecord::Base
6 has_many :changeset_tags, :foreign_key => 'id'
13 has_many :old_relations
15 def self.from_xml(xml, create=false)
23 doc.find('//osm/changeset').each do |pt|
25 cs.created_at = Time.now
28 pt.find('tag').each do |tag|
29 cs.add_tag_keyval(tag['k'], tag['v'])
32 rescue Exception => ex
33 print "noes "+ ex.to_s + "\n"
43 self.changeset_tags.each do |tag|
54 def add_tag_keyval(k, v)
55 @tags = Hash.new unless @tags
62 Changeset.transaction do
63 # fixme update modified_at time?
67 ChangesetTag.transaction do
69 ChangesetTag.delete_all(['id = ?', self.id])
72 tag = ChangesetTag.new
82 doc = OSM::API.new.get_xml_doc
83 doc.root << to_xml_node()
86 def to_xml_node(user_display_name_cache = nil)
87 el1 = XML::Node.new 'changeset'
88 el1['id'] = self.id.to_s
90 user_display_name_cache = {} if user_display_name_cache.nil?
92 if user_display_name_cache and user_display_name_cache.key?(self.user_id)
93 # use the cache if available
94 elsif self.user.data_public?
95 user_display_name_cache[self.user_id] = self.user.display_name
97 user_display_name_cache[self.user_id] = nil
100 el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
102 self.tags.each do |k,v|
103 el2 = XML::Node.new('tag')
109 el1['created_at'] = self.created_at.xmlschema
110 el1['open'] = self.open.to_s
112 # FIXME FIXME FIXME: This does not include changes yet! There is
113 # currently no changeset_id column in the tables as far as I can tell,
114 # so this is just a scaffold to build on, not a complete to_xml