From 41b7d853d354858962a3f6f546667babe6d494e1 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 14 Jan 2022 03:16:55 +0000 Subject: [PATCH 1/5] * Fix bug #18454. --- module/sonarqube/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/sonarqube/model.php b/module/sonarqube/model.php index 46f33d075d..854d6bd657 100644 --- a/module/sonarqube/model.php +++ b/module/sonarqube/model.php @@ -60,7 +60,7 @@ class sonarqubeModel extends model public function getApiBase($sonarqubeID) { $sonarqube = $this->getByID($sonarqubeID); - if(!$sonarqube) return ''; + if(!$sonarqube) return array('', array('')); $url = rtrim($sonarqube->url, '/') . '/api/%s'; $header[] = 'Authorization: Basic ' . $sonarqube->token; From 0be41abb83249c05a69792fd8749a30adcd5fe12 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 14 Jan 2022 03:22:47 +0000 Subject: [PATCH 2/5] * Fix bug #18442. --- module/job/js/create.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/job/js/create.js b/module/job/js/create.js index 3bff90333d..d147f5fc70 100644 --- a/module/job/js/create.js +++ b/module/job/js/create.js @@ -18,6 +18,8 @@ $(document).ready(function() $('#frameBox .loading').remove(); $('#frameBox .input-group').append(html); $('#frameBox #frame').chosen(); + + $('#frame').change(); } getFrameSelect(''); @@ -241,10 +243,10 @@ $(document).ready(function() $('tr.gitlabRepo').hide(); $('tr.commonRepo').show(); } + getFrameSelect(engine); }); $('#engine').change(); - $('#triggerType').change(); }); From 20f291b9b2c4ea1fcdbb8cd02ced6092cac8349e Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Fri, 14 Jan 2022 06:52:35 +0000 Subject: [PATCH 3/5] * Fix bug #18448. --- module/job/control.php | 6 +++--- module/job/lang/en.php | 1 + module/job/lang/zh-cn.php | 1 + module/job/model.php | 31 +++++++++++++++++++++++++++---- module/sonarqube/control.php | 10 ++++++++-- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/module/job/control.php b/module/job/control.php index d3ed975c64..53343533dc 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -121,7 +121,7 @@ class job extends control $this->view->products = array(0 => '') + $this->loadModel('product')->getProductPairsByProject($this->projectID); $this->view->jenkinsServerList = array('' => '') + $this->loadModel('jenkins')->getPairs(); - $this->view->sonarqubeServerList = array('' => '') + $this->loadModel('sonarqube')->getPairs(); + $this->view->sonarqubeServerList = array('') + $this->loadModel('sonarqube')->getPairs(); $this->display(); } @@ -198,9 +198,9 @@ class job extends control $this->view->repoTypes = $repoTypes; $this->view->repoType = zget($repoTypes, $job->repo, 'Git'); $this->view->job = $job; - $this->view->products = array(0 => '') + $products; + $this->view->products = array('') + $products; $this->view->jenkinsServerList = $this->loadModel('jenkins')->getPairs(); - $this->view->sonarqubeServerList = array('' => '') + $this->loadModel('sonarqube')->getPairs(); + $this->view->sonarqubeServerList = array('') + $this->loadModel('sonarqube')->getPairs(); $this->view->pipelines = $this->jenkins->getTasks($job->server); $this->display(); diff --git a/module/job/lang/en.php b/module/job/lang/en.php index 5aa7bb3833..bb21e8847e 100644 --- a/module/job/lang/en.php +++ b/module/job/lang/en.php @@ -57,6 +57,7 @@ $lang->job->sendExec = 'Send execute request success.'; $lang->job->inputName = 'Please enter parameter name.'; $lang->job->invalidName = 'The parameter name should be letters, numbers or underlines.'; $lang->job->repoExists = 'This repository has a build task associated with it『%s』'; +$lang->job->projectExists = 'This SonarQube Project has a build task associated with it『%s』'; $lang->job->mustUseJenkins = 'SonarQube frame is only used if the build engine is JenKins.'; $lang->job->buildTypeList['build'] = 'Only Build'; diff --git a/module/job/lang/zh-cn.php b/module/job/lang/zh-cn.php index 1994eab804..a109e455bb 100644 --- a/module/job/lang/zh-cn.php +++ b/module/job/lang/zh-cn.php @@ -57,6 +57,7 @@ $lang->job->sendExec = '发送执行请求成功!执行结果:%s'; $lang->job->inputName = '请输入参数名称。'; $lang->job->invalidName = '参数名称应该是英文字母、数字或下划线的组合。'; $lang->job->repoExists = '此版本库已关联构建任务『%s』'; +$lang->job->projectExists = '此SonarQube项目已关联构建任务『%s』'; $lang->job->mustUseJenkins = 'SonarQube工具/框架仅在构建引擎为JenKins的情况下使用'; $lang->job->buildTypeList['build'] = '仅构建'; diff --git a/module/job/model.php b/module/job/model.php index bf4b7e9b24..7a72790577 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -194,12 +194,23 @@ class jobModel extends model $sonarqubeJob = $this->getSonarqubeByRepo(array($job->repo)); if(!empty($sonarqubeJob)) { - $message = sprintf($this->lang->job->repoExists, $repo[$repoID]->id . '-' . $repo[$repoID]->name); + $message = sprintf($this->lang->job->repoExists, $sonarqubeJob[$job->repo]->id . '-' . $sonarqubeJob[$job->repo]->name); dao::$errors[]['repo'] = $message; return false; } } + if(!empty($job->projectKey) and $job->frame == 'sonarqube') + { + $projectList = $this->getJobBySonarqubeProject($job->sonarqubeServer, array($job->projectKey)); + if(!empty($projectList)) + { + $message = sprintf($this->lang->job->projectExists, $projectList[$job->projectKey]->id); + dao::$errors[]['projectKey'] = $message; + return false; + } + } + if($job->triggerType == 'schedule') $job->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); $job->svnDir = ''; @@ -300,12 +311,23 @@ class jobModel extends model $sonarqubeJob = $this->getSonarqubeByRepo(array($job->repo), $id); if(!empty($sonarqubeJob)) { - $message = sprintf($this->lang->job->repoExists, $repo[$repoID]->id . '-' . $repo[$repoID]->name); + $message = sprintf($this->lang->job->repoExists, $sonarqubeJob[$job->repo]->id . '-' . $sonarqubeJob[$job->repo]->name); dao::$errors[]['repo'] = $message; return false; } } + if(!empty($job->projectKey) and $job->frame == 'sonarqube') + { + $projectList = $this->getJobBySonarqubeProject($job->sonarqubeServer, array($job->projectKey)); + if(!empty($projectList) && $projectList[$job->projectKey]->id != $id) + { + $message = sprintf($this->lang->job->projectExists, $projectList[$job->projectKey]->id); + dao::$errors[]['projectKey'] = $message; + return false; + } + } + if($job->triggerType == 'schedule') $job->atDay = empty($_POST['atDay']) ? '' : join(',', $this->post->atDay); $job->svnDir = ''; @@ -599,16 +621,17 @@ class jobModel extends model * * @param int $sonarqubeID * @param array $projectKeys + * @param bool $emptyShowAll * @access public * @return array */ - public function getJobBySonarqubeProject($sonarqubeID, $projectKeys = array()) + public function getJobBySonarqubeProject($sonarqubeID, $projectKeys = array(), $emptyShowAll = false) { return $this->dao->select('projectKey,id')->from(TABLE_JOB) ->where('deleted')->eq(0) ->andWhere('frame')->eq('sonarqube') ->andWhere('sonarqubeServer')->eq($sonarqubeID) - ->andWhere('projectKey')->in($projectKeys) + ->beginIF(!empty($projectKeys) or !$emptyShowAll)->andWhere('projectKey')->in($projectKeys)->fi() ->fetchPairs(); } } diff --git a/module/sonarqube/control.php b/module/sonarqube/control.php index 84b57e577b..c0e3d22fac 100644 --- a/module/sonarqube/control.php +++ b/module/sonarqube/control.php @@ -60,10 +60,16 @@ class sonarqube extends control */ public function ajaxGetProjectList($sonarqubeID, $projectKey = '') { - $projectList = $this->loadModel('sonarqube')->apiGetProjects($sonarqubeID); + $jobPairs = $this->loadModel('job')->getJobBySonarqubeProject($sonarqubeID, array(), true); + $existsProject = array_diff(array_keys($jobPairs), array($projectKey)); + + $projectList = $this->sonarqube->apiGetProjects($sonarqubeID); $projectPairs = array('' => ''); - foreach($projectList as $project) $projectPairs[$project->key] = $project->name; + foreach($projectList as $project) + { + if(!empty($project) and !in_array($project->key, $existsProject)) $projectPairs[$project->key] = $project->name; + } echo html::select('projectKey', $projectPairs, str_replace('*', '-', $projectKey), "class='form-control chosen'"); } From 07ba811bc2597e5ed4585152b46a11f3a87ec768 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 17 Jan 2022 01:22:51 +0000 Subject: [PATCH 4/5] * Modify trash data tips. --- module/job/control.php | 4 ++-- module/job/lang/en.php | 1 + module/job/lang/zh-cn.php | 1 + module/job/model.php | 10 ++++++---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/module/job/control.php b/module/job/control.php index 53343533dc..061d5a9195 100644 --- a/module/job/control.php +++ b/module/job/control.php @@ -426,10 +426,10 @@ class job extends control */ public function ajaxCheckSonarqubeLink($repoID, $jobID = 0) { - $repo = $this->loadModel('job')->getSonarqubeByRepo(array($repoID), $jobID); + $repo = $this->loadModel('job')->getSonarqubeByRepo(array($repoID), $jobID, true); if(!empty($repo)) { - $message = sprintf($this->lang->job->repoExists, $repo[$repoID]->id . '-' . $repo[$repoID]->name); + $message = $repo[$repoID]->deleted ? $this->lang->job->jobIsDeleted : sprintf($this->lang->job->repoExists, $repo[$repoID]->id . '-' . $repo[$repoID]->name); $this->send(array('result' => 'fail', 'message' => $message)); } $this->send(array('result' => 'success', 'message' => '')); diff --git a/module/job/lang/en.php b/module/job/lang/en.php index bb21e8847e..e8b58344a5 100644 --- a/module/job/lang/en.php +++ b/module/job/lang/en.php @@ -59,6 +59,7 @@ $lang->job->invalidName = 'The parameter name should be letters, numbers or u $lang->job->repoExists = 'This repository has a build task associated with it『%s』'; $lang->job->projectExists = 'This SonarQube Project has a build task associated with it『%s』'; $lang->job->mustUseJenkins = 'SonarQube frame is only used if the build engine is JenKins.'; +$lang->job->jobIsDeleted = 'This repository is associated with a build task, please view the data from the recycle bin'; $lang->job->buildTypeList['build'] = 'Only Build'; $lang->job->buildTypeList['buildAndDeploy'] = 'Build And Deploy'; diff --git a/module/job/lang/zh-cn.php b/module/job/lang/zh-cn.php index a109e455bb..5f7bb63f04 100644 --- a/module/job/lang/zh-cn.php +++ b/module/job/lang/zh-cn.php @@ -59,6 +59,7 @@ $lang->job->invalidName = '参数名称应该是英文字母、数字或下 $lang->job->repoExists = '此版本库已关联构建任务『%s』'; $lang->job->projectExists = '此SonarQube项目已关联构建任务『%s』'; $lang->job->mustUseJenkins = 'SonarQube工具/框架仅在构建引擎为JenKins的情况下使用'; +$lang->job->jobIsDeleted = '此版本库已关联构建任务,请从回收站查看数据'; $lang->job->buildTypeList['build'] = '仅构建'; $lang->job->buildTypeList['buildAndDeploy'] = '构建部署'; diff --git a/module/job/model.php b/module/job/model.php index 7a72790577..1e416f67da 100644 --- a/module/job/model.php +++ b/module/job/model.php @@ -603,15 +603,17 @@ class jobModel extends model * Get sonarqube by RepoID. * * @param array $repoIDList + * @param int $jobID + * @param bool $showDeleted * @access public * @return array */ - public function getSonarqubeByRepo($repoIDList, $jobID = 0) + public function getSonarqubeByRepo($repoIDList, $jobID = 0, $showDeleted = false) { - return $this->dao->select('id,name,repo')->from(TABLE_JOB) - ->where('deleted')->eq('0') - ->andWhere('frame')->eq('sonarqube') + return $this->dao->select('id,name,repo,deleted')->from(TABLE_JOB) + ->where('frame')->eq('sonarqube') ->andWhere('repo')->in($repoIDList) + ->beginIF(!$showDeleted)->andWhere('deleted')->eq('0')->fi() ->beginIF($jobID > 0)->andWhere('id')->ne($jobID)->fi() ->fetchAll('repo'); } From 46fda606475e236124637e5bf27efec9f7de0df3 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 17 Jan 2022 01:57:23 +0000 Subject: [PATCH 5/5] * Modify return value. --- module/sonarqube/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/sonarqube/model.php b/module/sonarqube/model.php index 854d6bd657..ebdbddc79c 100644 --- a/module/sonarqube/model.php +++ b/module/sonarqube/model.php @@ -60,7 +60,7 @@ class sonarqubeModel extends model public function getApiBase($sonarqubeID) { $sonarqube = $this->getByID($sonarqubeID); - if(!$sonarqube) return array('', array('')); + if(!$sonarqube) return array('', array()); $url = rtrim($sonarqube->url, '/') . '/api/%s'; $header[] = 'Authorization: Basic ' . $sonarqube->token;