Skip to content

Commit

Permalink
fix inisializing
Browse files Browse the repository at this point in the history
  • Loading branch information
tdtds committed Nov 20, 2014
1 parent 9cd35b4 commit 2c0c7a5
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions misc/plugin/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c0c7a5

Please sign in to comment.