From: Shaun McDonald Date: Thu, 3 Jul 2008 13:06:24 +0000 (+0000) Subject: Merge changes from trunk 7673:8632. X-Git-Tag: live~7605^2~325 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5f8ab9e9244550b20b8d3bd97b3567df7020d06d Merge changes from trunk 7673:8632. --- 5f8ab9e9244550b20b8d3bd97b3567df7020d06d diff --cc app/models/relation.rb index 984732c71,9ee118f6e..eb3b06a13 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@@ -205,37 -181,19 +185,49 @@@ class Relation < ActiveRecord::Bas end end + def delete_with_history(user) + if self.visible + if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='relation' and member_id=?", self.id ]) + raise OSM::APIPreconditionFailedError.new + else + self.user_id = user.id + self.tags = [] + self.members = [] + self.visible = false + save_with_history! + end + else + raise OSM::APIAlreadyDeletedError.new + end + end + + def update_from(new_relation, user) + if !new_relation.preconditions_ok? + raise OSM::APIPreconditionFailedError.new + elsif new_relation.version != version + raise OSM::APIVersionMismatchError.new(new_relation.version, version) + else + self.user_id = user.id + self.tags = new_relation.tags + self.members = new_relation.members + self.visible = true + save_with_history! + end + end + def preconditions_ok? + # These are hastables that store an id in the index of all + # the nodes/way/relations that have already been added. + # Once we know the id of the node/way/relation exists + # we check to see if it is already existing in the hashtable + # if it does, then we return false. Otherwise + # we add it to the relevant hash table, with the value true.. + # Thus if you have nodes with the ids of 50 and 1 already in the + # relation, then the hash table nodes would contain: + # => {50=>true, 1=>true} + nodes = Hash.new + ways = Hash.new + relations = Hash.new self.members.each do |m| if (m[0] == "node") n = Node.find(:first, :conditions => ["id = ?", m[1]]) diff --cc app/models/way.rb index ea027fb47,64b11cf67..34afc6585 --- a/app/models/way.rb +++ b/app/models/way.rb @@@ -267,7 -254,12 +271,12 @@@ class Way < ActiveRecord::Bas self.user_id = user.id - self.delete_with_relations_and_history(user) + self.delete_with_history(user) end + + # Temporary method to match interface to nodes + def tags_as_hash + return self.tags + end end diff --cc config/environment.rb index 8aaab7302,495f94d80..fb7573d2a --- a/config/environment.rb +++ b/config/environment.rb @@@ -12,11 -11,16 +11,16 @@@ RAILS_GEM_VERSION = '2.0.2' unless defi SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org' # Application constants needed for routes.rb - must go before Initializer call -API_VERSION = ENV['OSM_API_VERSION'] || '0.5' +API_VERSION = ENV['OSM_API_VERSION'] || '0.6' - # Set to :readonly to put the API in read-only mode or :offline to - # take it completely offline - API_STATUS = :online + # Set application status - possible settings are: + # + # :online - online and operating normally + # :api_readonly - site online but API in read-only mode + # :api_offline - site online but API offline + # :database_offline - database offline with site in emergency mode + # + OSM_STATUS = :online # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot')