diff --git a/module/bug/control.php b/module/bug/control.php index 13714a464b..9b92147752 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -559,7 +559,9 @@ class bug extends control /* Set gitlabProjects. */ $allGitlabs = $this->loadModel('gitlab')->getPairs(); - $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + if(!empty($executionID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByExecution($executionID); + elseif(!empty($productID)) $gitlabProjects = $this->loadModel('gitlab')->getProjectsByProduct($productID); + foreach($allGitlabs as $id => $name) if($id and !isset($gitlabProjects[$id])) unset($allGitlabs[$id]); $this->view->gitlabList = $allGitlabs; $this->view->gitlabProjects = $gitlabProjects; @@ -1551,7 +1553,7 @@ class bug extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('bug', $bugID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID); + if(!empty($relation)) $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'bug', $bugID, $relation->issueID); $this->bug->delete(TABLE_BUG, $bugID); if($bug->toTask != 0) diff --git a/module/bug/model.php b/module/bug/model.php index aef3b6b84a..9f44bebf2a 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -646,6 +646,10 @@ class bugModel extends model if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID); $this->file->updateObjectID($this->post->uid, $bugID, 'bug'); + + $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); + return common::createChanges($oldBug, $bug); } } @@ -1178,6 +1182,9 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); + $relation = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); + if($relation) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $relation->gitlabID, $relation->projectID); + $openedBuilds = $this->post->openedBuild; if($openedBuilds) { @@ -1185,6 +1192,7 @@ class bugModel extends model foreach($openedBuilds as $openedBuild) { $build = $this->build->getByID($openedBuild); + if(empty($build)) continue; $build->bugs = trim(str_replace(",$bugID,", ',', ",$build->bugs,"), ','); $this->dao->update(TABLE_BUILD)->set('bugs')->eq($build->bugs)->where('id')->eq((int)$openedBuild)->exec(); } @@ -1220,7 +1228,7 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $objectID = $this->loadModel('gitlab')->getGitlabIDprojectID('bug',$bugID); - if($objectID) $this->loadModel('bug')->pushToissue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); + if($objectID) $this->loadModel('gitlab')->pushToIssue('bug', $bugID, $objectID->gitlabID, $objectID->projectID); return common::createChanges($oldBug, $bug); } diff --git a/module/gitlab/model.php b/module/gitlab/model.php index af1f28317d..d0891c6366 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -478,6 +478,16 @@ class gitlabModel extends model ->fetchGroup('AID'); } + public function getProjectsByProduct($productID) + { + return $this->dao->select('AID, BID as gitlabProject')->from(TABLE_RELATION) + ->where('relation')->eq('interrated') + ->andWhere('AType')->eq('gitlab') + ->andWhere('BType')->eq('gitlabProject') + ->andWhere('product')->eq($productID) + ->fetchGroup('AID'); + } + /** * Get gitlabID and projectID. * @@ -696,20 +706,22 @@ class gitlabModel extends model } /** - * Delete ans issue. + * Delete an issue. * * @param int $gitlabID * @param int $projectID * @param string $objectType * @param int $objectID + * @param int $issueID * @access public * @return void */ - public function deleteIssue($gitlabID, $projectID, $objectType, $objectID) + public function deleteIssue($gitlabID, $projectID, $objectType, $objectID, $issueID) { $object = $this->loadModel($objectType)->getByID($objectID); $relationID = $this->getRelationID($objectType, $objectID); - if(!empty($relationID)) $this->dao->delete(TABLE_RELATION, $relationID); + if(!empty($relationID)) $this->dao->delete()->from(TABLE_RELATION)->where('id')->eq($relationID)->exec(); + $this->apiDeleteIssue($gitlabID, $projectID, $issueID); } /** @@ -874,6 +886,7 @@ class gitlabModel extends model /* issue->state is null when creating it, we should put status_event when updating it. */ if(isset($issue->state) and $issue->state == 'closed') $issue->state_event='close'; + if(isset($issue->state) and $issue->state == 'opened') $issue->state_event='reopen'; return $issue; } diff --git a/module/story/control.php b/module/story/control.php index 1a43a84db7..e0bad0cb9e 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -989,7 +989,7 @@ class story extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('story', $storyID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'story', $storyID, $relation->issueID); $this->story->delete(TABLE_STORY, $storyID); if($story->parent > 0) diff --git a/module/task/control.php b/module/task/control.php index 7cbefe3cbd..869db13dc4 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -1282,7 +1282,7 @@ class task extends control { /* Delete related issue in gitlab. */ $relation = $this->loadModel('gitlab')->getGitlabIssueFromRelation('task', $taskID); - $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID); + $this->loadModel('gitlab')->deleteIssue($relation->gitlabID, $relation->projectID, 'task', $taskID, $relation->issueID); $this->task->delete(TABLE_TASK, $taskID); if($task->parent > 0)