X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/de29e9b3f59d7a06fbe2e32096328bd8a6ed2b3a..2b1bac1279e268c8e5fcca34c950f30d2c06ec1c:/app/models/way.rb diff --git a/app/models/way.rb b/app/models/way.rb index c95a12122..3284c47f3 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -2,11 +2,11 @@ # # Table name: current_ways # -# id :integer not null, primary key -# changeset_id :integer not null +# id :bigint(8) not null, primary key +# changeset_id :bigint(8) not null # timestamp :datetime not null # visible :boolean not null -# version :integer not null +# version :bigint(8) not null # # Indexes # @@ -39,11 +39,11 @@ class Way < ActiveRecord::Base has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation validates :id, :uniqueness => true, :presence => { :on => :update }, - :numericality => { :on => :update, :integer_only => true } + :numericality => { :on => :update, :only_integer => true } validates :version, :presence => true, - :numericality => { :integer_only => true } + :numericality => { :only_integer => true } validates :changeset_id, :presence => true, - :numericality => { :integer_only => true } + :numericality => { :only_integer => true } validates :timestamp, :presence => true validates :changeset, :associated => true validates :visible, :inclusion => [true, false] @@ -60,8 +60,8 @@ class Way < ActiveRecord::Base return Way.from_xml_node(pt, create) end raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.") - rescue LibXML::XML::Error, ArgumentError => ex - raise OSM::APIBadXMLError.new("way", xml, ex.message) + rescue LibXML::XML::Error, ArgumentError => e + raise OSM::APIBadXMLError.new("way", xml, e.message) end def self.from_xml_node(pt, create = false) @@ -106,44 +106,6 @@ class Way < ActiveRecord::Base way end - # Find a way given it's ID, and in a single SQL call also grab its nodes and tags - def to_xml - doc = OSM::API.new.get_xml_doc - doc.root << to_xml_node - doc - end - - def to_xml_node(visible_nodes = nil, changeset_cache = {}, user_display_name_cache = {}) - el = XML::Node.new "way" - el["id"] = id.to_s - - add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache) - - # make sure nodes are output in sequence_id order - ordered_nodes = [] - way_nodes.each do |nd| - if visible_nodes - # if there is a list of visible nodes then use that to weed out deleted nodes - ordered_nodes[nd.sequence_id] = nd.node_id.to_s if visible_nodes[nd.node_id] - else - # otherwise, manually go to the db to check things - ordered_nodes[nd.sequence_id] = nd.node_id.to_s if nd.node&.visible? - end - end - - ordered_nodes.each do |nd_id| - next unless nd_id && nd_id != "0" - - node_el = XML::Node.new "nd" - node_el["ref"] = nd_id - el << node_el - end - - add_tags_to_xml_node(el, way_tags) - - el - end - def nds @nds ||= way_nodes.collect(&:node_id) end @@ -206,7 +168,7 @@ class Way < ActiveRecord::Base def preconditions_ok?(old_nodes = []) return false if nds.empty? - raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES) if nds.length > MAX_NUMBER_OF_WAY_NODES + raise OSM::APITooManyWayNodesError.new(id, nds.length, Settings.max_number_of_way_nodes) if nds.length > Settings.max_number_of_way_nodes # check only the new nodes, for efficiency - old nodes having been checked last time and can't # be deleted when they're in-use.