diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-04-05 10:08:11 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-04-05 10:08:11 +0000 |
commit | ca166b30e1b223c7f3aba3befc894a8597362592 (patch) | |
tree | 42d3a97b4d38db99ba3ff6a91aa23e75db44b5c4 /app/models/board.rb | |
parent | 3d65ed7aa0b6892ca76160a89694acc4efa79f27 (diff) | |
download | redmine-ca166b30e1b223c7f3aba3befc894a8597362592.tar.gz redmine-ca166b30e1b223c7f3aba3befc894a8597362592.zip |
Adds the ability to move threads between project forums (#2452). 'Edit message' permission is required.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2649 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/board.rb')
-rw-r--r-- | app/models/board.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/board.rb b/app/models/board.rb index 26e2004d3..3bc18efec 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -26,4 +26,17 @@ class Board < ActiveRecord::Base validates_presence_of :name, :description validates_length_of :name, :maximum => 30 validates_length_of :description, :maximum => 255 + + def reset_counters! + self.class.reset_counters!(id) + end + + # Updates topics_count, messages_count and last_message_id attributes for +board_id+ + def self.reset_counters!(board_id) + board_id = board_id.to_i + update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," + + " messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," + + " last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})", + ["id = ?", board_id]) + end end |