From 6c8401ab0427dad4457b2d1b567bd61a43e02fae Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 14 Mar 2019 19:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20190314080809_create_shixun_student_works.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/db/migrate/20190314080809_create_shixun_student_works.rb b/db/migrate/20190314080809_create_shixun_student_works.rb index 83bac6c7..09be3891 100644 --- a/db/migrate/20190314080809_create_shixun_student_works.rb +++ b/db/migrate/20190314080809_create_shixun_student_works.rb @@ -1,4 +1,17 @@ class CreateShixunStudentWorks < ActiveRecord::Migration + DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) + + def down_generate_identifier type + if type == "game" + code = DCODES.sample(12).join + return down_generate_identifier(type) if Game.where(identifier: code).present? + elsif type == "myshixun" + code = DCODES.sample(10).join + return down_generate_identifier(type) if Myshixun.where(identifier: code).present? + end + code + end + def up ActiveRecord::Base.transaction do begin @@ -20,6 +33,7 @@ class CreateShixunStudentWorks < ActiveRecord::Migration end gshixun = g.fork(shixun.gpid, user.gid) shixun_tomcat = Redmine::Configuration['shixun_tomcat'] + code = down_generate_identifier("myshixun") # 一般通过默认分支是否存在来判断一个项目是否fork成功 if gshixun.try(:id).present? @@ -64,7 +78,7 @@ class CreateShixunStudentWorks < ActiveRecord::Migration end rescue Exception => e puts ("###failed to exec shixun: current task id is #{e}") - g.delete_project(gshixun.id) if gshixun.try(:id).present? + # g.delete_project(gshixun.id) if gshixun.try(:id).present? raise ActiveRecord::Rollback end end