diff --git a/Gemfile b/Gemfile index 574f6b26e..b3da39ab3 100644 --- a/Gemfile +++ b/Gemfile @@ -116,6 +116,9 @@ gem 'diffy' # feature - excel output gem 'writeexcel', require: false +# feature - csv import/export +gem 'csv', require: false + # feature - device logging gem 'browser' diff --git a/Gemfile.lock b/Gemfile.lock index 38df133be..8087564be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -165,6 +165,7 @@ GEM crack (0.4.5) rexml crass (1.0.6) + csv (3.2.0) daemons (1.4.1) dalli (2.7.11) debug_inspector (1.1.0) @@ -667,6 +668,7 @@ DEPENDENCIES coffeelint composite_primary_keys coveralls + csv daemons dalli delayed_job_active_record diff --git a/app/models/concerns/can_csv_import.rb b/app/models/concerns/can_csv_import.rb index b73f69988..4ba11882d 100644 --- a/app/models/concerns/can_csv_import.rb +++ b/app/models/concerns/can_csv_import.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require 'csv' - module CanCsvImport extend ActiveSupport::Concern @@ -59,6 +57,7 @@ returns raise Exceptions::UnprocessableEntity, "Unable to read file '#{data[:file]}': #{e.inspect}" end + require 'csv' # Only load it when it's really needed to save memory. header, *rows = ::CSV.parse(data[:string], **data[:parse_params]) header&.each do |column| @@ -296,6 +295,8 @@ returns end rows_to_add = [] end + + require 'csv' # Only load it when it's really needed to save memory. ::CSV.generate(**params) do |csv| csv << header rows.each do |row| diff --git a/app/models/translation.rb b/app/models/translation.rb index 906e65a58..1d2543df8 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -1,7 +1,5 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -require 'csv' - class Translation < ApplicationModel before_create :set_initial after_create :cache_clear @@ -407,6 +405,7 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation params = { col_sep: ',', } + require 'csv' # Only load it when it's really needed to save memory. rows = ::CSV.parse(content, params) rows.shift # remove header