From 8758235364534050144a5866acd3db1051d58308 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 12 Jan 2016 15:10:02 +0800 Subject: [PATCH] =?UTF-8?q?issue=E5=88=9B=E5=BB=BA=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8Cissues=5Fcount+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue.rb | 16 ++++++++++++++-- .../20160111071348_static_project_boards.rb | 5 ----- .../20160111071411_static_project_issues.rb | 3 +-- db/migrate/20160111071529_static_project_news.rb | 7 ++++--- .../20160111071558_static_project_attachments.rb | 7 ++++--- db/migrate/20160111080914_static_project_acts.rb | 10 +++++++--- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 5ecb3e36f..4d2776ff7 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -83,9 +83,9 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message + after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message, :add_issues_count after_update :be_user_score - after_destroy :down_user_score + after_destroy :down_user_score, :decrease_issues_count # after_create :be_user_score # end @@ -165,6 +165,18 @@ class Issue < ActiveRecord::Base end end + # 创建issue的时候,issues_count加1 + def add_issues_count + issue_count = self.project.issues_count + 1 + self.project.update_attribute(:issues_count, issue_count) + end + + # 删除issue的时候,issues_count减1 + def decrease_issues_count + issue_count = self.project.issues_count - 1 + self.project.update_attribute(:issues_count, issue_count) + end + # 更新缺陷 #def act_as_forge_message_update # unless self.author_id == self.assigned_to_id diff --git a/db/migrate/20160111071348_static_project_boards.rb b/db/migrate/20160111071348_static_project_boards.rb index 1d85860c6..4b82be23c 100644 --- a/db/migrate/20160111071348_static_project_boards.rb +++ b/db/migrate/20160111071348_static_project_boards.rb @@ -1,6 +1,5 @@ class StaticProjectBoards < ActiveRecord::Migration def up - begin Project.all.each do |project| puts project.id unless project.boards.first.nil? @@ -8,12 +7,8 @@ class StaticProjectBoards < ActiveRecord::Migration project.update_attribute(:boards_count, boards_count) end end - ensure - self.down - end end def down - Project.update_all(:boards_count => false) end end diff --git a/db/migrate/20160111071411_static_project_issues.rb b/db/migrate/20160111071411_static_project_issues.rb index 273527164..d9a3a24ff 100644 --- a/db/migrate/20160111071411_static_project_issues.rb +++ b/db/migrate/20160111071411_static_project_issues.rb @@ -2,11 +2,10 @@ class StaticProjectIssues < ActiveRecord::Migration def up Project.all.each do |project| issues_count = project.issues.count - project.update_attribute(:issues_count, boards_count) + project.update_attribute(:issues_count, issues_count) end end def down - Project.all.update_all(:issues_count => false) end end diff --git a/db/migrate/20160111071529_static_project_news.rb b/db/migrate/20160111071529_static_project_news.rb index 6ccefbc32..f013a929d 100644 --- a/db/migrate/20160111071529_static_project_news.rb +++ b/db/migrate/20160111071529_static_project_news.rb @@ -1,12 +1,13 @@ class StaticProjectNews < ActiveRecord::Migration def up Project.all.each do |project| - news_count = project.news.count - project.update_attribute(:news_count, news_count) + unless project.news.nil? + news_count = project.news.count + project.update_attribute(:news_count, news_count) + end end end def down - Project.all.update_all(:news_count => false) end end diff --git a/db/migrate/20160111071558_static_project_attachments.rb b/db/migrate/20160111071558_static_project_attachments.rb index af4a282ed..692ca68eb 100644 --- a/db/migrate/20160111071558_static_project_attachments.rb +++ b/db/migrate/20160111071558_static_project_attachments.rb @@ -1,12 +1,13 @@ class StaticProjectAttachments < ActiveRecord::Migration def up Project.all.each do |project| - attachments_count = project.attachments.count - project.update_attribute(:attachments_count, attachments_count) + unless project.attachments.nil? + attachments_count = project.attachments.count + project.update_attribute(:attachments_count, attachments_count) + end end end def down - Project.all.update_all(:attachments_count => false) end end diff --git a/db/migrate/20160111080914_static_project_acts.rb b/db/migrate/20160111080914_static_project_acts.rb index 6f0d4a2e6..c368507a3 100644 --- a/db/migrate/20160111080914_static_project_acts.rb +++ b/db/migrate/20160111080914_static_project_acts.rb @@ -1,12 +1,16 @@ class StaticProjectActs < ActiveRecord::Migration def up Project.all.each do |project| - acts_count = ForgeActivity.where("project_id = ?", project.id).count - project.update_attribute(:acts_count, acts_count) + acts = ForgeActivity.where("project_id = ?", project.id) + unless acts.blank? + acts_count = acts.count + puts project.id + puts "acts_count is #{acts_count}" + project.update_attribute(:acts_count, acts_count) + end end end def down - Project.all.update_all(:acts_count => false) end end