Class: PeopleImport
- Inherits:
-
Import
- Object
- ActiveRecord::Base
- Import
- PeopleImport
show all
- Defined in:
- app/models/imports/people_import.rb
Constant Summary
Constants inherited
from Import
Import::DATE_INPUT_FORMAT, Import::DATE_INPUT_FORMAT_WITH_TIME
Instance Method Summary
collapse
Methods inherited from Import
#attach_person, build, #cache_data, #fail!, #hash_address, #headers, #import, #message, #parsed_rows, #perform, #rows
#csv_data, included, #s3_service, #time_zone_parser
#approve!, #caching!, #failed!, #failed?, #imported!, #importing!, included, #invalidate!, #pending!, #recalled!, #recalling!
Instance Method Details
#create_person(parsed_row) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/models/imports/people_import.rb', line 52
def create_person(parsed_row)
new_person = attach_person(parsed_row)
existing_person = Person.first_or_initialize( {:email => new_person.email, :organization => self.organization} ) do |p|
p.import = self
p.type = new_person.type
p.subtype = new_person.subtype
end
message(nil, parsed_row, existing_person, "#{existing_person.email} exists. Will merge records.") unless existing_person.new_record?
existing_person.update_from_import(new_person)
existing_person.skip_commit = true
if !existing_person.save
error(parsed_row, existing_person)
end
existing_person
end
|
#error(parsed_row, person) ⇒ Object
45
46
47
48
49
50
|
# File 'app/models/imports/people_import.rb', line 45
def error(parsed_row, person)
message = ""
message = parsed_row.email + ": " unless parsed_row.email.blank?
message = message + person.errors.full_messages.join(", ")
raise Import::RowError, message
end
|
#kind ⇒ Object
2
3
4
|
# File 'app/models/imports/people_import.rb', line 2
def kind
"people"
end
|
#process(parsed_row) ⇒ Object
33
34
35
|
# File 'app/models/imports/people_import.rb', line 33
def process(parsed_row)
create_person(parsed_row)
end
|
#recall ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/models/imports/people_import.rb', line 14
def recall
raise "Can't recall this import" unless recallable?
self.import_messages.destroy_all
self.recalling!
no_errors = true
self.people.each do |person|
if person.destroyable?
person.destroy
else
self.message(nil, nil, person, "#{person} had existing actions or orders, and wasn't able to be recalled.")
no_errors = false
end
end
self.recalled!
no_errors
end
|
#recallable? ⇒ Boolean
10
11
12
|
# File 'app/models/imports/people_import.rb', line 10
def recallable?
true if self.status == "imported"
end
|
#rollback ⇒ Object
6
7
8
|
# File 'app/models/imports/people_import.rb', line 6
def rollback
self.people.destroy_all
end
|
#row_valid?(parsed_row) ⇒ Boolean
37
38
39
40
41
42
43
|
# File 'app/models/imports/people_import.rb', line 37
def row_valid?(parsed_row)
raise Import::RowError, "Please include a first name, last name, or email in this row: #{parsed_row.row}" unless attach_person(parsed_row).naming_details_available?
true
end
|