From 0b60f3fa3fa0cfab8634b309b17044a8d62e9943 Mon Sep 17 00:00:00 2001 From: wangyuting Date: Mon, 29 May 2023 15:28:06 +0800 Subject: [PATCH] * Optimize bug batchChangePlan function. --- module/bug/config/form.php | 2 +- module/bug/control.php | 21 ++++++------ module/bug/model.php | 54 +++--------------------------- module/bug/ui/batchcreate.html.php | 2 +- module/bug/zen.php | 41 +++++++++++++++++++++++ 5 files changed, 59 insertions(+), 61 deletions(-) diff --git a/module/bug/config/form.php b/module/bug/config/form.php index b191098f63..3da6de63a9 100644 --- a/module/bug/config/form.php +++ b/module/bug/config/form.php @@ -108,7 +108,7 @@ $config->bug->form->resolve['duplicateBug'] = array('required' => false, 'type $config->bug->form->resolve['buildName'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->resolve['createBuild'] = array('required' => false, 'type' => 'string', 'default' => 'off'); $config->bug->form->resolve['buildExecution'] = array('required' => false, 'type' => 'int', 'default' => 0); -$config->bug->form->confirm['comment'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->bug->form->resolve['comment'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->activate = array(); $config->bug->form->activate['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); diff --git a/module/bug/control.php b/module/bug/control.php index a27c325254..3a7007f17c 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -696,15 +696,13 @@ class bug extends control if(!empty($_POST)) { $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())); + $message = ''; + $bugIDList = array(); $uploadImages = $this->post->uploadImage; $bugImagesFiles = $this->session->bugImagesFile; - $bugIDList = array(); - $message = ''; foreach($bugs as $index => $bug) { $uploadImage = !empty($uploadImages[$index]) ? $uploadImages[$index] : ''; @@ -735,10 +733,8 @@ class bug extends control $this->bugZen->assignBatchCreateVars($executionID, $product, $branch, $output, $this->session->bugImagesFile); $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->batchCreate; - $this->view->users = $this->user->getPairs('devfirst|noclosed'); $this->view->moduleID = $moduleID; $this->view->product = $product; - $this->view->productID = $product->id; $this->display(); } @@ -826,6 +822,7 @@ class bug extends control $this->action->logHistory($actionID, $changes); } } + $this->loadModel('score')->create('ajax', 'batchOther'); return array('load' => $this->session->bugList, 'closeModal' => true); } @@ -851,6 +848,7 @@ class bug extends control $this->bug->update($bug); } + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('score')->create('ajax', 'batchOther'); } @@ -867,13 +865,14 @@ class bug extends control */ public function batchChangePlan(int $planID) { - if($this->post->bugIDList) + if(!empty($_POST) && isset($_POST['bugIdList'])) { - $bugIdList = array_unique($this->post->bugIDList); - $this->bug->batchChangePlan($bugIdList, $planID); + $bugIdList = array_unique($this->post->bugIdList); + $this->bugZen->batchChangePlan($bugIdList, $planID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->loadModel('score')->create('ajax', 'batchOther'); } - $this->loadModel('score')->create('ajax', 'batchOther'); return array('load' => $this->session->bugList, 'closeModal' => true); } @@ -898,6 +897,7 @@ class bug extends control { $bug->id = (int)$bugID; $bug->assignedTo = $assignedTo; + $this->bug->assign($bug); } @@ -932,6 +932,7 @@ class bug extends control $bug->id = (int)$bugID; $bug->confirmed = 1; $bug->assignedTo = $this->app->user->account; + $this->bug->confirm($bug); $message = $this->executeHooks($bugID); } diff --git a/module/bug/model.php b/module/bug/model.php index e6c9d26765..7d068c9e4d 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -365,11 +365,11 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug, 'deleteFiles,comment') ->autoCheck() ->batchCheck($this->config->bug->edit->requiredFields, 'notempty') - ->checkIF($bug->resolvedBy, 'resolution', 'notempty') - ->checkIF($bug->closedBy, 'resolution', 'notempty') - ->checkIF($bug->notifyEmail,'notifyEmail', 'email') - ->checkIF($bug->resolution == 'duplicate', 'duplicateBug', 'notempty') - ->checkIF($bug->resolution == 'fixed', 'resolvedBuild','notempty') + ->checkIF(!empty($bug->resolvedBy), 'resolution', 'notempty') + ->checkIF(!empty($bug->closedBy), 'resolution', 'notempty') + ->checkIF(!empty($bug->notifyEmail),'notifyEmail', 'email') + ->checkIF(!empty($bug->resolution) && $bug->resolution == 'duplicate', 'duplicateBug', 'notempty') + ->checkIF(!empty($bug->resolution) && $bug->resolution == 'fixed', 'resolvedBuild','notempty') ->checkFlow() ->where('id')->eq($bug->id) ->exec(); @@ -727,50 +727,6 @@ class bugModel extends model return $allChanges; } - /** - * 批量修改bug计划。 - * Batch change the plan of bug. - * - * @param array $bugIdList - * @param int $planID - * @access public - * @return void - */ - public function batchChangePlan(array $bugIdList, int $planID): void - { - $this->loadModel('action'); - $oldBugs = $this->getByIdList($bugIdList); - $unlinkPlans = array(); - $link2Plans = array(); - foreach($bugIdList as $bugID) - { - $oldBug = $oldBugs[$bugID]; - if($planID == $oldBug->plan) continue; - - /* Bugs link to plans and bugs unlink to plans. */ - $unlinkPlans[$oldBug->plan] = empty($unlinkPlans[$oldBug->plan]) ? $bugID : "{$unlinkPlans[$oldBug->plan]},$bugID"; - $link2Plans[$planID] = empty($link2Plans[$planID]) ? $bugID : "{$link2Plans[$planID]},$bugID"; - - /* Update bug plan. */ - $bug = new stdclass(); - $bug->plan = $planID; - $this->bugTao->updateByID((int)$bugID, $bug); - if(!dao::isError()) - { - $changes = common::createChanges($oldBug, $bug); - $actionID = $this->action->create('bug', $bugID, 'Edited'); - $this->action->logHistory($actionID, $changes); - } - } - - /* Record plan action. */ - if(!dao::isError()) - { - foreach($unlinkPlans as $planID => $bugs) $this->action->create('productplan', $planID, 'unlinkbug', '', $bugs); - foreach($link2Plans as $planID => $bugs) $this->action->create('productplan', $planID, 'linkbug', '', $bugs); - } - } - /** * 批量解决bug。 * Batch resolve bugs. diff --git a/module/bug/ui/batchcreate.html.php b/module/bug/ui/batchcreate.html.php index a53b90a1b0..173050ba41 100644 --- a/module/bug/ui/batchcreate.html.php +++ b/module/bug/ui/batchcreate.html.php @@ -246,7 +246,7 @@ formBatchPanel on::change('[data-name="project"]', 'loadProductExecutionsByProject'), on::change('[data-name="execution"]', 'loadExecutionBuilds'), on::change('[data-name="region"]', 'setLane'), - formHidden('product', $productID), + formHidden('product', $product->id), ); render(); diff --git a/module/bug/zen.php b/module/bug/zen.php index 75cfe29921..7ff1cab225 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -2279,4 +2279,45 @@ class bugZen extends bug return $bugs; } + + /** + * 批量修改bug计划。 + * Batch change the plan of bug. + * + * @param array $bugIdList + * @param int $planID + * @access public + * @return bool + */ + protected function batchChangePlan(array $bugIdList, int $planID): bool + { + $oldBugs = $this->bug->getByIdList($bugIdList); + $unlinkPlans = array(); + $link2Plans = array(); + foreach($bugIdList as $bugID) + { + $oldBug = $oldBugs[$bugID]; + if($planID == $oldBug->plan) continue; + + /* Bugs link to plans and bugs unlink to plans. */ + $unlinkPlans[$oldBug->plan] = empty($unlinkPlans[$oldBug->plan]) ? $bugID : "{$unlinkPlans[$oldBug->plan]},$bugID"; + $link2Plans[$planID] = empty($link2Plans[$planID]) ? $bugID : "{$link2Plans[$planID]},$bugID"; + + /* Update bug plan. */ + $bug = new stdclass(); + $bug->id = $bugID; + $bug->plan = $planID; + + $this->bug->update($bug); + } + + if(dao::isError()) return false; + + /* Record plan action. */ + $this->loadModel('action'); + foreach($unlinkPlans as $planID => $bugs) $this->action->create('productplan', $planID, 'unlinkbug', '', $bugs); + foreach($link2Plans as $planID => $bugs) $this->action->create('productplan', $planID, 'linkbug', '', $bugs); + + return !dao::isError(); + } }