]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
api06: Move version-checking into the models, raising an exception on mismatch
[rails.git] / app / models / way.rb
index 255f4329f89983c49f4a760a32df77caeafeb3f9..a6192e2d735e7ce128096a84cd32780da23db9d2 100644 (file)
@@ -31,6 +31,8 @@ class Way < ActiveRecord::Base
     if !create and pt['id'] != '0'
       way.id = pt['id'].to_i
     end
+    
+    way.version = pt['version']
 
     if create
       way.timestamp = Time.now
@@ -197,6 +199,8 @@ class Way < ActiveRecord::Base
   def update_from(new_way, user)
     if !new_way.preconditions_ok?
       raise OSM::APIPreconditionFailedError.new
+    elsif new_way.version != version
+      raise OSM::APIVersionMismatchError.new(new_way.version, version)
     else
       self.user_id = user.id
       self.tags = new_way.tags