* Refactor the function for editing MR.

This commit is contained in:
dingguodong
2021-08-23 16:53:10 +08:00
parent 304ed9c54e
commit 84f5c25aa9
4 changed files with 15 additions and 16 deletions
-2
View File
@@ -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';
+2 -3
View File
@@ -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);
+12 -10
View File
@@ -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'));
}
/**
+1 -1
View File
@@ -43,7 +43,7 @@
</tr>
<tr>
<th><?php echo $lang->mr->name;?></th>
<td class='required'><?php echo html::input('title', $MR->name, "class='form-control'"); ?></td>
<td class='required'><?php echo html::input('title', $MR->title, "class='form-control'"); ?></td>
</tr>
<tr>
<th><?php echo $lang->mr->description; ?></th>