Class: Locomotive::ContentEntryImportService
- Inherits:
-
Struct
- Object
- Struct
- Locomotive::ContentEntryImportService
show all
- Defined in:
- app/services/locomotive/content_entry_import_service.rb
Defined Under Namespace
Classes: WrongImportFileException
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type
4
5
6
|
# File 'app/services/locomotive/content_entry_import_service.rb', line 4
def content_type
@content_type
end
|
Instance Method Details
#async_import(file, csv_options = nil) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'app/services/locomotive/content_entry_import_service.rb', line 8
def async_import(file, csv_options = nil)
csv_asset = content_assets.create(source: file)
Locomotive::ImportContentEntryJob.perform_later(
content_type.id.to_s,
csv_asset.id.to_s,
csv_options
)
end
|
#cancel(reason) ⇒ Object
32
33
34
|
# File 'app/services/locomotive/content_entry_import_service.rb', line 32
def cancel(reason)
content_type.cancel_import(reason)
end
|
#import(csv_asset_id, csv_options = nil) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'app/services/locomotive/content_entry_import_service.rb', line 17
def import(csv_asset_id, csv_options = nil)
begin
csv = load_csv(csv_asset_id, csv_options)
rescue WrongImportFileException => e
content_type.cancel_import(e.message)
return false
end
content_type.start_import(total: csv.count)
import_rows(csv)
content_type.finish_import
content_assets.destroy_all(id: csv_asset_id)
end
|