diff --git a/config/zentaopms.php b/config/zentaopms.php index a0b8dc0ede..6a8fe3ca3a 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -179,7 +179,7 @@ define('TABLE_LOG', '`' . $config->db->prefix . 'log`'); define('TABLE_SCORE', '`' . $config->db->prefix . 'score`'); define('TABLE_NOTIFY', '`' . $config->db->prefix . 'notify`'); define('TABLE_OAUTH', '`' . $config->db->prefix . 'oauth`'); -define('TABLE_PIPLINE', '`' . $config->db->prefix . 'pipline`'); +define('TABLE_PIPELINE', '`' . $config->db->prefix . 'pipeline`'); define('TABLE_JOB', '`' . $config->db->prefix . 'job`'); define('TABLE_COMPILE', '`' . $config->db->prefix . 'compile`'); diff --git a/db/zentao.sql b/db/zentao.sql index fa9301cc1e..adcd1b45d3 100644 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -471,9 +471,10 @@ CREATE TABLE IF NOT EXISTS `zt_history` ( PRIMARY KEY (`id`), KEY `action` (`action`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; --- DROP TABLE IF EXISTS `zt_jenkins`; -CREATE TABLE IF NOT EXISTS `zt_jenkins` ( +-- 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, `url` varchar(255) DEFAULT NULL, `account` varchar(30) DEFAULT NULL, diff --git a/module/ci/control.php b/module/ci/control.php index b22366f61e..654a48a2a1 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -104,7 +104,7 @@ class ci extends control { $compile = $this->dao->select('t1.*, t2.jkJob,t2.product,t2.frame,t3.name as jenkinsName,t3.url,t3.account,t3.token,t3.password')->from(TABLE_COMPILE)->alias('t1') ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id') - ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id') + ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t2.jkHost=t3.id') ->where('t1.id')->eq($compileID) ->fetch(); diff --git a/module/ci/model.php b/module/ci/model.php index 46ff711cc9..3a0093d85e 100644 --- a/module/ci/model.php +++ b/module/ci/model.php @@ -31,7 +31,7 @@ class ciModel extends model $compiles = $this->dao->select('t1.*, t2.jkJob, t3.name as jenkinsName,t3.url,t3.account,t3.token,t3.password') ->from(TABLE_COMPILE)->alias('t1') ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id') - ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t2.jkHost=t3.id') + ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t2.jkHost=t3.id') ->where('t1.status')->ne('success') ->andWhere('t1.status')->ne('failure') ->andWhere('t1.status')->ne('create_fail') diff --git a/module/compile/model.php b/module/compile/model.php index 7f82a344ce..f9f1646335 100644 --- a/module/compile/model.php +++ b/module/compile/model.php @@ -37,7 +37,7 @@ class compileModel extends model return $this->dao->select('t1.id, t1.name, t1.job, t1.status, t1.createdDate,t1.testtask, t2.jkJob,t2.triggerType,t2.comment,t2.atDay,t2.atTime, t3.name as repoName, t4.name as jenkinsName')->from(TABLE_COMPILE)->alias('t1') ->leftJoin(TABLE_JOB)->alias('t2')->on('t1.job=t2.id') ->leftJoin(TABLE_REPO)->alias('t3')->on('t2.repo=t3.id') - ->leftJoin(TABLE_JENKINS)->alias('t4')->on('t2.jkHost=t4.id') + ->leftJoin(TABLE_PIPELINE)->alias('t4')->on('t2.jkHost=t4.id') ->where('t1.deleted')->eq('0') ->andWhere('t1.job')->ne('0') ->beginIF(!empty($jobID))->andWhere('t1.job')->eq($jobID)->fi() @@ -123,7 +123,7 @@ class compileModel extends model { $job = $this->dao->select('t1.id,t1.name,t1.repo,t1.jkJob,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') ->from(TABLE_JOB)->alias('t1') - ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') + ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.jkHost=t2.id') ->where('t1.id')->eq($compile->job) ->fetch(); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index e1a9f6873b..0e123d100c 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -21,10 +21,7 @@ class gitlabModel extends model */ public function getByID($id) { - $gitlab = $this->dao->select('*')->from(TABLE_PIPLINE)->where('id')->eq($id)->fetch(); - $gitlab->password = base64_decode($gitlab->password); - - return $gitlab; + return $this->loadModel('pipeline')->getByID($id); } /** @@ -37,12 +34,7 @@ class gitlabModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*')->from(TABLE_PIPLINE) - ->where('deleted')->eq('0') - ->andwhere('type')->eq('1') - ->orderBy($orderBy) - ->page($pager) - ->fetchAll('id'); + return $this->loadModel('pipeline')->getList('gitlab', $orderBy, $pager); } /** @@ -52,11 +44,7 @@ class gitlabModel extends model */ public function getPairs() { - $gitlab = $this->dao->select('id,name')->from(TABLE_PIPLINE) - ->where('deleted')->eq('0') - ->orderBy('id')->fetchPairs('id', 'name'); - $gitlab = array('' => '') + $gitlab; - return $gitlab; + return $this->loadModel('pipeline')->getPairs('gitlab'); } /** @@ -67,20 +55,7 @@ class gitlabModel extends model */ public function create() { - $gitlab = fixer::input('post') - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->add('type', 1) - ->skipSpecial('url,token') - ->get(); - - - $this->dao->insert(TABLE_PIPLINE)->data($gitlab) - ->batchCheck($this->config->gitlab->create->requiredFields, 'notempty') - ->autoCheck() - ->exec(); - if(dao::isError()) return false; - return $this->dao->lastInsertId(); + return $this->loadModel('pipeline')->create('gitlab'); } /** @@ -92,19 +67,7 @@ class gitlabModel extends model */ public function update($id) { - $gitlab = fixer::input('post') - ->add('editedBy', $this->app->user->account) - ->add('editedDate', helper::now()) - ->skipSpecial('url,token') - ->get(); - - $this->dao->update(TABLE_PIPLINE)->data($gitlab) - ->batchCheck($this->config->gitlab->edit->requiredFields, 'notempty') - ->batchCheck("url", 'URL') - ->autoCheck() - ->where('id')->eq($id) - ->exec(); - return !dao::isError(); + return $this->loadModel('pipeline')->update($id); } /** @@ -118,11 +81,9 @@ class gitlabModel extends model public function getPermissionsByToken($host, $token) { $host = rtrim($host, '/'); - $host .= '/api/v4/user/activities'; - + $host .= '/api/v4/activities'; $results = json_decode(file_get_contents($host . "?private_token=$token")); return $results; } - } diff --git a/module/jenkins/control.php b/module/jenkins/control.php index 70c030d2a4..1a77a02d27 100644 --- a/module/jenkins/control.php +++ b/module/jenkins/control.php @@ -111,7 +111,7 @@ class jenkins extends control { if($confim != 'yes') die(js::confirm($this->lang->jenkins->confirmDelete, inlink('delete', "id=$id&confirm=yes"))); - $this->jenkins->delete(TABLE_JENKINS, $id); + $this->jenkins->delete(TABLE_PIPELINE, $id); die(js::reload('parent')); } diff --git a/module/jenkins/model.php b/module/jenkins/model.php index 2d12469a3f..48eaa13a1b 100644 --- a/module/jenkins/model.php +++ b/module/jenkins/model.php @@ -21,10 +21,7 @@ class jenkinsModel extends model */ public function getByID($id) { - $jenkins = $this->dao->select('*')->from(TABLE_JENKINS)->where('id')->eq($id)->fetch(); - $jenkins->password = base64_decode($jenkins->password); - - return $jenkins; + return $this->loadModel('pipeline')->getByID($id); } /** @@ -37,11 +34,7 @@ class jenkinsModel extends model */ public function getList($orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*')->from(TABLE_JENKINS) - ->where('deleted')->eq('0') - ->orderBy($orderBy) - ->page($pager) - ->fetchAll('id'); + return $this->loadModel('pipeline')->getList('jenkins', $orderBy, $pager); } /** @@ -51,11 +44,7 @@ class jenkinsModel extends model */ public function getPairs() { - $jenkins = $this->dao->select('id,name')->from(TABLE_JENKINS) - ->where('deleted')->eq('0') - ->orderBy('id')->fetchPairs('id', 'name'); - $jenkins = array('' => '') + $jenkins; - return $jenkins; + return $this->loadModel('pipeline')->getPairs('jenkins'); } /** @@ -94,21 +83,7 @@ class jenkinsModel extends model */ public function create() { - $jenkins = fixer::input('post') - ->add('createdBy', $this->app->user->account) - ->add('createdDate', helper::now()) - ->skipSpecial('url,token,account,password') - ->get(); - - $jenkins->password = base64_encode($jenkins->password); - - $this->dao->insert(TABLE_JENKINS)->data($jenkins) - ->batchCheck($this->config->jenkins->create->requiredFields, 'notempty') - ->batchCheck("url", 'URL') - ->autoCheck() - ->exec(); - if(dao::isError()) return false; - return $this->dao->lastInsertId(); + return $this->loadModel('pipeline')->create('jenkins'); } /** @@ -120,20 +95,6 @@ class jenkinsModel extends model */ public function update($id) { - $jenkins = fixer::input('post') - ->add('editedBy', $this->app->user->account) - ->add('editedDate', helper::now()) - ->skipSpecial('url,token,account,password') - ->get(); - - $jenkins->password = base64_encode($jenkins->password); - - $this->dao->update(TABLE_JENKINS)->data($jenkins) - ->batchCheck($this->config->jenkins->edit->requiredFields, 'notempty') - ->batchCheck("url", 'URL') - ->autoCheck() - ->where('id')->eq($id) - ->exec(); - return !dao::isError(); + return $this->loadModel('pipeline')->update($id); } } diff --git a/module/job/model.php b/module/job/model.php index 5d19e6c298..c948ada4e7 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -35,7 +35,7 @@ class jobModel extends model { return $this->dao->select('t1.*, t2.name as repoName, t3.name as jenkinsName')->from(TABLE_JOB)->alias('t1') ->leftJoin(TABLE_REPO)->alias('t2')->on('t1.repo=t2.id') - ->leftJoin(TABLE_JENKINS)->alias('t3')->on('t1.jkHost=t3.id') + ->leftJoin(TABLE_PIPELINE)->alias('t3')->on('t1.jkHost=t3.id') ->where('t1.deleted')->eq('0') ->orderBy($orderBy) ->page($pager) @@ -290,7 +290,7 @@ class jobModel extends model { $job = $this->dao->select('t1.id,t1.name,t1.product,t1.repo,t1.jkJob,t1.triggerType,t1.atTime,t1.customParam,t2.name as jenkinsName,t2.url,t2.account,t2.token,t2.password') ->from(TABLE_JOB)->alias('t1') - ->leftJoin(TABLE_JENKINS)->alias('t2')->on('t1.jkHost=t2.id') + ->leftJoin(TABLE_PIPELINE)->alias('t2')->on('t1.jkHost=t2.id') ->where('t1.id')->eq($id) ->fetch(); if(!$job) return false; diff --git a/module/pipeline/config.php b/module/pipeline/config.php new file mode 100644 index 0000000000..29bc37b2ea --- /dev/null +++ b/module/pipeline/config.php @@ -0,0 +1,5 @@ +pipeline->create = new stdclass(); +$config->pipeline->edit = new stdclass(); +$config->pipeline->create->requiredFields = 'name,url,type'; +$config->pipeline->edit->requiredFields = 'name,url,type'; diff --git a/module/pipeline/lang/zh-cn.php b/module/pipeline/lang/zh-cn.php new file mode 100644 index 0000000000..b949e9998d --- /dev/null +++ b/module/pipeline/lang/zh-cn.php @@ -0,0 +1,7 @@ +pipeline->id = 'ID'; +$lang->pipeline->name = '名称'; +$lang->pipeline->url = '服务地址'; +$lang->pipeline->token = 'Token'; +$lang->pipeline->account = '用户名'; +$lang->pipeline->password = '密码'; diff --git a/module/pipline/model.php b/module/pipeline/model.php similarity index 65% rename from module/pipline/model.php rename to module/pipeline/model.php index eb73a6a595..b650093146 100644 --- a/module/pipline/model.php +++ b/module/pipeline/model.php @@ -1,6 +1,6 @@ dao->select('*')->from(TABLE_PIPLINE)->where('id')->eq($id)->fetch(); - $pipline->password = base64_decode($pipline->password); - return $pipline; + $pipeline = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch(); + $pipeline->password = base64_decode($pipeline->password); + return $pipeline; } /** - * Get pipline list. + * Get pipeline list. * * @param string $type jenkins|gitlab * @param string $orderBy @@ -37,7 +37,7 @@ class piplineModel extends model */ public function getList($type = 'jenkins', $orderBy = 'id_desc', $pager = null) { - return $this->dao->select('*')->from(TABLE_PIPLINE) + return $this->dao->select('*')->from(TABLE_PIPELINE) ->where('deleted')->eq('0') ->AndWhere('type')->eq($type) ->orderBy($orderBy) @@ -46,39 +46,39 @@ class piplineModel extends model } /** - * Get pipline pairs + * Get pipeline pairs * * @return array */ public function getPairs($type) { - $pipline = $this->dao->select('id,name')->from(TABLE_PIPLINE) + $pipeline = $this->dao->select('id,name')->from(TABLE_PIPELINE) ->where('deleted')->eq('0') ->AndWhere('type')->eq($type) ->orderBy('id')->fetchPairs('id', 'name'); - $pipline = array('' => '') + $pipline; - return $pipline; + $pipeline = array('' => '') + $pipeline; + return $pipeline; } /** - * Create a pipline. + * Create a pipeline. * * @access public * @return bool */ public function create($type) { - $pipline = fixer::input('post') + $pipeline = fixer::input('post') ->add('type', $type) ->add('createdBy', $this->app->user->account) ->add('createdDate', helper::now()) ->skipSpecial('url,token,account,password') ->get(); - $pipline->password = base64_encode($pipline->password); + $pipeline->password = base64_encode($pipeline->password); - $this->dao->insert(TABLE_PIPLINE)->data($pipline) - ->batchCheck($this->config->pipline->create->requiredFields, 'notempty') + $this->dao->insert(TABLE_PIPELINE)->data($pipeline) + ->batchCheck($this->config->pipeline->create->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() ->exec(); @@ -87,7 +87,7 @@ class piplineModel extends model } /** - * Update a pipline. + * Update a pipeline. * * @param int $id * @access public @@ -95,16 +95,16 @@ class piplineModel extends model */ public function update($id) { - $pipline = fixer::input('post') + $pipeline = fixer::input('post') ->add('editedBy', $this->app->user->account) ->add('editedDate', helper::now()) ->skipSpecial('url,token,account,password') ->get(); - $pipline->password = base64_encode($pipline->password); + $pipeline->password = base64_encode($pipeline->password); - $this->dao->update(TABLE_PIPLINE)->data($pipline) - ->batchCheck($this->config->pipline->edit->requiredFields, 'notempty') + $this->dao->update(TABLE_PIPELINE)->data($pipeline) + ->batchCheck($this->config->pipeline->edit->requiredFields, 'notempty') ->batchCheck("url", 'URL') ->autoCheck() ->where('id')->eq($id) diff --git a/module/pipline/config.php b/module/pipline/config.php deleted file mode 100644 index 0228d4f00c..0000000000 --- a/module/pipline/config.php +++ /dev/null @@ -1,5 +0,0 @@ -pipline->create = new stdclass(); -$config->pipline->edit = new stdclass(); -$config->pipline->create->requiredFields = 'name,url,type'; -$config->pipline->edit->requiredFields = 'name,url,type'; diff --git a/module/pipline/lang/zh-cn.php b/module/pipline/lang/zh-cn.php deleted file mode 100644 index 8d81ee7093..0000000000 --- a/module/pipline/lang/zh-cn.php +++ /dev/null @@ -1,7 +0,0 @@ -pipline->id = 'ID'; -$lang->pipline->name = '名称'; -$lang->pipline->url = '服务地址'; -$lang->pipline->token = 'Token'; -$lang->pipline->account = '用户名'; -$lang->pipline->password = '密码';