control.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * The control file of compile of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Yidong Wang <yidong@cnezsoft.com>
  8. * @package compile
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class compile extends control
  13. {
  14. /**
  15. * Construct
  16. *
  17. * @param string $moduleName
  18. * @param string $methodName
  19. * @access public
  20. * @return void
  21. */
  22. public function __construct($moduleName = '', $methodName = '')
  23. {
  24. parent::__construct($moduleName, $methodName);
  25. if(!in_array($this->app->rawMethod, array('browse', 'logs'))) $this->loadModel('ci')->setMenu();
  26. }
  27. /**
  28. * Browse jenkins build.
  29. *
  30. * @param int $repoID
  31. * @param int $jobID
  32. * @param string $browseType
  33. * @param int $param
  34. * @param string $orderBy
  35. * @param int $recTotal
  36. * @param int $recPerPage
  37. * @param int $pageID
  38. * @access public
  39. * @return void
  40. */
  41. public function browse($repoID = 0, $jobID = 0, $browseType = '', $param = 0, $orderBy = 'createdDate_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  42. {
  43. $this->loadModel('ci');
  44. $this->loadModel('job');
  45. if($jobID)
  46. {
  47. $job = $this->job->getByID($jobID);
  48. $repoID = $job->repo;
  49. $this->view->job = $job;
  50. }
  51. if($repoID)
  52. {
  53. $this->ci->setMenu($repoID);
  54. }
  55. else
  56. {
  57. $this->session->set('repoID', 0);
  58. }
  59. $this->app->loadClass('pager', true);
  60. $pager = new pager($recTotal, $recPerPage, $pageID);
  61. $this->compileZen->buildSearchForm($repoID, $jobID, (int)$param);
  62. $buildList = $this->compile->getList($repoID, $jobID, $browseType, (int)$param, $orderBy, $pager);
  63. foreach($buildList as $build) $build->triggerType = $this->job->getTriggerConfig($build);
  64. $this->view->title = $this->lang->ci->job . $this->lang->hyphen . $this->lang->compile->browse;
  65. $this->view->repoID = $repoID;
  66. $this->view->jobID = $jobID;
  67. $this->view->buildList = $buildList;
  68. $this->view->orderBy = $orderBy;
  69. $this->view->pager = $pager;
  70. $this->view->browseType = $browseType;
  71. $this->view->param = $param;
  72. $this->display();
  73. }
  74. /**
  75. * View jenkins build logs.
  76. *
  77. * @param int $buildID
  78. * @access public
  79. * @return void
  80. */
  81. public function logs($buildID)
  82. {
  83. $this->loadModel('ci');
  84. if($this->session->repoID)
  85. {
  86. $this->ci->setMenu();
  87. $this->view->repoID = $this->session->repoID;
  88. }
  89. $build = $this->compile->getByID($buildID);
  90. $job = $this->loadModel('job')->getByID($build->job);
  91. if(!in_array($build->status, array('created', 'pending'))) $build->logs = $this->compile->getLogs($job, $build);
  92. $logs = $build->logs ? str_replace(array("\r\n", "\n"), "<br />", $build->logs) : '';
  93. $this->view->logs = $logs;
  94. $this->view->build = $build;
  95. $this->view->job = $job;
  96. $this->view->title = $this->lang->ci->job . $this->lang->hyphen . $this->lang->compile->logs;
  97. $this->display();
  98. }
  99. /**
  100. * Sync compiles.
  101. *
  102. * @param int $repoID
  103. * @param int $jobID
  104. * @access public
  105. * @return bool
  106. */
  107. public function ajaxSyncCompile($repoID = 0, $jobID = 0)
  108. {
  109. $this->compile->syncCompile($repoID, $jobID);
  110. if(dao::isError())
  111. {
  112. echo json_encode(dao::getError());
  113. return true;
  114. }
  115. echo 'success';
  116. }
  117. }