From ac7b89db1ed83454ffa6fdd8602ef3f097013565 Mon Sep 17 00:00:00 2001 From: wangyuting Date: Mon, 29 May 2023 09:17:37 +0800 Subject: [PATCH] * Optimize bug activate function. --- module/bug/config/form.php | 46 +++++++++++++++++---------- module/bug/control.php | 33 +++++++++++-------- module/bug/model.php | 25 +++++++-------- module/bug/zen.php | 65 -------------------------------------- 4 files changed, 59 insertions(+), 110 deletions(-) diff --git a/module/bug/config/form.php b/module/bug/config/form.php index b4595389b7..27af633f28 100644 --- a/module/bug/config/form.php +++ b/module/bug/config/form.php @@ -34,7 +34,7 @@ $config->bug->form->create['keywords'] = array('required' => false, 'type' => $config->bug->form->create['status'] = array('required' => false, 'type' => 'string', 'default' => 'active'); $config->bug->form->create['issueKey'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->create['openedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->create['openedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->create['openedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->edit = array(); $config->bug->form->edit['title'] = array('required' => true, 'type' => 'string', 'filter' => 'trim'); @@ -77,18 +77,18 @@ global $app; $config->bug->form->close = array(); $config->bug->form->close['status'] = array('required' => false, 'type' => 'string', 'default' => 'closed'); $config->bug->form->close['confirmed'] = array('required' => false, 'type' => 'int', 'default' => 1); -$config->bug->form->close['assignedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->close['assignedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->close['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->close['lastEditedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->close['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->close['closedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->close['closedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->close['closedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->close['comment'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->assignTo = array(); $config->bug->form->assignTo['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); -$config->bug->form->assignTo['assignedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->assignTo['assignedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->assignTo['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->assignTo['lastEditedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->assignTo['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->assignTo['mailto'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join'); $config->bug->form->resolve = array(); @@ -97,20 +97,33 @@ $config->bug->form->resolve['confirmed'] = array('required' => false, 'type $config->bug->form->resolve['resolvedBuild'] = array('required' => false, 'type' => 'int', 'default' => 0); $config->bug->form->resolve['resolution'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->resolve['resolvedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->resolve['resolvedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->resolve['resolvedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->resolve['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); -$config->bug->form->resolve['assignedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->resolve['assignedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->resolve['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->resolve['lastEditedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->resolve['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->resolve['duplicateBug'] = array('required' => false, 'type' => 'int', 'default' => 0); $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->activate = array(); -$config->bug->form->activate['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); -$config->bug->form->activate['openedBuild'] = array('required' => false, 'type' => 'array', 'default' => array()); -$config->bug->form->activate['comment'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->bug->form->activate['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->bug->form->activate['openedBuild'] = array('required' => false, 'type' => 'array', 'default' => array(), 'filter' => 'join'); +$config->bug->form->activate['assignedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); +$config->bug->form->activate['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); +$config->bug->form->activate['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); +$config->bug->form->activate['activatedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); +$config->bug->form->activate['resolution'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->bug->form->activate['status'] = array('required' => false, 'type' => 'string', 'default' => 'active'); +$config->bug->form->activate['resolvedBy'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->bug->form->activate['resolvedDate'] = array('required' => false, 'type' => 'date', 'default' => null); +$config->bug->form->activate['resolvedBuild'] = array('required' => false, 'type' => 'int', 'default' => 0); +$config->bug->form->activate['closedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); +$config->bug->form->activate['closedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); +$config->bug->form->activate['duplicateBug'] = array('required' => false, 'type' => 'int', 'default' => 0); +$config->bug->form->activate['toTask'] = array('required' => false, 'type' => 'int', 'default' => 0); +$config->bug->form->activate['toStory'] = array('required' => false, 'type' => 'int', 'default' => 0); $config->bug->form->batchActivate = array(); $config->bug->form->batchActivate['bugIdList'] = array('type' => 'array', 'required' => true); @@ -127,7 +140,7 @@ $config->bug->form->batchCreate['branch'] = array('required' => false, 'ty $config->bug->form->batchCreate['laneID'] = array('required' => false, 'type' => 'int', 'default' => 0); $config->bug->form->batchCreate['openedBuild'] = array('required' => true, 'type' => 'array', 'default' => '', 'filter' => 'join'); $config->bug->form->batchCreate['title'] = array('required' => true, 'type' => 'string', 'default' => '', 'base' => true); -$config->bug->form->batchCreate['deadline'] = array('required' => false, 'type' => 'date', 'default' => ''); +$config->bug->form->batchCreate['deadline'] = array('required' => false, 'type' => 'date', 'default' => null); $config->bug->form->batchCreate['steps'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->batchCreate['type'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->batchCreate['color'] = array('required' => false, 'type' => 'string', 'default' => ''); @@ -147,7 +160,7 @@ $config->bug->form->batchEdit['branch'] = array('required' => false, 'ty $config->bug->form->batchEdit['module'] = array('required' => false, 'type' => 'int', 'default' => 0); $config->bug->form->batchEdit['plan'] = array('required' => false, 'type' => 'int', 'default' => 0); $config->bug->form->batchEdit['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); -$config->bug->form->batchEdit['deadline'] = array('required' => false, 'type' => 'date', 'default' => ''); +$config->bug->form->batchEdit['deadline'] = array('required' => false, 'type' => 'date', 'default' => null); $config->bug->form->batchEdit['os'] = array('required' => false, 'type' => 'array', 'default' => '', 'filter' => 'join'); $config->bug->form->batchEdit['browser'] = array('required' => false, 'type' => 'array', 'default' => '', 'filter' => 'join'); $config->bug->form->batchEdit['keywords'] = array('required' => false, 'type' => 'string', 'default' => ''); @@ -157,13 +170,12 @@ $config->bug->form->batchEdit['duplicateBug'] = array('required' => false, 'ty $config->bug->form->batchEdit['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); $config->bug->form->batchEdit['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); - $config->bug->form->confirm = array(); $config->bug->form->confirm['pri'] = array('required' => false, 'type' => 'int', 'default' => 3); $config->bug->form->confirm['type'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->confirm['status'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->bug->form->confirm['mailto'] = array('required' => false, 'type' => 'array', 'default' => array(''), 'filter' => 'join'); $config->bug->form->confirm['assignedTo'] = array('required' => false, 'type' => 'string', 'default' => ''); -$config->bug->form->confirm['assignedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->confirm['assignedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); $config->bug->form->confirm['lastEditedBy'] = array('required' => false, 'type' => 'string', 'default' => $app->user->account); -$config->bug->form->confirm['lastEditedDate'] = array('required' => false, 'type' => 'string', 'default' => helper::now()); +$config->bug->form->confirm['lastEditedDate'] = array('required' => false, 'type' => 'date', 'default' => helper::now()); diff --git a/module/bug/control.php b/module/bug/control.php index d8f2d298a5..dc295553cd 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -436,7 +436,7 @@ class bug extends control if($oldBug->status != 'closed') $changes = $this->bug->resolve($bug, $output); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - $regionID = !empty($output['regionID']) ? $output['regionID'] : 0; + $regionID = zget($output, 'regionID', 0); return $this->send($this->bugZen->responseAfterOperate($bugID, $changes, '', $regionID)); } @@ -450,7 +450,7 @@ class bug extends control $this->view->title = $this->products[$oldBug->product] . $this->lang->colon . $this->lang->bug->resolve; $this->view->bug = $oldBug; $this->view->execution = $oldBug->execution ? $this->loadModel('execution')->getByID($oldBug->execution) : ''; - $this->view->users = $this->user->getPairs('noclosed'); + $this->view->users = $this->loadModel('user')->getPairs('noclosed'); $this->view->executions = $this->loadModel('product')->getExecutionPairsByProduct($oldBug->product, $oldBug->branch ? "0,{$oldBug->branch}" : 0, (string)$oldBug->project, 'stagefilter'); $this->view->builds = $this->loadModel('build')->getBuildPairs($oldBug->product, $oldBug->branch, 'withbranch,noreleased'); $this->view->actions = $this->loadModel('action')->getList('bug', $bugID); @@ -468,28 +468,33 @@ class bug extends control */ public function activate(int $bugID, string $kanbanInfo = '') { + $oldBug = $this->bug->getByID($bugID); if(!empty($_POST)) { $kanbanInfo = str_replace(array(',', ' '), array('&', ''), $kanbanInfo); parse_str($kanbanInfo, $kanbanParams); - $bugData = $this->bugZen->buildBugForActivate($bugID); - if(!$bugData) return $this->send(array('result' => 'fail', 'message' => $this->lang->bug->error->notExist)); + $bug = form::data($this->config->bug->form->activate)->setDefault('assignedTo', $oldBug->resolvedBy)->add('id', $bugID)->get(); + $bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->activate['id'], $this->post->uid); - $this->bug->activate($bugData, $kanbanParams); + $changes = $this->bug->activate($bug, $kanbanParams); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - if(isonlybody()) - { - $regionID = zget($kanbanParams, 'regionID', 0); - $bug = $this->bug->getBaseInfo($bugID); - $this->bugZen->responseInModal($bug->execution, '', $regionID); - } - - return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $this->createLink('bug', 'view', "bugID={$bugID}"), 'closeModal' => true); + $regionID = zget($kanbanParams, 'regionID', 0); + return $this->send($this->bugZen->responseAfterOperate($bugID, $changes, '', $regionID)); } - $this->bugZen->buildActivateForm($bugID); + $this->checkBugExecutionPriv($oldBug); + + $productID = $oldBug->product; + $this->qa->setMenu($this->products, $productID, $oldBug->branch); + + $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->activate; + $this->view->bug = $oldBug; + $this->view->users = $this->loadModel('user')->getPairs('noclosed', $oldBug->resolvedBy); + $this->view->builds = $this->loadModel('build')->getBuildPairs($productID, $oldBug->branch, 'noempty,noreleased', 0, 'execution', $oldBug->openedBuild); + $this->view->actions = $this->loadModel('action')->getList('bug', $bugID); + $this->display(); } /** diff --git a/module/bug/model.php b/module/bug/model.php index 43ffa1dbc5..abe80d64c4 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -894,12 +894,11 @@ class bugModel extends model * @param object $bug * @param array $kanbanParams * @access public - * @return bool + * @return array|false */ - public function activate(object $bug, array $kanbanParams = array()): bool + public function activate(object $bug, array $kanbanParams = array()): array|false { - $bugID = (int)$bug->id; - $oldBug = $this->getBaseInfo($bugID); + $oldBug = $this->getBaseInfo($bug->id); if(!$oldBug) { dao::$errors[] = $this->lang->bug->error->notExist; @@ -912,13 +911,13 @@ class bugModel extends model } $bug->activatedCount = $oldBug->activatedCount + 1; - $this->dao->update(TABLE_BUG)->data($bug, 'comment')->autoCheck()->checkFlow()->where('id')->eq($bugID)->exec(); + $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->checkFlow()->where('id')->eq($bug->id)->exec(); /* Update build. */ - $solveBuild = $this->dao->select('id, bugs')->from(TABLE_BUILD)->where("FIND_IN_SET('$bugID', bugs)")->limit(1)->fetch(); + $solveBuild = $this->dao->select('id, bugs')->from(TABLE_BUILD)->where("FIND_IN_SET('{$bug->id}', bugs)")->limit(1)->fetch(); if($solveBuild) { - $buildBugs = trim(str_replace(",$bugID,", ',', ",$solveBuild->bugs,"), ','); + $buildBugs = trim(str_replace(",{$bug->id},", ',', ",$solveBuild->bugs,"), ','); $this->dao->update(TABLE_BUILD)->set('bugs')->eq($buildBugs)->where('id')->eq($solveBuild->id)->exec(); } @@ -926,22 +925,20 @@ class bugModel extends model if($oldBug->execution) { $this->loadModel('kanban'); - if(!isset($kanbanParams['toColID'])) $this->kanban->updateLane($oldBug->execution, 'bug', $bugID); - if(isset($kanbanParams['toColID'])) $this->kanban->moveCard($bugID, $kanbanParams['fromColID'], $kanbanParams['toColID'], $kanbanParams['fromLaneID'], $kanbanParams['toLaneID']); + if(!isset($kanbanParams['toColID'])) $this->kanban->updateLane($oldBug->execution, 'bug', $bug->id); + if(isset($kanbanParams['toColID'])) $this->kanban->moveCard($bug->id, $kanbanParams['fromColID'], $kanbanParams['toColID'], $kanbanParams['fromLaneID'], $kanbanParams['toLaneID']); } $changes = common::createChanges($oldBug, $bug); - $files = $this->loadModel('file')->saveUpload('bug', $bugID); + $files = $this->loadModel('file')->saveUpload('bug', $bug->id); if($changes or $files) { $fileAction = !empty($files) ? $this->lang->addFiles . implode(',', $files) . "\n" : ''; - $actionID = $this->loadModel('action')->create('bug', $bugID, 'Activated', $fileAction . zget($bug, 'comment', '')); + $actionID = $this->loadModel('action')->create('bug', $bug->id, 'Activated', $fileAction . $this->post->comment); $this->action->logHistory($actionID, $changes); - - $this->executeHooks($bugID); } - return !dao::isError(); + return $changes; } /** diff --git a/module/bug/zen.php b/module/bug/zen.php index 49aaf51089..499f12cf7c 100644 --- a/module/bug/zen.php +++ b/module/bug/zen.php @@ -1510,71 +1510,6 @@ class bugZen extends bug return $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->resolve['id'], $this->post->uid); } - /** - * 准备激活数据。 - * Prepare Activate Data. - * - * @param int $bugID - * @access protected - * @return object|false - */ - protected function buildBugForActivate(int $bugID): object|false - { - $bugInfo = $this->bug->getBaseInfo($bugID); - if(!$bugInfo) return false; - - $now = helper::now(); - $formConfig = $this->config->bug->form->activate; - - $bug = form::data($formConfig) - ->setDefault('assignedTo', $bugInfo->resolvedBy) - ->add('id', $bugID) - ->add('assignedDate', $now) - ->add('lastEditedBy', $this->app->user->account) - ->add('lastEditedDate', $now) - ->add('activatedDate', $now) - ->add('resolution', '') - ->add('status', 'active') - ->add('resolvedDate', null) - ->add('resolvedBy', '') - ->add('resolvedBuild', '') - ->add('closedBy', '') - ->add('closedDate', null) - ->add('duplicateBug', 0) - ->add('toTask', 0) - ->add('toStory', 0) - ->join('openedBuild', ',') - ->get(); - - $editorFields = array_keys(array_filter(array_map(function($config){return (!empty($config['control']) && $config['control'] == 'editor');}, $formConfig))); - return $this->loadModel('file')->processImgURL($bug, $editorFields, $this->post->uid); - } - - /** - * 构建bug激活表单。 - * Build bug activate form. - * - * @param int $bugID - * @access protected - * @return void - */ - protected function buildActivateForm(int $bugID): void - { - $bug = $this->bug->getByID($bugID); - $this->checkBugExecutionPriv($bug); - - $productID = $bug->product; - $this->qa->setMenu($this->products, $productID, $bug->branch); - - $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->activate; - $this->view->bug = $bug; - $this->view->users = $this->user->getPairs('noclosed', $bug->resolvedBy); - $this->view->builds = $this->loadModel('build')->getBuildPairs($productID, $bug->branch, 'noempty,noreleased', 0, 'execution', $bug->openedBuild); - $this->view->actions = $this->action->getList('bug', $bugID); - - $this->display(); - } - /** * 为批量创建bug构造数据。 * Build bugs for the batch creation.