diff --git a/module/mr/control.php b/module/mr/control.php index 3b42488dec..b4a9fcbb3b 100644 --- a/module/mr/control.php +++ b/module/mr/control.php @@ -54,7 +54,7 @@ class mr extends control { if($_POST) { - $result = $this->mr->edit($MRID); + $result = $this->mr->update($MRID); return $result; } @@ -67,9 +67,9 @@ class mr extends control } /** - * Delete a mr. + * Delete a MR. * - * @param int $MR + * @param int $id * @access public * @return void */ @@ -77,11 +77,12 @@ class mr extends control { if($confim != 'yes') die(js::confirm($this->lang->gitlab->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); - $MRList = $this->mr->getByID($id); + $MR = $this->mr->getByID($id); - $this->mr->apiDeleteMR($MRList->gitlabID, $MRList->projectID, $MRList->mrID); - $this->mr->deleteMR($id); - die(js::reload('parent')); + $this->dao->delete()->from(TABLE_MR)->where('id')->eq($id)->exec(); + $this->mr->apiDeleteMR($MR->gitlabID, $MR->sourceProject, $MR->mriid); + + die(js::locate(inlink('browse'), 'parent')); } /** @@ -93,7 +94,7 @@ class mr extends control public function view($id) { $MR = $this->mr->getByID($id); - if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); + if(isset($MR->gitlabID)) $rawMR = $this->mr->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); $this->view->title = $this->lang->mr->view; $this->view->MR = $MR; diff --git a/module/mr/model.php b/module/mr/model.php index 4e6462db67..d7b1c3ba73 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -53,6 +53,8 @@ class mrModel extends model ->page($pager) ->fetchAll('id'); + foreach($MRList as $MR) $this->apiSyncMR($MR); + return $MRList; } @@ -67,7 +69,7 @@ class mrModel extends model { if(!isset($MR->gitlabID)) return $MR; - $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->projectID, $MR->mrID); + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); $MR->name = $rawMR->title; $MR->sourceProject = $rawMR->source_project_id; @@ -205,6 +207,29 @@ class mrModel extends model return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => helper::createLink('mr', 'browse')); } + /** + * sync MR from GitLab API to Zentao database. + * + * @param object $MR + * @access public + * @return void + */ + public function apiSyncMR($MR) + { + $rawMR = $this->apiGetSingleMR($MR->gitlabID, $MR->targetProject, $MR->mriid); + if(isset($rawMR->iid)) + { + $newMR = new stdclass; + $newMR->status = $rawMR->state; + $newMR->mergeStatus = $rawMR->merge_status; + + /* Update MR in Zentao database. */ + $this->dao->update(TABLE_MR)->data($newMR) + ->where('id')->eq($MR->id) + ->exec(); + } + } + /** * Create MR by API. * @@ -241,7 +266,7 @@ class mrModel extends model * * @docs https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr * @param int $gitlabID - * @param int $projectID + * @param int $projectID targetProject * @param int $MRID * @access public * @return object