lib/data_import.rb in parlement-0.7 vs lib/data_import.rb in parlement-0.8
- old
+ new
@@ -26,15 +26,12 @@
def inputFile(d, fileName)
puts 'Loading: '+File.basename(fileName).gsub(/.txt/, '')
elt = Elt.find_by_id File.basename(fileName).gsub(/.txt/, '')
+ elt ||= Elt.new :id => File.basename(fileName).gsub(/.txt/, ''), :created_on => nil
- unless elt
- elt = Elt.new :id => File.basename(fileName).gsub(/.txt/, ''), :created_on => nil
- end
-
file = File.new fileName
if !elt.created_on or elt.created_on < file.mtime
elt.mail = nil
@@ -43,9 +40,10 @@
puts elt.created_on.class
elt.subject = ICONV.iconv(file.gets.strip)
elt.body = format(ICONV.iconv(file.gets('\n')))
puts "subject: #{elt.subject} (created_on: #{elt.created_on.to_s})"
elt.save
+ elt.parent.add_child elt unless elt.lft or elt.rgt
end
end
inputDir dir