From 84f5c25aa9e47e7d1638012762b6808bb52cd715 Mon Sep 17 00:00:00 2001 From: dingguodong Date: Mon, 23 Aug 2021 16:53:10 +0800 Subject: [PATCH] * Refactor the function for editing MR. --- module/mr/config.php | 2 -- module/mr/control.php | 5 ++--- module/mr/model.php | 22 ++++++++++++---------- module/mr/view/edit.html.php | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/module/mr/config.php b/module/mr/config.php index e93a28f438..952787e0e9 100644 --- a/module/mr/config.php +++ b/module/mr/config.php @@ -4,5 +4,3 @@ $config->MR->create = new stdclass(); $config->MR->create->requiredFields = 'gitlabID,sourceProject,sourceBranch,targetProject,targetBranch,title'; $config->MR->create->skippedFields = 'projectID'; -$config->MR->edit = new stdclass(); -$config->MR->edit->requiredFields = 'title'; diff --git a/module/mr/control.php b/module/mr/control.php index 4c5f78f2e2..3b42488dec 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -54,9 +54,8 @@ class mr extends control { if($_POST) { - $this->mr->edit($MRID); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + $result = $this->mr->edit($MRID); + return $result; } $MR = $this->mr->getByID($MRID); diff --git a/module/mr/model.php b/module/mr/model.php index 097fd0d06b..4e6462db67 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -179,12 +179,10 @@ class mrModel extends model */ public function edit($MRID) { - /* Get MR in zentao database and do not append extra attributes in GitLab. */ - $MR = $this->getByID($MRID, $process = false); - $MR->title = $this->post->title; - $MR->description = $this->post->description; - $MR->assignee = $this->post->assignee; - $MR->reviewer = $this->post->reviewer; + $MR = fixer::input('post') + ->setDefault('editedBy', $this->app->user->account) + ->setDefault('editedDate', helper::now()) + ->get(); /* Update MR in GitLab. */ $newMR = new stdclass; @@ -192,15 +190,19 @@ class mrModel extends model $newMR->description = $MR->description; $newMR->assignee = $MR->assignee; $newMR->reviewer = $MR->reviewer; - $newMR->targetBranch = $this->post->targetBranch; - $this->apiUpdateMR($MR->gitlabID, $MR->projectID, $MR->mrID, $newMR); + $newMR->targetBranch = $MR->targetBranch; + + $oldMR = $this->getByID($MRID); + $this->apiUpdateMR($oldMR->gitlabID, $oldMR->sourceProject, $oldMR->mriid, $newMR); /* Update MR in Zentao database. */ $this->dao->update(TABLE_MR)->data($MR) - ->batchCheck($this->config->MR->edit->requiredFields, 'notempty') + ->where('id')->eq($MRID) ->autoCheck() ->exec(); - if(dao::isError()) return false; + + if(dao::isError()) return array('result' => 'fail', 'message' => dao::getError()); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); } /** diff --git a/module/mr/view/edit.html.php b/module/mr/view/edit.html.php index 63a18d337a..0df56316f7 100644 --- a/module/mr/view/edit.html.php +++ b/module/mr/view/edit.html.php @@ -43,7 +43,7 @@ mr->name;?> - name, "class='form-control'"); ?> + title, "class='form-control'"); ?> mr->description; ?>