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