Improve upload error handling
This commit is contained in:
parent
c30ec67548
commit
5d47171b76
2 changed files with 8 additions and 2 deletions
|
@ -137,7 +137,7 @@ class ArticlesController < ApplicationController
|
||||||
|
|
||||||
# Update articles from a spreadsheet
|
# Update articles from a spreadsheet
|
||||||
def parse_upload
|
def parse_upload
|
||||||
uploaded_file = params[:articles]['file']
|
uploaded_file = params[:articles]['file'] or raise I18n.t('articles.controller.parse_upload.no_file')
|
||||||
options = {filename: uploaded_file.original_filename}
|
options = {filename: uploaded_file.original_filename}
|
||||||
options[:outlist_absent] = (params[:articles]['outlist_absent'] == '1')
|
options[:outlist_absent] = (params[:articles]['outlist_absent'] == '1')
|
||||||
options[:convert_units] = (params[:articles]['convert_units'] == '1')
|
options[:convert_units] = (params[:articles]['convert_units'] == '1')
|
||||||
|
@ -174,7 +174,12 @@ class ArticlesController < ApplicationController
|
||||||
has_error = false
|
has_error = false
|
||||||
Article.transaction do
|
Article.transaction do
|
||||||
# delete articles
|
# delete articles
|
||||||
@outlisted_articles.each(&:mark_as_deleted)
|
begin
|
||||||
|
@outlisted_articles.each(&:mark_as_deleted)
|
||||||
|
rescue
|
||||||
|
# raises an exception when used in current order
|
||||||
|
has_error = true
|
||||||
|
end
|
||||||
# Update articles
|
# Update articles
|
||||||
@updated_articles.map{|a| a.save or has_error=true }
|
@updated_articles.map{|a| a.save or has_error=true }
|
||||||
# Add new articles
|
# Add new articles
|
||||||
|
|
|
@ -358,6 +358,7 @@ en:
|
||||||
error_update: 'An error occured when updating article ''%{article}'': %{msg}'
|
error_update: 'An error occured when updating article ''%{article}'': %{msg}'
|
||||||
parse_upload:
|
parse_upload:
|
||||||
notice: Articles are already up to date.
|
notice: Articles are already up to date.
|
||||||
|
no_file: Please select a file to upload
|
||||||
sync:
|
sync:
|
||||||
notice: Articles are already up to date.
|
notice: Articles are already up to date.
|
||||||
shared_alert: "%{supplier} is not linked to an external database"
|
shared_alert: "%{supplier} is not linked to an external database"
|
||||||
|
|
Loading…
Reference in a new issue