diff --git a/db/zentao.sql b/db/zentao.sql index df7b01a6e7..adcd1b45d3 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -471,8 +471,8 @@ CREATE TABLE IF NOT EXISTS `zt_history` ( PRIMARY KEY (`id`), KEY `action` (`action`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_pipeline`; -CREATE TABLE IF NOT EXISTS `zt_pipeline` ( +-- DROP TABLE IF EXISTS `zt_pipline`; +CREATE TABLE IF NOT EXISTS `zt_pipline` ( `id` smallint(8) unsigned NOT NULL AUTO_INCREMENT, `type` char(30) NOT NULL, `name` varchar(50) NOT NULL, diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 203de5bf1d..c81c96a0f1 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -75,7 +75,10 @@ class gitlab extends control */ public function bind() { - var_dump($this->gitlab->getPermissionsByToken('http://127.0.0.1:8090/','rpz2PZKriNE6TD34QtDA')); + $gitlabUserData = $this->gitlab->getUserBindList('http://127.0.0.1:8090/','xV8EKDyCY7Sb5j1-FxyZ'); + + var_dump($gitlabUserData);die; + die; $this->display(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 6e090fb271..530cc97a13 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -85,31 +85,50 @@ class gitlabModel extends model $host = rtrim($host, '/') . "/api/v4/user?private_token=$token"; $response = json_decode(commonModel::http($host)); - if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); + if(!is_object($response)) return array('result' => 'fail', 'message' => array('url' => array($this->lang->gitlab->hostError))); if(isset($response->is_admin) and $response->is_admin == true) return array('result' => 'success'); return array('result' => 'fail', 'message' => array('token' => array($this->lang->gitlab->tokenError))); } - /** - * Get projects of one gitlab. - * - * @param int $id - * @access public - * @return void - */ - public function getProjectsByID($id) - { - $gitlab = $this->getByID($id); - $host = rtrim($gitlab->url, '/'); - $host .= '/api/v4/projects'; - $allResults = array(); - for($page = 1; true; $page ++) - { - $results = json_decode(file_get_contents($host . "?private_token={$gitlab->token}&simple=true&membership=true&page={$page}&per_page=100")); - if(empty($results) or $page > 10) break; - $allResults = $allResults + $results; - } - return $allResults; + /** + * Get gitlab user list. + * + * @param string $host + * @param string $token + * @access public + * @return array + */ + public function getUserBindList($host, $token) + { + $host = rtrim($host, '/') .'/api/v4/users?private_token='.$token ; + $response = json_decode(commonModel::http($host),true); + + if (!$response) return array(); + $localUsersList = $this->dao->select('id,account,email,realname')->from(TABLE_USER)->fetchAll(); + + $responseAllId = array(); + $matchUserIds = array(); + $responseMatchIds = array(); + foreach ($response as $i => $gitlabId) { + + $responseAllId[] = $gitlabId['id']; + + foreach ($localUsersList as $local) { + + if ( $gitlabId['email'] == $local->email && $gitlabId['username'] == $local->realname && $gitlabId['name'] == $local->account) + { + $matchUserIds[$i][$local->realname] = $local->id .'-'. $gitlabId['id']; + $responseMatchIds[] = $gitlabId['id']; + } + } + } + $notMatchUserIds = array_diff($responseAllId,$responseMatchIds); + + foreach ($notMatchUserIds as $k => $v) + { + $notMatchUserId[$k]['Not matched'] = 0 .'-'. $v; + } + return array_merge($notMatchUserId,$matchUserIds); } } diff --git a/module/gitlab/view/bind.html.php b/module/gitlab/view/bind.html.php deleted file mode 100644 index d9af48a455..0000000000 --- a/module/gitlab/view/bind.html.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @package gitlab - * @version $Id$ - * @link http://www.zentao.net - */ -?> - -