From eb457f477480057812b97c219c063f89b4db6ada Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 14 Oct 2017 15:25:07 +0800 Subject: [PATCH] add migrate --- app/controllers/games_controller.rb | 29 +++++++++++---------- app/controllers/shixuns_controller.rb | 2 +- app/models/tiding.rb | 19 ++++++++++++++ db/migrate/20171012073054_create_tidings.rb | 18 +++++++++++++ 4 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 app/models/tiding.rb create mode 100644 db/migrate/20171012073054_create_tidings.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 41a4ced17..1bc01fd78 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -91,20 +91,20 @@ class GamesController < ApplicationController # git_repository_url @myshixun, "Myshixun" # @st 0 实践任务 1 选择题任务 def show - g = Gitlab.client - g_name = g.project(@myshixun.gpid).try(:name) - g_rep = @myshixun.repository - g_identifier = g_rep.try(:identifier) - if g_name.include?("-") || g_identifier.include?("-") - g_user_id = @myshixun.owner.try(:gid) - g_name = g_name.split("-") - g_project_name = g_name[0] - num = g_name[1] - g_id = g.current_user_project(g_user_id, g_project_name).first.try(:id) - sql = "update `repositories` set identifier='#{g_project_name}' where id=#{g_rep.id}" - ActiveRecord::Base.connection.execute(sql) - @myshixun.update_attribute(:gpid, g_id) - end + # g = Gitlab.client + # g_name = g.project(@myshixun.gpid).try(:name) + # g_rep = @myshixun.repository + # g_identifier = g_rep.try(:identifier) + # if g_name.include?("-") || g_identifier.include?("-") + # g_user_id = @myshixun.owner.try(:gid) + # g_name = g_name.split("-") + # g_project_name = g_name[0] + # num = g_name[1] + # g_id = g.current_user_project(g_user_id, g_project_name).first.try(:id) + # sql = "update `repositories` set identifier='#{g_project_name}' where id=#{g_rep.id}" + # ActiveRecord::Base.connection.execute(sql) + # @myshixun.update_attribute(:gpid, g_id) + # end # 展示全部实训 # git_myshixun_url_ip @myshixun, user_id @is_subject = params[:is_subject] @@ -112,6 +112,7 @@ class GamesController < ApplicationController # 放置页面ajax数据还没获取就关闭 @game.update_attribute(:status, 0) end + # logger.info("#################%%%%%%#{@game.outputs.first.out_put}") # @games = @myshixun.games.includes(:challenge) @game_challenge = @game.challenge diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index cf01a172f..7eecc484c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -459,7 +459,7 @@ class ShixunsController < ApplicationController s.sync_user(User.current) end gshixun = g.fork(@shixun.gpid, User.current.gid) - if !gshixun.try(:id).blank? + if gshixun.try(:id).present? myshixun.update_column(:gpid, gshixun.id) if myshixun.try(:gpid).blank? # educoder 加入到myshixun中 myshixun_admin_gid = User.where(:login => "educoder").first.try(:gid) diff --git a/app/models/tiding.rb b/app/models/tiding.rb new file mode 100644 index 000000000..68c2f841d --- /dev/null +++ b/app/models/tiding.rb @@ -0,0 +1,19 @@ +# 使用请了解以下描述,不清楚请@Hjqreturn +# +# user_id: 信息接收人 +# trigger_user_id: 信息的触发者,具体情况可能有所不同。eg:产生消息的用户ID;处理消息的用户ID等 +# container_id:消息实体的ID。eg:issue的id +# container_type:消息实体的类型。eg:“Issue","Board" +# parent_container_id:消息实体的父实体消息的id,是为了生成url时使用,避免反复查数据库。eg:message中的board 的id +# parent_container_type:消息实体的父实体消息类型,便于分类。eg:“Message","Board" +# belong_container_id:消息实体所属的实体ID。eg:project_id,course_id,organization_id +# belong_container_type:消息实体所属的实体类型。eg:“Project”,“Course”,"Shixun" +# status:消息实体的状态。eg:“已处理”,“未处理” +# viewed:消息是否已读。eg:1 -> 已读; 0 -> 未读 +# +class Tiding < ActiveRecord::Base + attr_accessible :belong_container_id, :belong_container_type, :container_id, :container_type, :parent_container_id, + :parent_container_type, :status, :trigger_user_id, :user_id, :viewed + + +end diff --git a/db/migrate/20171012073054_create_tidings.rb b/db/migrate/20171012073054_create_tidings.rb new file mode 100644 index 000000000..03b2c88bd --- /dev/null +++ b/db/migrate/20171012073054_create_tidings.rb @@ -0,0 +1,18 @@ +class CreateTidings < ActiveRecord::Migration + def change + create_table :tidings do |t| + t.integer :user_id + t.integer :trigger_user_id + t.integer :container_id + t.string :container_type + t.integer :parent_container_id + t.string :parent_container_type + t.integer :belong_container_id + t.string :belong_container_type + t.integer :status + t.boolean :viewed + + t.timestamps + end + end +end