lib/updateagent/updaters/people_updater.rb in onebody-updateagent-0.4.0 vs lib/updateagent/updaters/people_updater.rb in onebody-updateagent-0.4.1
- old
+ new
@@ -8,27 +8,47 @@
if options[:converter]
converter = Kernel.const_get(@options['converter']['name'] + 'Converter').new(@options['converter'])
@data = converter.convert(@data.clone)
@attributes = @data.first.keys
end
+ check_for_missing_columns
person_data = []
family_data = {}
@data.each_with_index do |row, index|
person, family = split_change_hash(row)
if existing_family = family_data[family['legacy_id']]
person['family'] = existing_family
+ if person.has_key?('email')
+ person['email_changed'] = false
+ @attributes << 'email_changed'
+ end
person_data << person
else
person['family'] = family
+ if person.has_key?('email')
+ person['email_changed'] = false
+ @attributes << 'email_changed'
+ end
person_data << person
+ family['barcode_id_changed'] = false if family.has_key?('barcode_id')
family_data[family['legacy_id']] = family
end
print "splitting family record #{index+1}\r"
end
puts
@data = person_data
@attributes.reject! { |a| a =~ /^family_/ and a != 'family_id' }
@family_agent = FamilyUpdater.new(family_data.values)
+ end
+
+ @@required_columns = %w(legacy_id legacy_family_id)
+
+ def check_for_missing_columns
+ if row = @data.detect { |row| (@@required_columns - row.keys).any? }
+ puts "Error: one or more required columns are missing."
+ puts "Required but missing: #{(@@required_columns - row.keys).join(', ')}"
+ exit(1)
+ end
end
def name_for(row)
"#{row['first_name']} #{row['last_name']}" rescue ''
end