summaryrefslogtreecommitdiffstats
path: root/app/models/message.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-04-05 10:08:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-04-05 10:08:11 +0000
commitca166b30e1b223c7f3aba3befc894a8597362592 (patch)
tree42d3a97b4d38db99ba3ff6a91aa23e75db44b5c4 /app/models/message.rb
parent3d65ed7aa0b6892ca76160a89694acc4efa79f27 (diff)
downloadredmine-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/message.rb')
-rw-r--r--app/models/message.rb21
1 files changed, 11 insertions, 10 deletions
diff --git a/app/models/message.rb b/app/models/message.rb
index 716c53b0b..92bcb1275 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -37,7 +37,7 @@ class Message < ActiveRecord::Base
acts_as_watchable
attr_protected :locked, :sticky
- validates_presence_of :subject, :content
+ validates_presence_of :board, :subject, :content
validates_length_of :subject, :maximum => 255
after_create :add_author_as_watcher
@@ -48,21 +48,22 @@ class Message < ActiveRecord::Base
end
def after_create
- board.update_attribute(:last_message_id, self.id)
- board.increment! :messages_count
if parent
parent.reload.update_attribute(:last_reply_id, self.id)
- else
- board.increment! :topics_count
+ end
+ board.reset_counters!
+ end
+
+ def after_update
+ if board_id_changed?
+ Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
+ Board.reset_counters!(board_id_was)
+ Board.reset_counters!(board_id)
end
end
def after_destroy
- # The following line is required so that the previous counter
- # updates (due to children removal) are not overwritten
- board.reload
- board.decrement! :messages_count
- board.decrement! :topics_count unless parent
+ board.reset_counters!
end
def sticky?