fix indentation. Get teh api version from the constant, rather than hard coding it...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 10 Oct 2008 18:24:07 +0000 (18:24 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 10 Oct 2008 18:24:07 +0000 (18:24 +0000)
app/controllers/changeset_controller.rb
app/models/changeset.rb

index 8950126b4d86d77fff189a023b71ce85d7a89ed3..8151d3a677c3cadb85a7f796fd5460026cf8a8ea 100644 (file)
@@ -63,7 +63,7 @@ class ChangesetController < ApplicationController
       end
       changeset = Changeset.find(params[:id])
       changeset.open = false
-      changeset.save
+      changeset.save!
       render :nothing => true
     rescue ActiveRecord::RecordNotFound
       render :nothing => true, :status => :not_found
@@ -83,10 +83,13 @@ class ChangesetController < ApplicationController
 
     models = {"node"=>Node, "way"=>Way, "relation"=>Relation}
 
+    # FIXME shouldn't this be done through the 
+    # res = OSM::API.new.get_xml_doc
+    # as everything else is?
     res = XML::Document.new
     res.encoding = 'UTF-8'
     root = XML::Node.new 'osm'
-    root['version'] = '0.6'
+    root['version'] = API_VERSION
     root['creator'] = 'OpenStreetMap.org'
     res.root = root
 
@@ -95,69 +98,69 @@ class ChangesetController < ApplicationController
 
     Changeset.transaction do
       while p.read == 1
-       break if p.node_type == 15 # end element
-       next unless p.node_type == 1 # element
-
-       case p.name
-       when 'create':
-         while p.read == 1
-           break if p.node_type == 15 # end element
-           next unless p.node_type == 1 # element
-
-           model = models[p.name]
-           next if model.nil?
-
-           elem = XML::Node.new p.name
-           nd = p.expand; p.next
-           osm = model.from_xml_node(nd, true)
-           elem['old_id'] = nd['id']
-
-           case nd.name
-           when 'way':
-             fix_way(osm, node_ids)
-             raise OSM::APIPreconditionFailedError.new if !osm.preconditions_ok?
-           when 'relation':
-             fix_rel(osm, ids)
-             raise OSM::APIPreconditionFailedError.new if !osm.preconditions_ok?
-           end
-
-           create_prim ids[nd.name], osm, nd
-           elem['new_id'] = osm.id.to_s
-           elem['new_version'] = osm.version.to_s
-           root << elem
-         end
-       when 'modify':
-         while p.read == 1
-           break if p.node_type == 15 # end element
-           next unless p.node_type == 1 # element
-
-           model = models[p.name]
-           next if model.nil?
-
-           elem = XML::Node.new p.name
-           new_osm = model.from_xml_node(p.expand); p.next
-           osm = model.find(new_osm.id)
-           osm.update_from new_osm, @user
-           elem['old_id'] = elem['new_id'] = osm.id.to_s
-           elem['new_version'] = osm.version.to_s
-           root << elem
-         end
-       when 'delete':
-         while p.read == 1
-           break if p.node_type == 15 # end element
-           next unless p.node_type == 1 # element
-
-           model = models[p.name]
-           next if model.nil?
-
-           elem = XML::Node.new p.name
-           osm = model.find(p.expand['id']); p.next
-           osm.delete_with_history(@user)
-           elem['old_id'] = elem['new_id'] = osm.id.to_s
-           elem['new_version'] = osm.version.to_s
-           root << elem
-         end
-       end
+        break if p.node_type == 15 # end element
+        next unless p.node_type == 1 # element
+
+        case p.name
+        when 'create':
+            while p.read == 1
+            break if p.node_type == 15 # end element
+            next unless p.node_type == 1 # element
+
+            model = models[p.name]
+            next if model.nil?
+
+            elem = XML::Node.new p.name
+            nd = p.expand; p.next
+            osm = model.from_xml_node(nd, true)
+            elem['old_id'] = nd['id']
+
+            case nd.name
+            when 'way':
+                fix_way(osm, node_ids)
+              raise OSM::APIPreconditionFailedError.new if !osm.preconditions_ok?
+            when 'relation':
+                fix_rel(osm, ids)
+              raise OSM::APIPreconditionFailedError.new if !osm.preconditions_ok?
+            end
+
+            create_prim ids[nd.name], osm, nd
+            elem['new_id'] = osm.id.to_s
+            elem['new_version'] = osm.version.to_s
+            root << elem
+          end
+        when 'modify':
+            while p.read == 1
+            break if p.node_type == 15 # end element
+            next unless p.node_type == 1 # element
+
+            model = models[p.name]
+            next if model.nil?
+
+            elem = XML::Node.new p.name
+            new_osm = model.from_xml_node(p.expand); p.next
+            osm = model.find(new_osm.id)
+            osm.update_from new_osm, @user
+            elem['old_id'] = elem['new_id'] = osm.id.to_s
+            elem['new_version'] = osm.version.to_s
+            root << elem
+          end
+        when 'delete':
+            while p.read == 1
+            break if p.node_type == 15 # end element
+            next unless p.node_type == 1 # element
+
+            model = models[p.name]
+            next if model.nil?
+
+            elem = XML::Node.new p.name
+            osm = model.find(p.expand['id']); p.next
+            osm.delete_with_history(@user)
+            elem['old_id'] = elem['new_id'] = osm.id.to_s
+            elem['new_version'] = osm.version.to_s
+            root << elem
+          end
+        end
       end
     end
 
index 934d75e39de953d51e9bd98221e4b1815056be81..caa167c9eb19e52b32e277269820b056f918e962 100644 (file)
@@ -71,6 +71,7 @@ class Changeset < ActiveRecord::Base
 
     Changeset.transaction do
       # fixme update modified_at time?
+      # FIXME there is no modified_at time, should it be added
       self.save!
     end