diff --git a/module/gitea/control.php b/module/gitea/control.php index d95e35ab6d..3e0822b020 100644 --- a/module/gitea/control.php +++ b/module/gitea/control.php @@ -153,7 +153,7 @@ class gitea extends control public function delete($giteaID) { $oldGitea = $this->loadModel('pipeline')->getByID($giteaID); - $actionID = $this->pipeline->delete($giteaID, 'gitea'); + $actionID = $this->pipeline->deleteByObject($giteaID, 'gitea'); if(!$actionID) { $response['result'] = 'fail'; diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 11b0853457..e6c1dbfb3f 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -261,7 +261,7 @@ class gitlab extends control public function delete($id) { $oldGitLab = $this->loadModel('pipeline')->getByID($id); - $actionID = $this->pipeline->delete($id, 'gitlab'); + $actionID = $this->pipeline->deleteByObject($id, 'gitlab'); if(!$actionID) { $response['result'] = 'fail'; diff --git a/module/gogs/control.php b/module/gogs/control.php index 243bf57af4..20107859b6 100644 --- a/module/gogs/control.php +++ b/module/gogs/control.php @@ -151,7 +151,7 @@ class gogs extends control public function delete($gogsID) { $oldGogs = $this->loadModel('pipeline')->getByID($gogsID); - $actionID = $this->pipeline->delete($gogsID, 'gogs'); + $actionID = $this->pipeline->deleteByObject($gogsID, 'gogs'); if(!$actionID) { $response['result'] = 'fail'; diff --git a/module/instance/control.php b/module/instance/control.php index d474dc3e6f..28deac9750 100644 --- a/module/instance/control.php +++ b/module/instance/control.php @@ -493,7 +493,7 @@ class instance extends control if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false); $oldApp = $this->loadModel('pipeline')->getByID($externalID); - $actionID = $this->pipeline->delete($externalID, $oldApp->type); + $actionID = $this->pipeline->deleteByObject($externalID, $oldApp->type); if(!$actionID) { $response['result'] = 'fail'; @@ -642,7 +642,7 @@ class instance extends control $externalApp = $this->loadModel('space')->getExternalAppByApp($instance); if($externalApp) { - $actionID = $this->loadModel('pipeline')->delete($externalApp->id, strtolower($instance->appName)); + $actionID = $this->loadModel('pipeline')->deleteByObject($externalApp->id, strtolower($instance->appName)); if(!$actionID) return $this->send(array('result' => 'fail', 'message' => $this->lang->pipeline->delError)); } diff --git a/module/pipeline/model.php b/module/pipeline/model.php index 1b809bbaac..736a710d9d 100644 --- a/module/pipeline/model.php +++ b/module/pipeline/model.php @@ -1,25 +1,26 @@ - * @package product - * @version $Id: $ + * @package pipeline * @link http://www.zentao.net */ class pipelineModel extends model { /** + * 根据id获取一条服务器记录。 * Get a pipeline by id. * * @param int $id * @access public - * @return object + * @return object|false */ - public function getByID($id) + public function getByID(int $id): object|false { $pipeline = $this->dao->select('*')->from(TABLE_PIPELINE)->where('id')->eq($id)->fetch(); if($pipeline && !empty($pipeline->password)) $pipeline->password = base64_decode($pipeline->password); @@ -33,9 +34,9 @@ class pipelineModel extends model * @param string $name * @param string $type * @access public - * @return object + * @return object|false */ - public function getByNameAndType(string $name, string $type) + public function getByNameAndType(string $name, string $type): object|false { return $this->dao->select('id')->from(TABLE_PIPELINE)->where('name')->eq($name)->andWhere('type')->eq($type)->fetch(); } @@ -46,23 +47,24 @@ class pipelineModel extends model * * @param string $url * @access public - * @return object + * @return object|false */ - public function getByUrl(string $url) + public function getByUrl(string $url): object|false { return $this->dao->select('id')->from(TABLE_PIPELINE)->where('url')->eq($url)->andWhere('createdBy')->eq('system')->fetch(); } /** + * 获取服务器列表。 * Get pipeline list. * - * @param string $type jenkins|gitlab + * @param string $type * @param string $orderBy * @param object $pager * @access public * @return array */ - public function getList($type = 'jenkins', $orderBy = 'id_desc', $pager = null) + public function getList(string $type = 'jenkins', string $orderBy = 'id_desc', object|null $pager = null): array { return $this->dao->select('*')->from(TABLE_PIPELINE) ->where('deleted')->eq('0') @@ -73,22 +75,24 @@ class pipelineModel extends model } /** - * Get pipeline pairs + * 获取服务器列表。 + * Get pipeline pairs. * + * @param string $type + * @access public * @return array */ - public function getPairs($type = null) + public function getPairs(string $type = ''): array { - $pipeline = $this->dao->select('id,name')->from(TABLE_PIPELINE) + return $this->dao->select('id,name')->from(TABLE_PIPELINE) ->where('deleted')->eq('0') ->beginIF($type)->AndWhere('type')->eq($type)->fi() ->orderBy('id')->fetchPairs('id', 'name'); - - return $pipeline; } /** - * Create a pipeline. + * 创建服务器。 + * Create a server. * * @access public * @return bool @@ -115,13 +119,14 @@ class pipelineModel extends model } /** - * Update a pipeline. + * 更新服务器。 + * Update a server. * * @param int $id * @access public * @return bool */ - public function update($id) + public function update(int $id): bool { $pipeline = fixer::input('post') ->add('editedBy', $this->app->user->account) @@ -149,25 +154,26 @@ class pipelineModel extends model } /** + * 删除服务器。 * Delete one record. * - * @param string $id the id to be deleted - * @param string $object the action object + * @param string $id the id to be deleted + * @param string $type the action object * @access public * @return int|bool */ - public function delete($id, $object = 'gitlab') + public function deleteByObject(int $id, string $type = 'gitlab'): int|bool { - if(in_array($object, array('gitlab', 'gitea', 'gogs'))) + if(in_array($type, array('gitlab', 'gitea', 'gogs'))) { $repo = $this->dao->select('*')->from(TABLE_REPO) ->where('deleted')->eq('0') - ->andWhere('SCM')->eq(ucfirst($object)) + ->andWhere('SCM')->eq(ucfirst($type)) ->andWhere('serviceHost')->eq($id) ->fetch(); if($repo) return false; } - elseif($object == 'sonarqube') + elseif($type == 'sonarqube') { $job = $this->dao->select('id,name,repo,deleted')->from(TABLE_JOB) ->where('frame')->eq('sonarqube') @@ -177,7 +183,7 @@ class pipelineModel extends model if($job) return false; } $this->dao->update(TABLE_PIPELINE)->set('deleted')->eq(1)->where('id')->eq($id)->exec(); - $this->loadModel('action')->create($object, $id, 'deleted', ''); + $this->loadModel('action')->create($type, $id, 'deleted', ''); $actionID = $this->dao->lastInsertID(); return $actionID; diff --git a/module/pipeline/test/model/delete.php b/module/pipeline/test/model/deletebyobject.php similarity index 88% rename from module/pipeline/test/model/delete.php rename to module/pipeline/test/model/deletebyobject.php index 8f3d02ef7a..cf9b480ee0 100755 --- a/module/pipeline/test/model/delete.php +++ b/module/pipeline/test/model/deletebyobject.php @@ -6,7 +6,7 @@ su('admin'); /** -title=测试 pipelineModel->delete(); +title=测试 pipelineModel->deleteByObject(); cid=1 pid=1 diff --git a/module/pipeline/test/pipeline.class.php b/module/pipeline/test/pipeline.class.php index 2fd000a20b..c981933708 100644 --- a/module/pipeline/test/pipeline.class.php +++ b/module/pipeline/test/pipeline.class.php @@ -1,7 +1,7 @@ objectModel = $tester->loadModel('pipeline'); } @@ -29,8 +29,8 @@ class pipelineTest return $objects; } - - /** + + /** * Get pipeline list. * * @param string $type jenkins|gitlab @@ -51,16 +51,16 @@ class pipelineTest /** * Get pipeline pairs * - * @param int $data + * @param int $data * @access public - * @return array + * @return array */ public function getPairs($data) { $objects = $this->objectModel->getPairs($data['type']); - if(empty($objects)) return '没有获取到数据'; - if(isset($data['id'])) return $objects[$data['id']]; + if(empty($objects)) return '没有获取到数据'; + if(isset($data['id'])) return $objects[$data['id']]; if(dao::isError()) return dao::getError(); return $objects; @@ -69,8 +69,8 @@ class pipelineTest /** * Create a pipeline. * - * @param int $type - * @param int $param + * @param int $type + * @param int $param * @access public * @return void */ @@ -79,7 +79,7 @@ class pipelineTest foreach($param as $k => $v) $_POST[$k] = $v; $objects = $this->objectModel->create($type); unset($_POST); - + if(dao::isError()) return dao::getError(); $objects = $this->objectModel->getById($objects); @@ -115,7 +115,7 @@ class pipelineTest */ public function deleteTest($id, $object = 'gitlab') { - $objects = $this->objectModel->delete($id, $object = 'gitlab'); + $objects = $this->objectModel->deleteByObject($id, $object); if(dao::isError()) return dao::getError(); diff --git a/module/sonarqube/control.php b/module/sonarqube/control.php index 0ce669b5e9..87d3720c7c 100644 --- a/module/sonarqube/control.php +++ b/module/sonarqube/control.php @@ -231,7 +231,7 @@ class sonarqube extends control { $oldSonarQube = $this->loadModel('pipeline')->getByID($sonarqubeID); $this->loadModel('action'); - $actionID = $this->pipeline->delete($sonarqubeID, 'sonarqube'); + $actionID = $this->pipeline->deleteByObject($sonarqubeID, 'sonarqube'); if($actionID) { $response['result'] = 'fail';