From a47c9176b79bdbf80c8e271c25e535a69008c20c Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 2 Sep 2015 21:33:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B6=88=E6=81=AFhtml=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/user_messages.html.erb | 2 +- db/migrate/20150829023459_forge_messages.rb | 144 ++++++++--------- db/migrate/20150829024549_course_messages.rb | 152 +++++++++--------- .../20150829081822_update_message_time.rb | 40 ++--- ...0150829130302_update_forge_message_time.rb | 40 ++--- .../20150831070611_about_memo_message.rb | 58 +++---- ...50831093918_about_user_feedback_message.rb | 58 +++---- ...20150901004812_update_memo_message_time.rb | 40 ++--- ...1004910_update_userfeeback_message_time.rb | 40 ++--- 9 files changed, 287 insertions(+), 287 deletions(-) diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb index 5a17d5912..b2f852264 100644 --- a/app/views/users/user_messages.html.erb +++ b/app/views/users/user_messages.html.erb @@ -31,7 +31,7 @@
<% if params[:type].nil? %> <% end %> <% if @message_alls.count >0 %> diff --git a/db/migrate/20150829023459_forge_messages.rb b/db/migrate/20150829023459_forge_messages.rb index c468ad68f..96369a323 100644 --- a/db/migrate/20150829023459_forge_messages.rb +++ b/db/migrate/20150829023459_forge_messages.rb @@ -1,78 +1,78 @@ # encoding: UTF-8 class ForgeMessages < ActiveRecord::Migration def up - Project.all.each do |project| - transaction do - project.forge_messages << ForgeMessage.new(:user_id => project.user_id, :project_id => project.id) - - # 新闻 - project.news.each do |new| - new.project.members.each do |m| - if m.user_id != new.author_id - if m.created_on < new.created_on # 在成员加入项目之后 - new.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => new.project_id, :viewed => true) - end - end - end - end - - # 新闻回复 - project.news.each do |new| - if new.comments - new.comments.each do |comment| - if comment.author_id != comment.commented.author_id - comment.forge_messages << ForgeMessage.new(:user_id => comment.commented.author_id, :project_id => comment.commented.project.id, :viewed => true) - end - end - end - end - - # 讨论区 - if project.boards.first - project.boards.first.messages.each do |message| - if message.parent_id.nil? # 主贴 - message.project.members.each do |m| - if m.user_id != message.author_id - if m.created_on < message.created_on - message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) - end - end - end - else # 回帖 - message.project.members.each do |m| - if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 - if m.created_on < message.created_on - message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) - end - end - end - end - end - end - - # 缺陷 - project.issues.each do |issue| - unless issue.author_id == issue.assigned_to_id - issue.forge_messages << ForgeMessage.new(:user_id => issue.assigned_to_id, :project_id => issue.project_id, :viewed => true) - end - end - - # 缺陷更新 - project.issues.each do |issue| - if issue.journals - issue.journals.each do |journal| - if journal.user_id != journal.issue.author_id - journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.author_id, :project_id => journal.issue.project_id, :viewed => true) - end - if journal.user_id != journal.issue.assigned_to_id && journal.issue.assigned_to_id != journal.issue.author_id # 指派人不是自己的话,则给指派人发送 - journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.assigned_to_id, :project_id => journal.issue.project_id, :viewed => true) - end - end - end - end - - end - end + # Project.all.each do |project| + # transaction do + # project.forge_messages << ForgeMessage.new(:user_id => project.user_id, :project_id => project.id) + # + # # 新闻 + # project.news.each do |new| + # new.project.members.each do |m| + # if m.user_id != new.author_id + # if m.created_on < new.created_on # 在成员加入项目之后 + # new.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => new.project_id, :viewed => true) + # end + # end + # end + # end + # + # # 新闻回复 + # project.news.each do |new| + # if new.comments + # new.comments.each do |comment| + # if comment.author_id != comment.commented.author_id + # comment.forge_messages << ForgeMessage.new(:user_id => comment.commented.author_id, :project_id => comment.commented.project.id, :viewed => true) + # end + # end + # end + # end + # + # # 讨论区 + # if project.boards.first + # project.boards.first.messages.each do |message| + # if message.parent_id.nil? # 主贴 + # message.project.members.each do |m| + # if m.user_id != message.author_id + # if m.created_on < message.created_on + # message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) + # end + # end + # end + # else # 回帖 + # message.project.members.each do |m| + # if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 + # if m.created_on < message.created_on + # message.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => message.board.project_id, :viewed => true) + # end + # end + # end + # end + # end + # end + # + # # 缺陷 + # project.issues.each do |issue| + # unless issue.author_id == issue.assigned_to_id + # issue.forge_messages << ForgeMessage.new(:user_id => issue.assigned_to_id, :project_id => issue.project_id, :viewed => true) + # end + # end + # + # # 缺陷更新 + # project.issues.each do |issue| + # if issue.journals + # issue.journals.each do |journal| + # if journal.user_id != journal.issue.author_id + # journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.author_id, :project_id => journal.issue.project_id, :viewed => true) + # end + # if journal.user_id != journal.issue.assigned_to_id && journal.issue.assigned_to_id != journal.issue.author_id # 指派人不是自己的话,则给指派人发送 + # journal.forge_messages << ForgeMessage.new(:user_id => journal.issue.assigned_to_id, :project_id => journal.issue.project_id, :viewed => true) + # end + # end + # end + # end + # + # end + # end end def down diff --git a/db/migrate/20150829024549_course_messages.rb b/db/migrate/20150829024549_course_messages.rb index 34f4e9ef2..9d66bf9cd 100644 --- a/db/migrate/20150829024549_course_messages.rb +++ b/db/migrate/20150829024549_course_messages.rb @@ -1,80 +1,80 @@ # encoding: UTF-8 class CourseMessages < ActiveRecord::Migration def up - Course.all.each do |course| - transaction do - put course.id - course.course_messages << CourseMessage.new(:user_id => course.tea_id,:course_id => course.id) - # 作业 - course.homework_commons.each do |homework_common| - homework_common.course.members.each do |m| - if m.user_id != homework_common.user_id - if m.created_on < homework_common.created_at - homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) - end - end - end - end - - # 通知 - course.news.each do |new| - new.course.members.each do |m| - if m.user_id != new.author_id - if m.created_on < new.created_on # 在成员加入课程之后 - new.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) - end - end - end - end - - # 通知的回复 - course.news.each do |new| - if new.comments - new.comments.each do |comment| - if comment.author_id != comment.commented.author_id - comment.course_messages << CourseMessage.new(:user_id => comment.commented.author_id, :course_id => course.id, :viewed => true) - end - end - end - end - - # 讨论区 - if course.boards.first - course.boards.first.messages.each do |message| - if message.parent_id.nil? # 主贴 - message.course.members.each do |m| - if message.author.allowed_to?(:as_teacher, message.course) && m.user_id != message.author_id # 老师 自己的帖子不给自己发送消息 - if m.created_on < message.created_on - message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) - end - end - end - else # 回帖 - message.course.members.each do |m| - if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 - if m.created_on < message.created_on - message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) - end - end - end - end - end - end - - # 问卷 - Poll.where("polls_type = 'Course' and polls_group_id = #{course.id}").each do |poll| - if poll.polls_status == 2 #问卷是发布状态 - Course.find(poll.polls_group_id).members.each do |m| - if m.user_id != poll.user_id - if m.created_on < poll.created_at - poll.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) - end - end - end - elsif poll.polls_status == 1 #问卷是新建状态 - poll.course_messages.destroy_all - end - end + # Course.all.each do |course| + # transaction do + # put course.id + # course.course_messages << CourseMessage.new(:user_id => course.tea_id,:course_id => course.id) + # # 作业 + # course.homework_commons.each do |homework_common| + # homework_common.course.members.each do |m| + # if m.user_id != homework_common.user_id + # if m.created_on < homework_common.created_at + # homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # end + # + # # 通知 + # course.news.each do |new| + # new.course.members.each do |m| + # if m.user_id != new.author_id + # if m.created_on < new.created_on # 在成员加入课程之后 + # new.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # end + # + # # 通知的回复 + # course.news.each do |new| + # if new.comments + # new.comments.each do |comment| + # if comment.author_id != comment.commented.author_id + # comment.course_messages << CourseMessage.new(:user_id => comment.commented.author_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # end + # + # # 讨论区 + # if course.boards.first + # course.boards.first.messages.each do |message| + # if message.parent_id.nil? # 主贴 + # message.course.members.each do |m| + # if message.author.allowed_to?(:as_teacher, message.course) && m.user_id != message.author_id # 老师 自己的帖子不给自己发送消息 + # if m.created_on < message.created_on + # message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # else # 回帖 + # message.course.members.each do |m| + # if m.user_id == Message.find(message.parent_id).author_id && m.user_id != message.author_id # 只针对主贴回复,回复自己的帖子不发消息 + # if m.created_on < message.created_on + # message.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # end + # end + # end + # + # # 问卷 + # Poll.where("polls_type = 'Course' and polls_group_id = #{course.id}").each do |poll| + # if poll.polls_status == 2 #问卷是发布状态 + # Course.find(poll.polls_group_id).members.each do |m| + # if m.user_id != poll.user_id + # if m.created_on < poll.created_at + # poll.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => true) + # end + # end + # end + # elsif poll.polls_status == 1 #问卷是新建状态 + # poll.course_messages.destroy_all + # end + # end # 作品评阅 # course.homework_commons.each do |homework_common| @@ -107,8 +107,8 @@ class CourseMessages < ActiveRecord::Migration # end # 作品讨论 - end - end + # end + # end end def down diff --git a/db/migrate/20150829081822_update_message_time.rb b/db/migrate/20150829081822_update_message_time.rb index 09e42b6d1..a5b2457ad 100644 --- a/db/migrate/20150829081822_update_message_time.rb +++ b/db/migrate/20150829081822_update_message_time.rb @@ -1,25 +1,25 @@ class UpdateMessageTime < ActiveRecord::Migration def up - course_count = CourseMessage.all.count / 30 + 1 - transaction do - for i in 1 ... course_count do i - CourseMessage.page(i).per(30).each do |cmessage| - if cmessage.course_message - if cmessage.course_message.respond_to?("created_at") - cmessage.created_at = cmessage.course_message.created_at - elsif cmessage.course_message.respond_to?("created_on") - cmessage.created_at = cmessage.course_message.created_on - end - cmessage.save - puts cmessage.id - - course_all_message = MessageAll.where("message_type = '#{cmessage.class.to_s}' and message_id = '#{cmessage.id}'").first - course_all_message.created_at = cmessage.created_at - course_all_message.save - end - end - end - end + # course_count = CourseMessage.all.count / 30 + 1 + # transaction do + # for i in 1 ... course_count do i + # CourseMessage.page(i).per(30).each do |cmessage| + # if cmessage.course_message + # if cmessage.course_message.respond_to?("created_at") + # cmessage.created_at = cmessage.course_message.created_at + # elsif cmessage.course_message.respond_to?("created_on") + # cmessage.created_at = cmessage.course_message.created_on + # end + # cmessage.save + # puts cmessage.id + # + # course_all_message = MessageAll.where("message_type = '#{cmessage.class.to_s}' and message_id = '#{cmessage.id}'").first + # course_all_message.created_at = cmessage.created_at + # course_all_message.save + # end + # end + # end + # end end def down diff --git a/db/migrate/20150829130302_update_forge_message_time.rb b/db/migrate/20150829130302_update_forge_message_time.rb index 295cafea6..3121278ae 100644 --- a/db/migrate/20150829130302_update_forge_message_time.rb +++ b/db/migrate/20150829130302_update_forge_message_time.rb @@ -1,25 +1,25 @@ class UpdateForgeMessageTime < ActiveRecord::Migration def up - forge_count = ForgeMessage.all.count / 30 + 1 - transaction do - for i in 1 ... forge_count do i - ForgeMessage.page(i).per(30).each do |fmessage| - if fmessage.forge_message - if fmessage.forge_message.respond_to?("created_at") - fmessage.created_at = fmessage.forge_message.created_at - elsif fmessage.forge_message.respond_to?("created_on") - fmessage.created_at = fmessage.forge_message.created_on - end - fmessage.save - puts fmessage.id - - forge_all_message = MessageAll.where("message_type = '#{fmessage.class.to_s}' and message_id = '#{fmessage.id}'").first - forge_all_message.created_at = fmessage.created_at - forge_all_message.save - end - end - end - end + # forge_count = ForgeMessage.all.count / 30 + 1 + # transaction do + # for i in 1 ... forge_count do i + # ForgeMessage.page(i).per(30).each do |fmessage| + # if fmessage.forge_message + # if fmessage.forge_message.respond_to?("created_at") + # fmessage.created_at = fmessage.forge_message.created_at + # elsif fmessage.forge_message.respond_to?("created_on") + # fmessage.created_at = fmessage.forge_message.created_on + # end + # fmessage.save + # puts fmessage.id + # + # forge_all_message = MessageAll.where("message_type = '#{fmessage.class.to_s}' and message_id = '#{fmessage.id}'").first + # forge_all_message.created_at = fmessage.created_at + # forge_all_message.save + # end + # end + # end + # end end def down diff --git a/db/migrate/20150831070611_about_memo_message.rb b/db/migrate/20150831070611_about_memo_message.rb index fde94d2f9..a6e4a34c1 100644 --- a/db/migrate/20150831070611_about_memo_message.rb +++ b/db/migrate/20150831070611_about_memo_message.rb @@ -1,34 +1,34 @@ class AboutMemoMessage < ActiveRecord::Migration def up - Memo.all.each do |memo| - transaction do - # 贴吧帖子 - receivers = [] - u = User.find(6) - receivers << u - # 主贴 - if memo.parent_id.nil? - if memo.author_id != memo.forum.creator_id # 发帖人不是吧主 - receivers << memo.forum.creator - end - else # 回帖 - # 添加吧主 - if memo.author_id != memo.forum.creator_id - receivers << memo.forum.creator - end - # 添加发帖人 - unless memo.parent.nil? - if memo.author_id != memo.parent.author_id - receivers << memo.parent.author - puts memo.id - end - end - end - receivers.each do |r| - memo.memo_messages << MemoMessage.new(:user_id => r.id, :forum_id => memo.forum_id, :memo_id => memo.id, :memo_type => "Memo", :viewed => true) - end - end - end + # Memo.all.each do |memo| + # transaction do + # # 贴吧帖子 + # receivers = [] + # u = User.find(6) + # receivers << u + # # 主贴 + # if memo.parent_id.nil? + # if memo.author_id != memo.forum.creator_id # 发帖人不是吧主 + # receivers << memo.forum.creator + # end + # else # 回帖 + # # 添加吧主 + # if memo.author_id != memo.forum.creator_id + # receivers << memo.forum.creator + # end + # # 添加发帖人 + # unless memo.parent.nil? + # if memo.author_id != memo.parent.author_id + # receivers << memo.parent.author + # puts memo.id + # end + # end + # end + # receivers.each do |r| + # memo.memo_messages << MemoMessage.new(:user_id => r.id, :forum_id => memo.forum_id, :memo_id => memo.id, :memo_type => "Memo", :viewed => true) + # end + # end + # end end def down diff --git a/db/migrate/20150831093918_about_user_feedback_message.rb b/db/migrate/20150831093918_about_user_feedback_message.rb index d021bc3ad..a76b7c5e3 100644 --- a/db/migrate/20150831093918_about_user_feedback_message.rb +++ b/db/migrate/20150831093918_about_user_feedback_message.rb @@ -1,34 +1,34 @@ class AboutUserFeedbackMessage < ActiveRecord::Migration def up - JournalsForMessage.all.each do |jour_for_message| - transaction do - # 主留言 - if jour_for_message.jour_type == 'Principal' - receivers = [] - if jour_for_message.reply_id == 0 - if jour_for_message.user_id != jour_for_message.jour_id # 过滤自己给自己的留言消息 - receivers << jour_for_message.jour - end - else # 留言回复 - reply_to = User.find(jour_for_message.reply_id) - if jour_for_message.user_id != jour_for_message.reply_id # 添加我回复的那个人 - receivers << reply_to - end - unless jour_for_message.parent.nil? - if jour_for_message.user_id != jour_for_message.parent.jour_id && jour_for_message.reply_id != jour_for_message.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发 - receivers << jour_for_message.parent.jour - end - end - end - unless receivers.blank? - receivers.each do |r| - puts jour_for_message.id - jour_for_message.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => jour_for_message.id, :journals_for_message_type => "Principal", :viewed => true) - end - end - end - end - end + # JournalsForMessage.all.each do |jour_for_message| + # transaction do + # # 主留言 + # if jour_for_message.jour_type == 'Principal' + # receivers = [] + # if jour_for_message.reply_id == 0 + # if jour_for_message.user_id != jour_for_message.jour_id # 过滤自己给自己的留言消息 + # receivers << jour_for_message.jour + # end + # else # 留言回复 + # reply_to = User.find(jour_for_message.reply_id) + # if jour_for_message.user_id != jour_for_message.reply_id # 添加我回复的那个人 + # receivers << reply_to + # end + # unless jour_for_message.parent.nil? + # if jour_for_message.user_id != jour_for_message.parent.jour_id && jour_for_message.reply_id != jour_for_message.parent.jour_id # 给东家发信息,如果回复的对象是东家则不发 + # receivers << jour_for_message.parent.jour + # end + # end + # end + # unless receivers.blank? + # receivers.each do |r| + # puts jour_for_message.id + # jour_for_message.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => jour_for_message.id, :journals_for_message_type => "Principal", :viewed => true) + # end + # end + # end + # end + # end end def down diff --git a/db/migrate/20150901004812_update_memo_message_time.rb b/db/migrate/20150901004812_update_memo_message_time.rb index 80ae557fc..8760a50a4 100644 --- a/db/migrate/20150901004812_update_memo_message_time.rb +++ b/db/migrate/20150901004812_update_memo_message_time.rb @@ -1,25 +1,25 @@ class UpdateMemoMessageTime < ActiveRecord::Migration def up - memo_count = Memo.all.count / 30 + 1 - transaction do - for i in 1 ... memo_count do i - MemoMessage.page(i).per(30).each do |memo_message| - if memo_message.memo - if memo_message.memo.respond_to?("created_at") - memo_message.created_at = memo_message.memo.created_at - elsif memo_message.memo.respond_to?("created_on") - memo_message.created_at = memo_message.memo.created_on - end - memo_message.save - puts memo_message.id - - memo_messages = MessageAll.where("message_type = '#{memo_message.class.to_s}' and message_id = '#{memo_message.id}'").first - memo_messages.created_at = memo_message.created_at - memo_messages.save - end - end - end - end + # memo_count = Memo.all.count / 30 + 1 + # transaction do + # for i in 1 ... memo_count do i + # MemoMessage.page(i).per(30).each do |memo_message| + # if memo_message.memo + # if memo_message.memo.respond_to?("created_at") + # memo_message.created_at = memo_message.memo.created_at + # elsif memo_message.memo.respond_to?("created_on") + # memo_message.created_at = memo_message.memo.created_on + # end + # memo_message.save + # puts memo_message.id + # + # memo_messages = MessageAll.where("message_type = '#{memo_message.class.to_s}' and message_id = '#{memo_message.id}'").first + # memo_messages.created_at = memo_message.created_at + # memo_messages.save + # end + # end + # end + # end end def down diff --git a/db/migrate/20150901004910_update_userfeeback_message_time.rb b/db/migrate/20150901004910_update_userfeeback_message_time.rb index 686bc496e..95bfbd2ac 100644 --- a/db/migrate/20150901004910_update_userfeeback_message_time.rb +++ b/db/migrate/20150901004910_update_userfeeback_message_time.rb @@ -1,25 +1,25 @@ class UpdateUserfeebackMessageTime < ActiveRecord::Migration def up - user_feedback_count = UserFeedbackMessage.all.count / 30 + 1 - transaction do - for i in 1 ... user_feedback_count do i - UserFeedbackMessage.page(i).per(30).each do |ufm| - if ufm.journals_for_message - if ufm.journals_for_message.respond_to?("created_at") - ufm.created_at = ufm.journals_for_message.created_at - elsif ufm.journals_for_message.respond_to?("created_on") - ufm.created_at = ufm.journals_for_message.created_on - end - puts ufm.id - ufm.save - - user_feedback_messages = MessageAll.where("message_type = '#{ufm.class.to_s}' and message_id = '#{ufm.id}'").first - user_feedback_messages.created_at = ufm.created_at - user_feedback_messages.save - end - end - end - end + # user_feedback_count = UserFeedbackMessage.all.count / 30 + 1 + # transaction do + # for i in 1 ... user_feedback_count do i + # UserFeedbackMessage.page(i).per(30).each do |ufm| + # if ufm.journals_for_message + # if ufm.journals_for_message.respond_to?("created_at") + # ufm.created_at = ufm.journals_for_message.created_at + # elsif ufm.journals_for_message.respond_to?("created_on") + # ufm.created_at = ufm.journals_for_message.created_on + # end + # puts ufm.id + # ufm.save + # + # user_feedback_messages = MessageAll.where("message_type = '#{ufm.class.to_s}' and message_id = '#{ufm.id}'").first + # user_feedback_messages.created_at = ufm.created_at + # user_feedback_messages.save + # end + # end + # end + # end end def down