don't do anything if csv_content is empty
This commit is contained in:
@@ -46,35 +46,37 @@ class ItemsController < ApplicationController
|
|||||||
@csv_content = params[:csv_content]
|
@csv_content = params[:csv_content]
|
||||||
|
|
||||||
@error_message = ""
|
@error_message = ""
|
||||||
@error_message = "Format of CSV is wrong (CSV content is empty)" if params[:csv_content] == ""
|
|
||||||
|
|
||||||
csv_parsed = CSV.parse(params[:csv_content])
|
if params[:csv_content] == ""
|
||||||
csv_file = ItemsHelper::create_csv(csv_parsed)
|
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
||||||
|
else
|
||||||
|
csv_parsed = CSV.parse(params[:csv_content])
|
||||||
|
csv_file = ItemsHelper::create_csv(csv_parsed)
|
||||||
|
|
||||||
@output = ""
|
@output = ""
|
||||||
|
|
||||||
begin
|
begin
|
||||||
ENV["INPUT"] = csv_file.path
|
ENV["INPUT"] = csv_file.path
|
||||||
|
|
||||||
case params[:task]
|
case params[:task]
|
||||||
when 'validate_items'
|
when 'validate_items'
|
||||||
@output = ItemsHelper::execute_command("rake ribica:validate_items")
|
@output = ItemsHelper::execute_command("rake ribica:validate_items")
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
when 'import_items'
|
when 'import_items'
|
||||||
@output = ItemsHelper::execute_command("rake ribica:import_items")
|
@output = ItemsHelper::execute_command("rake ribica:import_items")
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
when 'update_prices'
|
when 'update_prices'
|
||||||
@output = ItemsHelper::execute_command("rake ribica:update_prices")
|
@output = ItemsHelper::execute_command("rake ribica:update_prices")
|
||||||
#ItemsHelper::execute_command("rake ribica:reindex")
|
#ItemsHelper::execute_command("rake ribica:reindex")
|
||||||
else
|
else
|
||||||
@error_message = "There is no such task"
|
@error_message = "There is no such task"
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
csv_file.unlink
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
sleep 5
|
|
||||||
csv_file.unlink
|
|
||||||
end
|
|
||||||
|
|
||||||
@output = @output.join("<br/>")
|
@output = @output.join("<br/>")
|
||||||
|
end
|
||||||
|
|
||||||
render :template => "items/export_import"
|
render :template => "items/export_import"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user