43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/models/dhatu/section.rb', line 43
def self.save_row_data(hsh)
error_object = Kuppayam::Importer::ErrorHash.new
return error_object if hsh[:code].to_s.strip.blank?
section = Dhatu::Section.where("code = ?", hsh[:code].to_s.strip).first || Dhatu::Section.new
section.name = hsh[:name].to_s.strip
section.code = hsh[:code].to_s.strip
section.title = hsh[:title].to_s.strip
section.sub_title = hsh[:sub_title].to_s.strip
section.short_description = hsh[:short_description].to_s.strip
section.long_description = hsh[:long_description].to_s.strip
section.button_one_text = hsh[:button_one_text].to_s.strip
section.button_two_text = hsh[:button_two_text].to_s.strip
section.button_one_link = hsh[:button_one_link].to_s.strip
section.button_two_link = hsh[:button_two_link].to_s.strip
section.page = Dhatu::Page.where("code = ?", hsh[:page].to_s.strip).first
section.status = hsh[:status].to_s.strip || PUBLISHED
section.priority = hsh[:priority].to_s.strip || 1
if section.valid?
begin
section.save!
rescue Exception => e
summary = "uncaught #{e} exception while handling connection: #{e.message}"
details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}"
error_object.errors << { summary: summary, details: details }
end
else
summary = "Error while saving section: #{section.title}"
details = "Error! #{section.errors.full_messages.to_sentence}"
error_object.errors << { summary: summary, details: details }
end
return error_object
end
|