From eb67724fc56863542bc81c3e4c04ae6e8b73849e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 19 Mar 2020 15:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=85=B3=E5=8D=A1=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 762943183..44fa18f56 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -313,19 +313,27 @@ class ChallengesController < ApplicationController end rescue => e tip_exception("上移失败: #{e.message}") + raise ActiveRecord::Rollback end end def destroy next_challenges = @shixun.challenges.where("position > #{@challenge.position}") - next_challenges.update_all("position = position - 1") - # Todo: 实训修改后,关卡需要重置 - # shixun_modify_status_without_publish(@shixun, 1) - @challenge.destroy - # 关卡位置被删除,需要修改脚本 - script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.shixun_info.update_column(:evaluate_script, script) + begin + ActiveRecord::Base.transaction do + next_challenges.update_all("position = position - 1") + # Todo: 实训修改后,关卡需要重置 + # shixun_modify_status_without_publish(@shixun, 1) + @challenge.destroy + # 关卡位置被删除,需要修改脚本 + script = modify_shixun_script @shixun, @shixun.evaluate_script + @shixun.shixun_info.update_column(:evaluate_script, script) + end + rescue => e + tip_exception("删除关卡失败: #{e.message}") + raise ActiveRecord::Rollback + end end