diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 366cea06b..9572034aa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -120,59 +120,52 @@ module ApplicationHelper case type when "HomeworkCommon" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1) else - score = course_contributor_score.homework_journal_num + 1 + score = course_contributor_score.homework_journal_num.to_i + 1 course_contributor_score.update_attributes(:homework_journal_num => score) end # 课程留言 when "Course" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1) else - score = course_contributor_score.journal_num + 1 + score = course_contributor_score.journal_num.to_i + 1 course_contributor_score.update_attributes(:journal_num => score) end when "Message" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1) else - score = course_contributor_score.message_num + 1 + score = course_contributor_score.message_num.to_i + 1 course_contributor_score.update_attributes(:message_num => score) end when "MessageReply" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1) else - score = course_contributor_score.message_reply_num + 1 + score = course_contributor_score.message_reply_num.to_i + 1 course_contributor_score.update_attributes(:message_reply_num => score) end when "NewReply" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1) else - score = course_contributor_score.news_reply_num + 1 + score = course_contributor_score.news_reply_num.to_i + 1 course_contributor_score.update_attributes(:news_reply_num => score) end when "News" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1) else - score = course_contributor_score.news_num + 1 + score = course_contributor_score.news_num.to_i + 1 course_contributor_score.update_attributes(:news_num => score) end when "Attachment" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1) else - score = course_contributor_score.resource_num + 1 + score = course_contributor_score.resource_num.to_i + 1 course_contributor_score.update_attributes(:resource_num => score) end end @@ -184,38 +177,38 @@ module ApplicationHelper case type when "HomeworkCommon" unless course_contributor_score.nil? - score = course_contributor_score.homework_journal_num - 1 + score = course_contributor_score.homework_journal_num.to_i - 1 course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score) end # 课程留言 when "Course" unless course_contributor_score.nil? - score = course_contributor_score.journal_num - 1 + score = course_contributor_score.journal_num.to_i - 1 course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score) end when "Message" unless course_contributor_score.nil? - score = course_contributor_score.message_num - 1 + score = course_contributor_score.message_num.to_i - 1 course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score) end when "MessageReply" unless course_contributor_score.nil? - score = course_contributor_score.message_reply_num - 1 + score = course_contributor_score.message_reply_num.to_i - 1 course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score) end when "NewReply" unless course_contributor_score.nil? - score = course_contributor_score.news_reply_num - 1 + score = course_contributor_score.news_reply_num.to_i - 1 course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score) end when "News" unless course_contributor_score.nil? - score = course_contributor_score.news_num - 1 + score = course_contributor_score.news_num.to_i - 1 course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score) end when "Attachment" unless course_contributor_score.nil? - score = course_contributor_score.resource_num - 1 + score = course_contributor_score.resource_num.to_i - 1 course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score) end end diff --git a/app/models/message.rb b/app/models/message.rb index 2f4637042..1c7bf7677 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -80,12 +80,10 @@ class Message < ActiveRecord::Base validates_length_of :subject, :maximum => 255 validate :cannot_reply_to_locked_topic, :on => :create - after_create :add_author_as_watcher, :reset_counters!, :add_boards_count + # after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score - - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, - :act_as_system_message, :send_mail, :act_as_student_score, act_as_at_message(:content, :author_id) + after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count #before_save :be_user_score scope :visible, lambda {|*args| @@ -137,11 +135,11 @@ class Message < ActiveRecord::Base if self.project && !project.project_score.nil? # 讨论区 if self.parent_id.nil? - count = self.project.project_score.board_num + 1 - self.project.project_score.update_attribute(:board_num, count) + count = self.project.project_score.board_num.to_i + 1 + self.project.project_score.update_column(:board_num, count) else # 回复 - count = self.project.project_score.board_message_num + 1 - self.project.project_score.update_attribute(:board_message_num, count) + count = self.project.project_score.board_message_num.to_i + 1 + self.project.project_score.update_column(:board_message_num, count) end end end diff --git a/lib/tasks/sync_files.rake b/lib/tasks/sync_files.rake new file mode 100644 index 000000000..5c9326356 --- /dev/null +++ b/lib/tasks/sync_files.rake @@ -0,0 +1,38 @@ +require 'trustie/gitlab/sync' + +namespace :trustie do + namespace :files do + desc "sync course'file" + task :course => :environment do + # Course.all.each do |course| + # unless course.attachments.count.to_i == 0 + # attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and container_type ='Course'").count + # project_score = ProjectScore.where("project_id=?", project.id).first + # if project_score.nil? + # ProjectScore.create(:project_id => project.id, :attach_num => 0) + # else + # project_score.attach_num = attachment_count + # project_score.save + # end + # end + # end + end + + desc "sync project'file" + task :project => :environment do + Project.all.each do |project| + unless project.attachments.count.to_i == 0 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{project.id} and container_type ='Project'").count + project_score = ProjectScore.where("project_id=?", project.id).first + if project_score.nil? + ProjectScore.create(:project_id => project.id, :attach_num => 0) + else + project_score.attach_num = attachment_count + project_score.save + end + end + end + end + + end +end