X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/990dcedc4cbcf176c9427a358bd5e162b19ec27d..eff9fa3b00379f8306fa25e1ea52504cd75c1161:/app/controllers/trace_controller.rb diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 91ae92b05..0c4fc9e58 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -48,8 +48,9 @@ class TraceController < ApplicationController if params[:tag] @tag = params[:tag] - conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)" - conditions << @tag + + files = Tracetag.find_all_by_tag(params[:tag]).collect { |tt| tt.gpx_id } + conditions[0] += " AND gpx_files.id IN (#{files.join(',')})" end conditions[0] += " AND gpx_files.visible = 1" @@ -292,20 +293,37 @@ class TraceController < ApplicationController private def do_create(file, tags, description, public) + # Sanitise the user's filename name = file.original_filename.gsub(/[^a-zA-Z0-9.]/, '_') + + # Get a temporary filename... filename = "/tmp/#{rand}" + # ...and save the uploaded file to that location File.open(filename, "w") { |f| f.write(file.read) } - @trace = Trace.new({:name => name, :tagstring => tags, - :description => description, :public => public}) - @trace.inserted = false - @trace.user = @user - @trace.timestamp = Time.now - + # Create the trace object, falsely marked as already + # inserted to stop the import daemon trying to load it + @trace = Trace.new({ + :name => name, + :tagstring => tags, + :description => description, + :public => public, + :inserted => true, + :user => @user, + :timestamp => Time.now + }) + + # Save the trace object if @trace.save + # Rename the temporary file to the final name FileUtils.mv(filename, @trace.trace_name) + + # Clear the inserted flag to make the import daemon load the trace + @trace.inserted = false + @trace.save! else + # Remove the file as we have failed to update the database FileUtils.rm_f(filename) end end