修复帖子统计问题
This commit is contained in:
parent
49327905f8
commit
8f707f3987
|
@ -17,4 +17,16 @@ class Forum < ActiveRecord::Base
|
|||
acts_as_taggable
|
||||
scope :by_join_date, order("created_at DESC")
|
||||
|
||||
def reset_counters!
|
||||
self.class.reset_counters!(id)
|
||||
end
|
||||
|
||||
# Updates topic_count, memo_count and last_memo_id attributes for +board_id+
|
||||
def self.reset_counters!(forum_id)
|
||||
forum_id = forum_id.to_i
|
||||
update_all("topic_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NULL)," +
|
||||
" memo_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})," +
|
||||
" last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})",
|
||||
["id = ?", forum_id])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Memo < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :forums
|
||||
belongs_to :forum
|
||||
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
|
||||
|
||||
validates_presence_of :author_id, :forum_id, :subject
|
||||
|
@ -13,10 +13,10 @@ class Memo < ActiveRecord::Base
|
|||
acts_as_attachable
|
||||
belongs_to :last_reply_id, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
||||
# acts_as_searchable :column => ['subject', 'content'],
|
||||
# #:include => { :forums => :p}
|
||||
# #:include => { :forum => :p}
|
||||
# #:project_key => "#{Forum.table_name}.project_id"
|
||||
# :date_column => "#{table_name}.created_at"
|
||||
# acts_as_event :title => Proc.new {|o| "#{o.forums.name}: #{o.subject}"},
|
||||
# acts_as_event :title => Proc.new {|o| "#{o.forum.name}: #{o.subject}"},
|
||||
# :description => :content,
|
||||
# :group => :parent,
|
||||
# :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||
|
@ -29,7 +29,7 @@ class Memo < ActiveRecord::Base
|
|||
"subject",
|
||||
"content",
|
||||
"forum_id",
|
||||
"last_reply_id",
|
||||
"last_memo_id",
|
||||
"lock",
|
||||
"parent_id",
|
||||
"replies_count",
|
||||
|
@ -39,8 +39,8 @@ class Memo < ActiveRecord::Base
|
|||
# after_update :update_memos_forum
|
||||
after_destroy :reset_counters!
|
||||
# after_create :send_notification
|
||||
after_save :plusParentAndForum
|
||||
after_destroy :minusParentAndForum
|
||||
# after_save :plusParentAndForum
|
||||
# after_destroy :minusParentAndForum
|
||||
|
||||
# scope :visible, lambda { |*args|
|
||||
# includes(:forum => ).where()
|
||||
|
@ -62,7 +62,7 @@ class Memo < ActiveRecord::Base
|
|||
if parent && parent.id
|
||||
Memo.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id})
|
||||
end
|
||||
# forums.reset_counters!
|
||||
forum.reset_counters!
|
||||
end
|
||||
|
||||
def sticky=(arg)
|
||||
|
|
|
@ -203,7 +203,7 @@ Redmine::MenuManager.map :top_menu do |menu|
|
|||
menu.push :software_user, {:controller => 'users', :action => 'index'}
|
||||
menu.push :contest_innovate, {:controller => 'bids', :action => 'contest', :project_type => 1}
|
||||
menu.push :requirement_enterprise, {:controller => 'bids', :action => 'index'}
|
||||
menu.push :project_module_forums, {:controller => 'forums', :action => 'index'}
|
||||
menu.push :project_module_forums, forums_path
|
||||
|
||||
|
||||
# menu.push :investor, :home_path
|
||||
|
|
Loading…
Reference in New Issue