From 2daed2a4823cdfaba1f98178cb41a3acfd886ac5 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 12 Sep 2023 10:15:41 +0800 Subject: [PATCH] * testtaskModel: refactor the block method. --- module/testtask/model.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/module/testtask/model.php b/module/testtask/model.php index 45d88d72c9..81eb656da2 100755 --- a/module/testtask/model.php +++ b/module/testtask/model.php @@ -834,29 +834,34 @@ class testtaskModel extends model } /** - * update block testtask. + * 阻塞一个测试单。 + * Block a testtask. * - * @param int $taskID + * @param object $task * @access public - * @return void + * @return bool */ - public function block($taskID) + public function block(object $task): bool { - $oldTesttask = $this->getByID($taskID); - $testtask = fixer::input('post') - ->add('id', $taskID) - ->add('status', 'blocked') - ->stripTags($this->config->testtask->editor->block['id'], $this->config->allowedTags) - ->remove('comment')->get(); + $taskID = (int)$task->id; + $oldTask = $this->fetchByID($taskID); + if(!$oldTask || !self::isClickable($oldTask, 'block')) return false; - $testtask = $this->loadModel('file')->processImgURL($testtask, $this->config->testtask->editor->block['id'], $this->post->uid); - $this->dao->update(TABLE_TESTTASK)->data($testtask) + $this->dao->update(TABLE_TESTTASK)->data($task, 'comment,uid') ->autoCheck() ->checkFlow() - ->where('id')->eq((int)$taskID) + ->where('id')->eq($taskID) ->exec(); + if(dao::isError()) return false; - if(!dao::isError()) return common::createChanges($oldTesttask, $testtask); + $changes = common::createChanges($oldTask, $task); + if($changes || $task->comment) + { + $actionID = $this->loadModel('action')->create('testtask', $taskID, 'Blocked', $task->comment); + $this->action->logHistory($actionID, $changes); + } + + return !dao::isError(); } /**