项目的更新加到作业的最后更新时间中
This commit is contained in:
parent
29c18518e7
commit
0fafbffa49
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue