]> git.openstreetmap.org Git - rails.git/commitdiff
Fixing a bug in my foreign keys. I can now upload and download nodes and ways using...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 3 Oct 2008 17:09:58 +0000 (17:09 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Fri, 3 Oct 2008 17:09:58 +0000 (17:09 +0000)
app/controllers/node_controller.rb
app/controllers/way_controller.rb
app/models/node.rb
app/models/old_node.rb
app/models/old_way.rb
app/models/way.rb
db/migrate/020_add_changesets.rb

index 70bf597345c27044a3282c105c02f0c796dfce43..03ae64f41939a4c9f4e4dcd92895a3ab33044b40 100644 (file)
@@ -13,10 +13,13 @@ class NodeController < ApplicationController
   def create
     if request.put?
       node = Node.from_xml(request.raw_post, true)
   def create
     if request.put?
       node = Node.from_xml(request.raw_post, true)
+      # FIXME remove debug
+      logger.debug request.raw_post
+      logger.debug node
 
       if node
         node.version = 0
 
       if node
         node.version = 0
-        node.user_id = @user.id
+        #node.changeset_id = node.changeset
         node.visible = true
         node.save_with_history!
 
         node.visible = true
         node.save_with_history!
 
index cf1634fa55699cccdae1084536256c3f7c5fc4bd..17f166ddc85d7c50abd4a7d5ce7424546d259007 100644 (file)
@@ -12,11 +12,10 @@ class WayController < ApplicationController
       way = Way.from_xml(request.raw_post, true)
 
       if way
       way = Way.from_xml(request.raw_post, true)
 
       if way
-        if !way.preconditions_ok?
+        unless way.preconditions_ok?
           render :text => "", :status => :precondition_failed
         else
           way.version = 0
           render :text => "", :status => :precondition_failed
         else
           way.version = 0
-          way.user_id = @user.id
           way.save_with_history!
 
           render :text => way.id.to_s, :content_type => "text/plain"
           way.save_with_history!
 
           render :text => way.id.to_s, :content_type => "text/plain"
index 2efdb1bc93b58ce7f73c38bf67425c5123bb462d..2f3001a49a8c627c571f45bd2ed2c68711026a8f 100644 (file)
@@ -5,7 +5,7 @@ class Node < ActiveRecord::Base
 
   set_table_name 'current_nodes'
   
 
   set_table_name 'current_nodes'
   
-  validates_presence_of :user_id, :timestamp
+  validates_presence_of :changeset_id, :timestamp
   validates_inclusion_of :visible, :in => [ true, false ]
   validates_numericality_of :latitude, :longitude
   validate :validate_position
   validates_inclusion_of :visible, :in => [ true, false ]
   validates_numericality_of :latitude, :longitude
   validate :validate_position
@@ -77,6 +77,7 @@ class Node < ActiveRecord::Base
     node.version = pt['version']
     node.lat = pt['lat'].to_f
     node.lon = pt['lon'].to_f
     node.version = pt['version']
     node.lat = pt['lat'].to_f
     node.lon = pt['lon'].to_f
+    node.changeset_id = pt['changeset'].to_i
 
     return nil unless node.in_world?
 
 
     return nil unless node.in_world?
 
@@ -151,7 +152,8 @@ class Node < ActiveRecord::Base
       raise OSM::APIVersionMismatchError.new(new_node.version, version)
     end
 
       raise OSM::APIVersionMismatchError.new(new_node.version, version)
     end
 
-    self.user_id = user.id
+    # FIXME logic need looked at
+    self.changeset_id = user.id
     self.latitude = new_node.latitude 
     self.longitude = new_node.longitude
     self.tags = new_node.tags
     self.latitude = new_node.latitude 
     self.longitude = new_node.longitude
     self.tags = new_node.tags
@@ -173,15 +175,15 @@ class Node < ActiveRecord::Base
 
     user_display_name_cache = {} if user_display_name_cache.nil?
 
 
     user_display_name_cache = {} if user_display_name_cache.nil?
 
-    if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+    if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
       # use the cache if available
       # use the cache if available
-    elsif self.user.data_public?
-      user_display_name_cache[self.user_id] = self.user.display_name
+    elsif self.changeset.user.data_public?
+      user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
     else
     else
-      user_display_name_cache[self.user_id] = nil
+      user_display_name_cache[self.changeset.user_id] = nil
     end
 
     end
 
-    el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+    el1['user'] = user_display_name_cache[self.changeset.user_id] unless user_display_name_cache[self.changeset.user_id].nil?
 
     self.tags.each do |k,v|
       el2 = XML::Node.new('tag')
 
     self.tags.each do |k,v|
       el2 = XML::Node.new('tag')
@@ -219,6 +221,4 @@ class Node < ActiveRecord::Base
     @tags[k] = v
   end
 
     @tags[k] = v
   end
 
-
-
 end
 end
index 58a514bcd7b213b0081cbec3fab73eca91c0eb7d..d4d9f177575ab3e23b131afd6f93567cbe9fbb09 100644 (file)
@@ -3,7 +3,7 @@ class OldNode < ActiveRecord::Base
 
   set_table_name 'nodes'
   
 
   set_table_name 'nodes'
   
-  validates_presence_of :user_id, :timestamp
+  validates_presence_of :changeset_id, :timestamp
   validates_inclusion_of :visible, :in => [ true, false ]
   validates_numericality_of :latitude, :longitude
   validate :validate_position
   validates_inclusion_of :visible, :in => [ true, false ]
   validates_numericality_of :latitude, :longitude
   validate :validate_position
@@ -21,7 +21,7 @@ class OldNode < ActiveRecord::Base
     old_node.visible = node.visible
     old_node.tags = node.tags
     old_node.timestamp = node.timestamp
     old_node.visible = node.visible
     old_node.tags = node.tags
     old_node.timestamp = node.timestamp
-    old_node.user_id = node.user_id
+    old_node.changeset_id = node.changeset_id
     old_node.id = node.id
     old_node.version = node.version
     return old_node
     old_node.id = node.id
     old_node.version = node.version
     return old_node
@@ -38,7 +38,7 @@ class OldNode < ActiveRecord::Base
     el1['id'] = self.id.to_s
     el1['lat'] = self.lat.to_s
     el1['lon'] = self.lon.to_s
     el1['id'] = self.id.to_s
     el1['lat'] = self.lat.to_s
     el1['lon'] = self.lon.to_s
-    el1['user'] = self.user.display_name if self.user.data_public?
+    el1['user'] = self.changeset.user.display_name if self.changeset.user.data_public?
 
     self.tags.each do |k,v|
       el2 = XML::Node.new('tag')
 
     self.tags.each do |k,v|
       el2 = XML::Node.new('tag')
index 2820d9438a1e6868151e68a01595c0bed7f1610a..f297cfc1ac01ac3800436817dd59c614a011aaf5 100644 (file)
@@ -6,7 +6,7 @@ class OldWay < ActiveRecord::Base
   def self.from_way(way)
     old_way = OldWay.new
     old_way.visible = way.visible
   def self.from_way(way)
     old_way = OldWay.new
     old_way.visible = way.visible
-    old_way.user_id = way.user_id
+    old_way.changeset_id = way.changeset_id
     old_way.timestamp = way.timestamp
     old_way.id = way.id
     old_way.version = way.version
     old_way.timestamp = way.timestamp
     old_way.id = way.id
     old_way.version = way.version
index 8da9598537681773d41bb6b4966fed0ce3b892c2..7c6e9d06b6c1a05d48694464b30424c7f577da69 100644 (file)
@@ -3,6 +3,9 @@ class Way < ActiveRecord::Base
 
   set_table_name 'current_ways'
 
 
   set_table_name 'current_ways'
 
+  validates_presence_of :changeset_id, :timestamp
+  validates_inclusion_of :visible, :in => [ true, false ]
+  
   belongs_to :changeset
 
   has_many :old_ways, :foreign_key => 'id', :order => 'version'
   belongs_to :changeset
 
   has_many :old_ways, :foreign_key => 'id', :order => 'version'
@@ -37,13 +40,14 @@ class Way < ActiveRecord::Base
     end
     
     way.version = pt['version']
     end
     
     way.version = pt['version']
+    way.changeset_id = pt['changeset']
 
     if create
       way.timestamp = Time.now
       way.visible = true
     else
       if pt['timestamp']
 
     if create
       way.timestamp = Time.now
       way.visible = true
     else
       if pt['timestamp']
-       way.timestamp = Time.parse(pt['timestamp'])
+        way.timestamp = Time.parse(pt['timestamp'])
       end
     end
 
       end
     end
 
@@ -84,15 +88,15 @@ class Way < ActiveRecord::Base
 
     user_display_name_cache = {} if user_display_name_cache.nil?
 
 
     user_display_name_cache = {} if user_display_name_cache.nil?
 
-    if user_display_name_cache and user_display_name_cache.key?(self.user_id)
+    if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
       # use the cache if available
       # use the cache if available
-    elsif self.user.data_public?
-      user_display_name_cache[self.user_id] = self.user.display_name
+    elsif self.changeset.user.data_public?
+      user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
     else
     else
-      user_display_name_cache[self.user_id] = nil
+      user_display_name_cache[self.changeset.user_id] = nil
     end
 
     end
 
-    el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil?
+    el1['user'] = user_display_name_cache[self.changeset.user_id] unless user_display_name_cache[self.changeset.user_id].nil?
 
     # make sure nodes are output in sequence_id order
     ordered_nodes = []
 
     # make sure nodes are output in sequence_id order
     ordered_nodes = []
index c21b507820f283176473a70c07936597be4ee88b..75a909e8038606532b76d987480f36d0891b9f0d 100644 (file)
@@ -38,7 +38,7 @@ class AddChangesets < ActiveRecord::Migration
     @@conv_user_tables.each { |tbl|
       rename_column tbl, :user_id, :changeset_id
       #foreign keys too
     @@conv_user_tables.each { |tbl|
       rename_column tbl, :user_id, :changeset_id
       #foreign keys too
-      add_foreign_key tbl, [:changeset_id], :users, [:id]
+      add_foreign_key tbl, [:changeset_id], :changesets, [:id]
     }
   end
 
     }
   end