]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/way_controller.rb
api06: Preliminary support for diff uploading. This will not return anything
[rails.git] / app / controllers / way_controller.rb
index a7f74e50c7e66e465581c3deb575a582df5670b2..fd01008fa511778aaf1e503a32ee6898c4df782b 100644 (file)
@@ -51,15 +51,9 @@ class WayController < ApplicationController
       new_way = Way.from_xml(request.raw_post)
 
       if new_way and new_way.id == way.id
-        if !new_way.preconditions_ok?
+        unless update_internal(way, new_way)
           render :text => "", :status => :precondition_failed
         else
-          way.user_id = @user.id
-          way.tags = new_way.tags
-          way.nds = new_way.nds
-          way.visible = true
-          way.save_with_history!
-
           render :nothing => true
         end
       else
@@ -70,6 +64,22 @@ class WayController < ApplicationController
     end
   end
 
+  def update_internal way, new_way
+    way = Way.find(new_way.id) if way.nil?
+
+    if !new_way.preconditions_ok?
+      return false
+    else
+      way.user_id = @user.id
+      way.tags = new_way.tags
+      way.nds = new_way.nds
+      way.visible = true
+      way.save_with_history!
+
+      return true
+    end
+  end
+
   # This is the API call to delete a way
   def delete
     begin