Class: Spree::ImportRow
- Inherits:
-
Object
- Object
- Spree::ImportRow
- Defined in:
- app/models/spree/import_row.rb
Instance Method Summary collapse
- #attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
-
#bulk_process!(mappings:, schema_fields:) ⇒ Object
Bulk processing mode for large imports.
- #data_json ⇒ Object
- #process!(mappings: nil, schema_fields: nil) ⇒ Object
- #publish_import_row_completed_event ⇒ Object
- #publish_import_row_failed_event ⇒ Object
- #to_schema_hash ⇒ Object
Instance Method Details
#attribute_by_schema_field(schema_field, mappings = nil) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'app/models/spree/import_row.rb', line 71 def attribute_by_schema_field(schema_field, mappings = nil) mappings ||= import.mappings.mapped mapping = mappings.find { |m| m.schema_field == schema_field } return unless mapping&.mapped? data_json[mapping.file_column] end |
#bulk_process!(mappings:, schema_fields:) ⇒ Object
Bulk processing mode for large imports. Uses update_columns to skip callbacks, validations, and event publishing.
92 93 94 95 96 97 98 99 100 |
# File 'app/models/spree/import_row.rb', line 92 def bulk_process!(mappings:, schema_fields:) update_columns(status: 'processing', updated_at: Time.current) processor = import.row_processor_class.new(self, mappings: mappings, schema_fields: schema_fields) self.item = processor.process! update_columns(status: 'completed', item_type: item.class.name, item_id: item.id, updated_at: Time.current) rescue StandardError => e Rails.error.report(e, handled: true, context: { import_row_id: id }, source: 'spree.core') update_columns(status: 'failed', validation_errors: e., updated_at: Time.current) end |
#data_json ⇒ Object
52 53 54 55 56 |
# File 'app/models/spree/import_row.rb', line 52 def data_json @data_json ||= JSON.parse(data) rescue JSON::ParserError {} end |
#process!(mappings: nil, schema_fields: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'app/models/spree/import_row.rb', line 80 def process!(mappings: nil, schema_fields: nil) start_processing! self.item = import.row_processor_class.new(self, mappings: mappings, schema_fields: schema_fields).process! complete! rescue StandardError => e Rails.error.report(e, handled: true, context: { import_row_id: id }, source: 'spree.core') self.validation_errors = e. fail! end |
#publish_import_row_completed_event ⇒ Object
102 103 104 |
# File 'app/models/spree/import_row.rb', line 102 def publish_import_row_completed_event publish_event('import_row.completed') end |
#publish_import_row_failed_event ⇒ Object
106 107 108 |
# File 'app/models/spree/import_row.rb', line 106 def publish_import_row_failed_event publish_event('import_row.failed') end |
#to_schema_hash ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/spree/import_row.rb', line 58 def to_schema_hash @to_schema_hash ||= begin mappings = import.mappings.mapped schema_fields = import.schema_fields attributes = {} schema_fields.each do |field| attributes[field[:name]] = attribute_by_schema_field(field[:name], mappings) end attributes end end |