imp_exp 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94c393f1951d6c5ce96e649b5ddebeb783e4602d136808852826903bdc656374
|
|
4
|
+
data.tar.gz: e4ddda971aeaa6f46fce2fa376dfd904b7e3f1fc43a289aef5d6980ec6520e0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d192022028986ba40750b6abe36b480c0a7167657b71cb2a2528edc4760bfaa61f1a543a73a6893cdf1fd916bfd70ccc2d8aee6f5cbaa95107d9801a79fc2be
|
|
7
|
+
data.tar.gz: 8ffdaf906fa00dbc63613d18334aef5f5c89007e892dcc17669f35efcbe7cea9696fd3d43696e2f8435e1ee2fe93f804c4567d5f0ea3444bf6fc36109ec45f9f
|
|
@@ -81,9 +81,14 @@ module ImpExp
|
|
|
81
81
|
next
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
model.
|
|
86
|
-
|
|
84
|
+
begin
|
|
85
|
+
if model.save(record)
|
|
86
|
+
@imported[model.model_name] += 1
|
|
87
|
+
next
|
|
88
|
+
end
|
|
89
|
+
rescue ActiveRecord::RecordNotUnique => e
|
|
90
|
+
message = I18n.t('imp_exp.importer.record_not_unique', details: unique_violation_details_suffix(e))
|
|
91
|
+
upsert_error_messages(model_name, line, row.to_s, message)
|
|
87
92
|
next
|
|
88
93
|
end
|
|
89
94
|
|
|
@@ -97,6 +102,12 @@ module ImpExp
|
|
|
97
102
|
Rails.env.local?
|
|
98
103
|
end
|
|
99
104
|
|
|
105
|
+
def unique_violation_details_suffix(exception)
|
|
106
|
+
details = exception.cause&.message || exception.message
|
|
107
|
+
details = details.to_s.strip
|
|
108
|
+
details.present? ? "(#{details})" : ""
|
|
109
|
+
end
|
|
110
|
+
|
|
100
111
|
def attributes_from_row(row, model)
|
|
101
112
|
row.slice(*model.attribute_to_import_names)
|
|
102
113
|
end
|
|
@@ -133,7 +144,7 @@ module ImpExp
|
|
|
133
144
|
|
|
134
145
|
full_file_path = File.join(files_directory_path, file_path.strip)
|
|
135
146
|
begin
|
|
136
|
-
file = File.open(full_file_path)
|
|
147
|
+
file = File.open(full_file_path) # rubocop:disable Style/FileOpen
|
|
137
148
|
record.send(file_attribute_name).attach(io: file, filename: File.basename(file_path))
|
|
138
149
|
rescue Errno::ENOENT
|
|
139
150
|
error_msg = I18n.t('imp_exp.importer.file_not_found', file_path: file_path)
|
|
@@ -143,7 +143,9 @@ module ImpExp
|
|
|
143
143
|
"#{active_storage_file.name}-#{active_storage_file.record.code}#{file_extension(active_storage_file)}"
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
def
|
|
146
|
+
def save(record)
|
|
147
|
+
record.save(context: :import)
|
|
148
|
+
end
|
|
147
149
|
|
|
148
150
|
private
|
|
149
151
|
|
|
@@ -26,7 +26,7 @@ module ImpExp
|
|
|
26
26
|
return [ImpExp::Serializers::Errors::WrongFormat.new("#{relation_name} error | #{message}")]
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
unless data.is_a?(Array) && data.all?
|
|
29
|
+
unless data.is_a?(Array) && data.all?(Hash)
|
|
30
30
|
return [ImpExp::Serializers::Errors::WrongFormat.new("#{relation_name} should be an array of hashes")]
|
|
31
31
|
end
|
|
32
32
|
|
data/config/locales/en.yml
CHANGED
|
@@ -4,6 +4,7 @@ en:
|
|
|
4
4
|
invalid_columns: "The %{model_name} sheet does not contain the expected columns. Expected columns: %{expected_columns} Columns in the file: %{in_file_columns}."
|
|
5
5
|
invalid_sheets: "The file does not contain the expected sheets. Expected sheets: %{expected_sheets} Sheets in the file: %{in_file_sheets}."
|
|
6
6
|
record_not_found: "%{model_name} with %{conditions} conditions has not been found."
|
|
7
|
+
record_not_unique: "Unique constraint violation. Check the code field. Details: %{details}."
|
|
7
8
|
wrong_format: "Format error: %{message}."
|
|
8
9
|
model_errors: "%{model_name} sheet - Row %{line}: %{messages}"
|
|
9
10
|
data_validation_error: "%{model_name} sheet - Row %{line} - Column \"%{column}\": value \"%{value}\" incorrect, expected value: %{expected}"
|
data/config/locales/fr.yml
CHANGED
|
@@ -4,7 +4,8 @@ fr:
|
|
|
4
4
|
invalid_columns: "La feuille %{model_name} ne contient pas les colonnes attendues. Colonnes attendues : %{expected_columns}. Colonnes dans le fichier : %{in_file_columns}."
|
|
5
5
|
invalid_sheets: "Le fichier ne contient pas les feuilles attendues. Feuilles attendues : %{expected_sheets}. Feuilles dans le fichier : %{in_file_sheets}."
|
|
6
6
|
record_not_found: "%{model_name} avec les conditions %{conditions} n'a pas été trouvé."
|
|
7
|
+
record_not_unique: "Violation de contrainte d'unicité. Vérifiez les champs code. Détails : %{details}."
|
|
7
8
|
wrong_format: "Erreur de format : %{message}."
|
|
8
9
|
model_errors: "Feuille %{model_name} - Ligne %{line} : %{messages}"
|
|
9
10
|
data_validation_error: "Feuille %{model_name} - Ligne %{line} - Colonne \"%{column}\" : valeur \"%{value}\" incorrecte, valeur attendue : %{expected}"
|
|
10
|
-
file_not_found: "Fichier %{file_path} non trouvé."
|
|
11
|
+
file_not_found: "Fichier %{file_path} non trouvé."
|
data/lib/imp_exp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imp_exp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dev team Nerya
|
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
139
|
- !ruby/object:Gem::Version
|
|
140
140
|
version: '0'
|
|
141
141
|
requirements: []
|
|
142
|
-
rubygems_version: 4.0.
|
|
142
|
+
rubygems_version: 4.0.10
|
|
143
143
|
specification_version: 4
|
|
144
144
|
summary: Import data from xlsx into a rails app and export data to xlsx from a rails
|
|
145
145
|
app
|