From 35057ad37c0b23c3c679c21ee49a8b56bc0623bc Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 14 Aug 2023 15:08:36 +0800 Subject: [PATCH] * testcase: refactor the methods to batch change type of cases. --- module/testcase/control.php | 14 +++++++------- module/testcase/model.php | 38 ++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index 19d1b4d3ec..0b5176abb4 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1450,17 +1450,17 @@ class testcase extends control /** * Batch review case. * - * @param string $result + * @param string $type * @access public * @return void */ - public function batchCaseTypeChange($result) + public function batchCaseTypeChange($type) { - if(!$this->post->caseIDList) return print(js::locate($this->session->caseList, 'parent')); - $caseIdList = array_unique($this->post->caseIDList); - $this->testcase->batchCaseTypeChange($caseIdList, $result); - - if(dao::isError()) return print(js::error(dao::getError())); + if($this->post->caseIDList) + { + $this->testcase->batchCaseTypeChange($this->post->caseIDList, $type); + if(dao::isError()) return print(js::error(dao::getError())); + } echo js::locate($this->session->caseList, 'parent'); } diff --git a/module/testcase/model.php b/module/testcase/model.php index f097c2480c..dcac47a9d6 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -1451,29 +1451,37 @@ class testcaseModel extends model * Batch case type change. * * @param array $caseIDList - * @param string $result + * @param string $type * @access public * @return array */ - public function batchCaseTypeChange($caseIdList, $result) + public function batchCaseTypeChange($caseIDList, $type) { - $now = helper::now(); - $actions = array(); + $caseIDList = $this->filterIdList($idList); + if(!$caseIDList) return false; + + $oldCases = $this->getByList($caseIDList, "type != {$type}"); + $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->where('type')->ne($type)->('id')->in($caseIDList)->exec(); + if(dao::isError()) return false; + $this->loadModel('action'); - $oldCases = $this->getByList($caseIdList); - foreach($caseIdList as $caseID) - { - $case = new stdClass(); - $case->lastEditedBy = $this->app->user->account; - $case->lastEditedDate = $now; - $case->type = $result; + $case = new stdClass(); + $case->type = $type; + $case->lastEditedBy = $this->app->user->account; + $case->lastEditedDate = helper::now(); - $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->where('id')->eq($caseID)->exec(); - $actionID = $this->action->create('case', $caseID, 'Edited', '', ucfirst($result)); - $changes = common::createChanges($oldCases[$caseID], $case); - $this->action->logHistory($actionID, $changes); + foreach($oldCases as $oldCase) + { + $changes = common::createChanges($oldCase, $case); + if($changes) + { + $actionID = $this->action->create('case', $oldCase->id, 'Edited', '', ucfirst($result)); + $this->action->logHistory($actionID, $changes); + } } + + return !dao::isError(); } /**