Files
EasySoft-ZenTaoPMS/module/sonarqube/control.php
T
2022-01-12 01:46:35 +00:00

100 lines
3.7 KiB
PHP

<?php
/**
* The control file of sonarqube module of ZenTaoPMS.
*
* @copyright Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Yanyi Cao <caoyanyi@easycorp.ltd>
* @package sonarqube
* @version $Id: ${FILE_NAME} 5144 2022/1/11 8:55 上午 caoyanyi@easycorp.ltd $
* @link http://www.zentao.net
*/
class sonarqube extends control
{
/**
* The sonarqube constructor.
* @param string $moduleName
* @param string $methodName
*/
public function __construct($moduleName = '', $methodName = '')
{
parent::__construct($moduleName, $methodName);
/* Optional: common::setMenuVars('devops', $this->session->repoID); */
$this->loadModel('ci')->setMenu();
}
/**
* Browse sonarqube.
*
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$sonarqubeList = $this->sonarqube->getList($orderBy, $pager);
$this->view->title = $this->lang->sonarqube->common . $this->lang->colon . $this->lang->sonarqube->browse;
$this->view->sonarqubeList = $sonarqubeList;
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->display();
}
/**
* create a sonarqube.
*
* @access public
* @return void
*/
public function create()
{
if($_POST)
{
$this->checkToken();
$sonarqubeID = $this->loadModel('pipeline')->create('sonarqube');
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action');
$actionID = $this->action->create('sonarqube', $sonarqubeID, 'created');
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->sonarqube->common . $this->lang->colon . $this->lang->sonarqube->createServer;
$this->display();
}
/**
* Check post info.
*
* @access protected
* @return void
*/
protected function checkToken()
{
$sonarqube = fixer::input('post')->get();
$this->dao->update('sonarqube')->data($sonarqube)->batchCheck($this->config->sonarqube->create->requiredFields, 'notempty');
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(strpos($sonarqube->url, 'http') !== 0) return $this->send(array('result' => 'fail', 'message' => array('url' => array($this->lang->sonarqube->hostError))));
/* Check name and url unique. */
$isExist = $this->dao->select('*')->from(TABLE_PIPELINE)->where("name='{$sonarqube->name}' or url='{$sonarqube->url}'")->fetch();
if($isExist) return $this->send(array('result' => 'fail', 'message' => $this->lang->sonarqube->repeatError));
$token = base64_encode("{$sonarqube->account}:{$sonarqube->password}");
$result = $this->sonarqube->apiValidate($sonarqube->url, $token);
if(!isset($result->valid) or !$result->valid) return $this->send(array('result' => 'fail', 'message' => array('token' => array($this->lang->sonarqube->validError))));
$this->post->set('token', $token);
}
}