diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 0d6a1a0e7..8da82afd3 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -11,6 +11,7 @@ class HomeworkCommonController < ApplicationController before_filter :member_of_course, :only => [:index] def index + update_homework_time(@course.homework_commons) @new_homework = HomeworkCommon.new @new_homework.homework_detail_manual = HomeworkDetailManual.new @new_homework.course = @course @@ -385,4 +386,42 @@ class HomeworkCommonController < ApplicationController student_works += student_works student_works[index + 1 .. index + n] end + + def update_homework_time homeworks + unless homeworks.nil? + homeworks.each do |h| + if h.homework_type == 3 + student_works = h.student_works.where("project_id != 0") + time = h.updated_at + unless student_works.nil? + student_works.each do |s| + project = Project.find s.project_id + unless project.nil? && project.gpid.nil? + begin + # gitlab端获取默认分支 + g = Gitlab.client + default_branch = g.project(project.gpid).default_branch + changesets = g.commits(project.gpid, :ref_name => default_branch) + changesets_latest_coimmit = changesets[0] + unless changesets[0].blank? + if time < changesets_latest_coimmit.created_at + time = changesets_latest_coimmit.created_at + end + end + rescue + logger.error("############## ==> update homework project time") + end + end + end + end + puts h.updated_at + puts time + s_time = time + if format_time(time) > format_time(h.updated_at) + h.update_attribute(:updated_at, s_time) + end + end + end + end + end end diff --git a/lib/tasks/homework_update.rake b/lib/tasks/homework_update.rake new file mode 100644 index 000000000..b2246bfd5 --- /dev/null +++ b/lib/tasks/homework_update.rake @@ -0,0 +1,7 @@ +namespace :homework_update do + desc "update homework updated_at" + task :update_homework => :environment do + stu_pro = StudentWork.where("project_id != 0") + + end +end \ No newline at end of file