1 class OldWay < ActiveRecord::Base
2 include ConsistencyValidations
5 self.table_name = "ways"
6 self.primary_keys = "way_id", "version"
8 # note this needs to be included after the table name changes, or
9 # the queries generated by Redactable will use the wrong table name.
14 belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id"
16 has_many :old_nodes, :class_name => 'OldWayNode', :foreign_key => [:way_id, :version]
17 has_many :old_tags, :class_name => 'OldWayTag', :foreign_key => [:way_id, :version]
19 validates_associated :changeset
21 def self.from_way(way)
23 old_way.visible = way.visible
24 old_way.changeset_id = way.changeset_id
25 old_way.timestamp = way.timestamp
26 old_way.way_id = way.id
27 old_way.version = way.version
29 old_way.tags = way.tags
33 def save_with_dependencies!
48 nd.id = [way_id, version, sequence]
56 @nds ||= old_nodes.order(:sequence_id).collect(&:node_id)
60 @tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
67 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
68 el = XML::Node.new 'way'
69 el['id'] = way_id.to_s
71 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
73 old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
74 node_el = XML::Node.new 'nd'
75 node_el['ref'] = nd.node_id.to_s
79 add_tags_to_xml_node(el, old_tags)
84 # Read full version of old way
85 # For get_nodes_undelete, uses same nodes, even if they've moved since
86 # For get_nodes_revert, allocates new ids
87 # Currently returns Potlatch-style array
88 # where [5] indicates whether latest version is usable as is (boolean)
89 # (i.e. is it visible? are we actually reverting to an earlier version?)
91 def get_nodes_undelete
94 [node.lon, node.lat, n, node.version, node.tags_as_hash, node.visible]
98 def get_nodes_revert(timestamp)
101 oldnode = OldNode.where('node_id = ? AND timestamp <= ?', n, timestamp).unredacted.order("timestamp DESC").first
102 curnode = Node.find(n)
104 reuse = curnode.visible
105 if oldnode.lat != curnode.lat || oldnode.lon != curnode.lon || oldnode.tags != curnode.tags
106 # node has changed: if it's in other ways, give it a new id
107 if curnode.ways - [way_id]
112 points << [oldnode.lon, oldnode.lat, id, curnode.version, oldnode.tags_as_hash, reuse]
117 # Temporary method to match interface to nodes
122 # Temporary method to match interface to ways
127 # Pretend we're not in any relations
128 def containing_relation_members
132 # check whether this element is the latest version - that is,
133 # has the same version as its "current" counterpart.
134 def is_latest_version?
135 current_way.version == version