* Adjust the code.
This commit is contained in:
+53
-77
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The control file of gitlab module of ZenTaoPMS.
|
||||
*
|
||||
@@ -27,9 +26,6 @@ class gitlab extends control
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$this->view->position[] = $this->lang->gitlab->common;
|
||||
$this->view->position[] = $this->lang->gitlab->browse;
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->browse;
|
||||
$this->view->gitlabList = $this->gitlab->getList($orderBy, $pager);
|
||||
$this->view->orderBy = $orderBy;
|
||||
@@ -39,7 +35,7 @@ class gitlab extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a gitlab.
|
||||
* create a gitlab.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
@@ -57,9 +53,6 @@ class gitlab extends control
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->create;
|
||||
|
||||
$this->view->position[] = html::a(inlink('browse'), $this->lang->gitlab->common);
|
||||
$this->view->position[] = $this->lang->gitlab->create;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -81,9 +74,6 @@ class gitlab extends control
|
||||
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
|
||||
}
|
||||
|
||||
$this->view->position[] = html::a(inlink('browse'), $this->lang->gitlab->common);
|
||||
$this->view->position[] = $this->lang->gitlab->edit;
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->edit;
|
||||
$this->view->gitlab = $gitlab;
|
||||
|
||||
@@ -93,6 +83,7 @@ class gitlab extends control
|
||||
/**
|
||||
* Bind gitlab user to zentao users.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -102,7 +93,7 @@ class gitlab extends control
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$users = $this->post->zentaoUsers;
|
||||
$users = $this->post->zentaoUsers;
|
||||
$accountList = array();
|
||||
$repeatUsers = array();
|
||||
foreach($users as $openID => $user)
|
||||
@@ -118,7 +109,7 @@ class gitlab extends control
|
||||
$user->providerID = $gitlabID;
|
||||
$user->providerType = 'gitlab';
|
||||
|
||||
/* Delete binded users and save new relationship.*/
|
||||
/* Delete binded users and save new relationship. */
|
||||
$this->dao->delete()->from(TABLE_OAUTH)->where('providerType')->eq($user->providerType)->andWhere('providerID')->eq($user->providerID)->exec();
|
||||
foreach($users as $openID => $account)
|
||||
{
|
||||
@@ -127,12 +118,12 @@ class gitlab extends control
|
||||
$user->openID = $openID;
|
||||
|
||||
$this->dao->delete()
|
||||
->from(TABLE_OAUTH)
|
||||
->where('openID')->eq($user->openID)
|
||||
->andWhere('providerType')->eq($user->providerType)
|
||||
->andWhere('providerID')->eq($user->providerID)
|
||||
->andWhere('account')->eq($user->account)
|
||||
->exec();
|
||||
->from(TABLE_OAUTH)
|
||||
->where('openID')->eq($user->openID)
|
||||
->andWhere('providerType')->eq($user->providerType)
|
||||
->andWhere('providerID')->eq($user->providerID)
|
||||
->andWhere('account')->eq($user->account)
|
||||
->exec();
|
||||
|
||||
$this->dao->insert(TABLE_OAUTH)->data($user)->exec();
|
||||
}
|
||||
@@ -151,8 +142,8 @@ class gitlab extends control
|
||||
|
||||
/**
|
||||
* Bind product and gitlab projects.
|
||||
*
|
||||
* @param int $gitlabID
|
||||
*
|
||||
* @param int $gitlabID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -161,7 +152,7 @@ class gitlab extends control
|
||||
$this->view->projectPairs = $this->gitlab->getProjectPairs($gitlabID);
|
||||
$this->view->title = $this->lang->gitlab->bindProduct;
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a gitlab.
|
||||
@@ -180,7 +171,7 @@ class gitlab extends control
|
||||
|
||||
/**
|
||||
* Check post token has admin permissions.
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -197,7 +188,7 @@ class gitlab extends control
|
||||
|
||||
/**
|
||||
* Webhook api.
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -214,7 +205,7 @@ class gitlab extends control
|
||||
|
||||
$logFile = $this->app->getLogRoot() . 'webhook.'. date('Ymd') . '.log.php';
|
||||
if(!file_exists($logFile)) file_put_contents($logFile, '<?php die(); ?' . '>');
|
||||
|
||||
|
||||
$fh = @fopen($logFile, 'a');
|
||||
if($fh)
|
||||
{
|
||||
@@ -238,52 +229,40 @@ class gitlab extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function test($id = 11)
|
||||
{
|
||||
$gitlabID = 1; $projectID = 7;
|
||||
$task = $this->loadModel('task')->getByID($id);
|
||||
$relations = $this->gitlab->getRelationByObject('task', $task->id);
|
||||
|
||||
a($relations);exit;
|
||||
$issue = $this->gitlab->taskToIssue($gitlabID, $projectID, $task);
|
||||
$issue = $this->gitlab->apiCreateIssue($gitlabID, $projectID, $issue);
|
||||
$this->gitlab->saveIssueRelation('task', $task, $gitlabID, $issue);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import gitlab issue to zentaopms.
|
||||
*
|
||||
* @param int $repoID
|
||||
* Import gitlab issue to zentaopms.
|
||||
*
|
||||
* @param int $repoID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function importIssue($repoID)
|
||||
{
|
||||
$repo = $this->loadModel('repo')->getRepoByID($repoID);
|
||||
$productIDList = explode(',', $repo->product);
|
||||
$gitlabID = $repo->gitlab;
|
||||
$projectID = $repo->project;
|
||||
|
||||
$repo = $this->loadModel('repo')->getRepoByID($repoID);
|
||||
$productIDList = explode(',', $repo->product);
|
||||
$gitlabID = $repo->gitlab;
|
||||
$projectID = $repo->project;
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$executionList = $this->post->executionList;
|
||||
$objectTypeList = $this->post->objectTypeList;
|
||||
$productList = $this->post->productList;
|
||||
|
||||
$failedIssues = array();
|
||||
$failedIssues = array();
|
||||
foreach($executionList as $issueID => $executionID)
|
||||
{
|
||||
if($executionID)
|
||||
if($executionID)
|
||||
{
|
||||
$objectType = $objectTypeList[$issueID];
|
||||
$issue = $this->gitlab->apiGetSingleIssue($gitlabID, $projectID, $issueID);
|
||||
$issue->objectType = $objectType;
|
||||
$issue->objectID = 0; // meet the required parameters for issueToZentaoObject.
|
||||
if(isset($issue->assignee)) $issue->assignee_id = $issue->assignee->id;
|
||||
$issue->updated_by_id = $issue->author->id; // here can be replaced by current zentao user.
|
||||
|
||||
$object = $this->gitlab->issueToZentaoObject($issue, $gitlabID);
|
||||
$issue = $this->gitlab->apiGetSingleIssue($gitlabID, $projectID, $issueID);
|
||||
$issue->objectType = $objectType;
|
||||
$issue->objectID = 0; // Meet the required parameters for issueToZentaoObject.
|
||||
if(isset($issue->assignee)) $issue->assignee_id = $issue->assignee->id;
|
||||
$issue->updated_by_id = $issue->author->id; // Here can be replaced by current zentao user.
|
||||
|
||||
$object = $this->gitlab->issueToZentaoObject($issue, $gitlabID);
|
||||
$object->product = $productList[$issueID];
|
||||
$object->execution = $executionID;
|
||||
$clonedObject = clone $object;
|
||||
@@ -293,7 +272,7 @@ class gitlab extends control
|
||||
if($objectType == 'story') $objectID = $this->loadModel('story')->createStoryFromGitlabIssue($clonedObject, $executionID);
|
||||
|
||||
if($objectID)
|
||||
{
|
||||
{
|
||||
$object->id = $objectID;
|
||||
$this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object);
|
||||
}
|
||||
@@ -313,19 +292,19 @@ class gitlab extends control
|
||||
}
|
||||
|
||||
$savedIssueIDList = $this->dao->select('BID as issueID')->from(TABLE_RELATION)
|
||||
->where('relation')->eq('gitlab')
|
||||
->andWhere('BType')->eq('issue')
|
||||
->andWhere('BVersion')->eq($projectID)
|
||||
->andWhere('extra')->eq($gitlabID)
|
||||
->fetchAll('issueID');
|
||||
->where('relation')->eq('gitlab')
|
||||
->andWhere('BType')->eq('issue')
|
||||
->andWhere('BVersion')->eq($projectID)
|
||||
->andWhere('extra')->eq($gitlabID)
|
||||
->fetchAll('issueID');
|
||||
|
||||
/* 'not[iids]' option in gitlab API has a issue when iids is too long. */
|
||||
$gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, '&state=opened');
|
||||
/* 'not[iids]' option in gitlab API has a issue when iids is too long. */
|
||||
$gitlabIssues = $this->gitlab->apiGetIssues($gitlabID, $projectID, '&state=opened');
|
||||
foreach($gitlabIssues as $index => $issue)
|
||||
{
|
||||
foreach($savedIssueIDList as $savedIssueID)
|
||||
{
|
||||
if($issue->iid == $savedIssueID->issueID)
|
||||
if($issue->iid == $savedIssueID->issueID)
|
||||
{
|
||||
unset($gitlabIssues[$index]);
|
||||
break;
|
||||
@@ -333,41 +312,38 @@ class gitlab extends control
|
||||
}
|
||||
}
|
||||
|
||||
$products = array();
|
||||
$products[] = '';
|
||||
foreach($productIDList as $productID)
|
||||
{
|
||||
$products[$productID] = $this->loadModel("product")->getByID($productID)->name;
|
||||
}
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->importIssue;
|
||||
$products = array('' => '');
|
||||
$this->loadModel("product");
|
||||
foreach($productIDList as $productID) $products[$productID] = $this->product->getByID($productID)->name;
|
||||
|
||||
$this->view->title = $this->lang->gitlab->common . $this->lang->colon . $this->lang->gitlab->importIssue;
|
||||
$this->view->importable = empty($gitlabIssues) ? false : true;
|
||||
$this->view->products = $products;
|
||||
$this->view->gitlabID = $gitlabID;
|
||||
$this->view->gitlabProjectID = $projectID;
|
||||
$this->view->objectTypes = $this->config->gitlab->objectTypes;
|
||||
|
||||
$this->view->gitlabIssues = $gitlabIssues;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax get executions by productID.
|
||||
*
|
||||
* @param int $productID
|
||||
* AJAX: Get executions by productID.
|
||||
*
|
||||
* @param int $productID
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function ajaxGetExecutionsByProduct($productID)
|
||||
{
|
||||
if(!$productID) $this->send(array('message' => array()));
|
||||
|
||||
|
||||
$executions = $this->loadModel('product')->getAllExecutionPairsByProduct($productID);
|
||||
$options = "<option value=''></option>";
|
||||
$options = "<option value=''></option>";
|
||||
foreach($executions as $index =>$execution)
|
||||
{
|
||||
$options .= "<option value='{$index}' data-name='{$execution}'>{$execution}</option>";
|
||||
}
|
||||
die($options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+265
-262
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user