From fb436a2df5837b77744ead0f444edec18735a9da Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 26 May 2023 15:48:39 +0800 Subject: [PATCH] * Fix bug for saving bug-batchCreate, and modify bugTao-checkBugsForBatchCreate to bugZen-checkBugsForBatchCreate. --- module/bug/control.php | 4 + module/bug/model.php | 44 ------- module/bug/test/bug.class.php | 31 ----- .../test/model/checkbugsforbatchcreate.php | 111 ------------------ module/bug/ui/batchcreate.html.php | 2 +- module/bug/zen.php | 40 +++++++ 6 files changed, 45 insertions(+), 187 deletions(-) delete mode 100755 module/bug/test/model/checkbugsforbatchcreate.php diff --git a/module/bug/control.php b/module/bug/control.php index 37b0c9018f..5af5051342 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -702,6 +702,10 @@ class bug extends control { $bugs = $this->bugZen->buildBugsForBatchCreate($productID, $branch, $this->session->bugImagesFile); + /* Check bugs. */ + $bugs = $this->bugZen->checkBugsForBatchCreate($bugs, $productID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + /* Batch create bugs. */ $actions = $this->bug->batchCreate($bugs, $productID, $output, $this->post->uploadImage, $this->session->bugImagesFile); diff --git a/module/bug/model.php b/module/bug/model.php index ea07178bc5..abb79377e3 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -88,10 +88,6 @@ class bugModel extends model $this->loadModel('action'); if(!empty($uploadImages)) $this->loadModel('file'); - /* Check bugs. */ - $bugs = $this->bugTao->checkBugsForBatchCreate($bugs, $productID); - if(dao::isError()) return false; - $actions = array(); foreach($bugs as $index => $bug) { @@ -2851,46 +2847,6 @@ class bugModel extends model return $index; } - /** - * 检查批量创建的bug的数据。 - * Check the batch created bugs. - * - * @param array $bugs - * @param int $productID - * @access protected - * @return array - */ - protected function checkBugsForBatchCreate(array $bugs, int $productID): array - { - $this->loadModel('common'); - - /* Check whether the bugs meet the requirements, and if not, remove it. */ - foreach($bugs as $index => $bug) - { - $result = $this->common->removeDuplicate('bug', $bug, "product={$productID}"); - if(zget($result, 'stop', false) !== false) - { - unset($bugs[$index]); - continue; - } - - /* If the bug is not valid data, unset it.*/ - if($this->common->checkValidRow('bug', $bug, $index)) unset($bugs[$index]); - } - - /* Check required fields. */ - foreach($bugs as $index => $bug) - { - foreach(explode(',', $this->config->bug->create->requiredFields) as $field) - { - $field = trim($field); - if($field and empty($bug->$field) and $field != 'title') dao::$errors["{$field}[{$index}]"] = sprintf($this->lang->error->notempty, $this->lang->bug->$field); - } - } - - return $bugs; - } - /** * 批量创建bug前处理上传图片。 * Before batch creating bugs, process the uploaded images. diff --git a/module/bug/test/bug.class.php b/module/bug/test/bug.class.php index a0bfbd9197..fde81fa834 100644 --- a/module/bug/test/bug.class.php +++ b/module/bug/test/bug.class.php @@ -2198,37 +2198,6 @@ class bugTest return $tester->config->bug->dtable->fieldList['actions']['actionsMap']; } - /** - * 测试检查批量创建的bug的数据。 - * Test check the batch created bugs. - * - * @param array $bugs - * @param int $productID - * @access public - * @return array|string - */ - public function checkBugsForBatchCreateTest(array $bugs, int $productID): array|string - { - $bugs = $this->objectModel->checkBugsForBatchCreate($bugs, $productID); - - $return = ''; - if(dao::isError()) - { - $errors = dao::getError(); - foreach($errors as $key => $value) - { - if(is_string($value)) $return .= "{$value}"; - if(is_array($value)) $return .= implode('', $value); - } - return $return; - } - else - { - $return = array_keys($bugs); - return implode(',', $return); - } - } - /** * 测试检查批量创建的bug的数据。 * Test check the batch created bugs. diff --git a/module/bug/test/model/checkbugsforbatchcreate.php b/module/bug/test/model/checkbugsforbatchcreate.php deleted file mode 100755 index bbd0e95c6a..0000000000 --- a/module/bug/test/model/checkbugsforbatchcreate.php +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env php -checkBugsForBatchCreate(); -cid=1 -pid=1 - -*/ - -$emptyModule = new stdclass(); -$emptyModule->title = '一个标题'; -$emptyModule->openedBuild = 1; -$emptyModule->module = 0; - -$emptyBuild = new stdclass(); -$emptyBuild->title = '111'; -$emptyBuild->openedBuild = 0; -$emptyBuild->module = 1; - -$emptyItem = new stdclass(); -$emptyItem->title = ''; -$emptyItem->module = 0; -$emptyItem->openedBuild = 0; - -$productID = 1; - -$emptyAll = new stdclass(); -$emptyAll->title = ''; -$emptyAll->openedBuild = 0; -$emptyAll->product = 1; -$emptyAll->branch = 0; -$emptyAll->module = 0; -$emptyAll->project = 0; -$emptyAll->execution = 0; -$emptyAll->deadline = ''; -$emptyAll->steps = ''; -$emptyAll->type = ''; -$emptyAll->pri = 0; -$emptyAll->severity = 0; -$emptyAll->keywords = ''; - -$hasModuleBuild = new stdclass(); -$hasModuleBuild->title = '11'; -$hasModuleBuild->openedBuild = 1; -$hasModuleBuild->product = 1; -$hasModuleBuild->branch = 0; -$hasModuleBuild->module = 1; -$hasModuleBuild->project = 0; -$hasModuleBuild->execution = 0; -$hasModuleBuild->deadline = ''; -$hasModuleBuild->steps = ''; -$hasModuleBuild->type = ''; -$hasModuleBuild->pri = 0; -$hasModuleBuild->severity = 0; -$hasModuleBuild->keywords = ''; - -$normal1 = new stdclass(); -$normal1->title = '一个标题'; -$normal1->openedBuild = 1; -$normal1->product = 1; -$normal1->branch = 0; -$normal1->module = 1; -$normal1->project = 1; -$normal1->execution = 11; -$normal1->deadline = '2023-01-01'; -$normal1->steps = '一个步骤'; -$normal1->type = 'codeerror'; -$normal1->pri = 1; -$normal1->severity = 1; -$normal1->keywords = '关键词1'; - - -$normal2 = new stdclass(); -$normal2->title = '标题'; -$normal2->openedBuild = 1; -$normal2->product = 1; -$normal2->branch = 0; -$normal2->module = 1; -$normal2->project = 1; -$normal2->execution = 11; -$normal2->deadline = '2023-01-01'; -$normal2->steps = '步骤'; -$normal2->type = 'config'; -$normal2->pri = 1; -$normal2->severity = 1; -$normal2->keywords = '关键词'; - -$bugs1 = array('emptyModule' => $emptyModule); -$bugs2 = array('emptyBuild' => $emptyBuild); -$bugs3 = array('emptyModule' => $emptyModule, 'emptyBuild' => $emptyBuild); -$bugs4 = array('emptyItem' => $emptyItem); -$bugs5 = array('emptyAll' => $emptyAll); -$bugs6 = array('emptyItem' => $emptyItem, 'emptyAll' => $emptyAll); -$bugs7 = array('hasModuleBuild' => $hasModuleBuild, 'narmal1' => $normal1, 'narmal2' => $normal2); - -$bug = new bugTest(); - -global $tester; -$tester->config->bug->create->requiredFields .= ',module'; - -r($bug->checkBugsForBatchCreateTest($bugs1, $productID)) && p() && e('『所属模块』不能为空。'); // 测试检查 不输入模块 的bugs -r($bug->checkBugsForBatchCreateTest($bugs2, $productID)) && p() && e('『影响版本』不能为空。'); // 测试检查 不输入版本 的bugs -r($bug->checkBugsForBatchCreateTest($bugs3, $productID)) && p() && e('『所属模块』不能为空。『影响版本』不能为空。'); // 测试检查 不输入模块 不输入版本 的bugs -r($bug->checkBugsForBatchCreateTest($bugs4, $productID)) && p() && e('『影响版本』不能为空。『所属模块』不能为空。'); // 测试检查 空对象 的bugs -r($bug->checkBugsForBatchCreateTest($bugs5, $productID)) && p() && e('『影响版本』不能为空。『所属模块』不能为空。'); // 测试检查 不输入任务字段 的bugs -r($bug->checkBugsForBatchCreateTest($bugs6, $productID)) && p() && e('『影响版本』不能为空。『所属模块』不能为空。『影响版本』不能为空。『所属模块』不能为空。'); // 测试检查 空对象 不输入任务字段 的bugs -r($bug->checkBugsForBatchCreateTest($bugs7, $productID)) && p() && e('hasModuleBuild,narmal1,narmal2'); // 测试检查 有模块和版本 两个有所有字段 的bugs diff --git a/module/bug/ui/batchcreate.html.php b/module/bug/ui/batchcreate.html.php index 44d66886d5..a53b90a1b0 100644 --- a/module/bug/ui/batchcreate.html.php +++ b/module/bug/ui/batchcreate.html.php @@ -22,7 +22,7 @@ foreach(explode(',', $config->bug->create->requiredFields) as $field) if($field) { $requiredFields[$field] = ''; - if(strpos(",{$config->bug->custom->batchCreateFields},", ",{$field},") !== false) $visibleFields[$field] = ''; + if(strpos(",{$config->bug->list->customBatchCreateFields},", ",{$field},") !== false) $visibleFields[$field] = ''; } } diff --git a/module/bug/zen.php b/module/bug/zen.php index fbcec90e42..0b2432d635 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -2254,4 +2254,44 @@ class bugZen extends bug return !dao::isError(); } + + /** + * 检查批量创建的bug的数据。 + * Check the batch created bugs. + * + * @param array $bugs + * @param int $productID + * @access protected + * @return array + */ + protected function checkBugsForBatchCreate(array $bugs, int $productID): array + { + $this->loadModel('common'); + + /* Check whether the bugs meet the requirements, and if not, remove it. */ + foreach($bugs as $index => $bug) + { + $result = $this->common->removeDuplicate('bug', $bug, "product={$productID}"); + if(zget($result, 'stop', false) !== false) + { + unset($bugs[$index]); + continue; + } + + /* If the bug is not valid data, unset it.*/ + if($this->common->checkValidRow('bug', $bug, $index)) unset($bugs[$index]); + } + + /* Check required fields. */ + foreach($bugs as $index => $bug) + { + foreach(explode(',', $this->config->bug->create->requiredFields) as $field) + { + $field = trim($field); + if($field and empty($bug->$field) and $field != 'title') dao::$errors["{$field}[{$index}]"] = sprintf($this->lang->error->notempty, $this->lang->bug->$field); + } + } + + return $bugs; + } }