diff --git a/misc/plugin/category.rb b/misc/plugin/category.rb index b0ce89d8..3cc0109a 100644 --- a/misc/plugin/category.rb +++ b/misc/plugin/category.rb @@ -488,16 +488,24 @@ def recreate(years) cgi = Category::CGI::new list = [] - years.each do |y, ms| - ms.each do |m| - ym = "#{y}#{m}" - cgi.params['date'] = [ym] - m = TDiaryMonth.new(cgi, '', @conf) - m.diaries.each do |ymd, diary| - next if !diary.visible? - initial_replace_sections(diary) - diary.each_section do |s| - list |= s.categories unless s.categories.empty? + @plugin.__send__(:transaction, 'category') do |db| + db.keys.each {|key|db.delete(key)} + + years.each do |y, ms| + ms.each do |m| + ym = "#{y}#{m}" + cgi.params['date'] = [ym] + m = TDiaryMonth.new(cgi, '', @conf) + m.diaries.each do |ymd, diary| + next if !diary.visible? or !diary.categorizable? + categorized = categorize_diary(diary) + categorized.keys.each do |c| + cat = get(db, c) || {} + set(db, c, cat.update(categorized[c])) + end + diary.each_section do |s| + list |= s.categories unless s.categories.empty? + end end end end @@ -582,22 +590,6 @@ def categorize_diary(diary) categorized end - - # - # cache each section of diary - # used in recreate - # - def initial_replace_sections(diary) - return if diary.nil? or !diary.visible? or !diary.categorizable? - - categorized = categorize_diary(diary) - @plugin.__send__(:transaction, 'category') do |db| - categorized.keys.each do |c| - cat = get(db, c) || {} - set(db, c, cat.update(categorized[c])) - end - end - end end end # module Category