jobs.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * The jobs entry point 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 Yanyi Cao <caoyanyi@easycorp.ltd>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class jobsEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @access public
  18. * @return string
  19. */
  20. public function get()
  21. {
  22. $control = $this->loadController('job', 'browse');
  23. $pipeline = $this->param('pipeline', '');
  24. $orderBy = $this->param('order', 'id_desc');
  25. if(empty($pipeline))
  26. {
  27. $control->browse($orderBy, 0, $this->param('limit', 100), $this->param('page', 1));
  28. /* Response */
  29. $data = $this->getData();
  30. if(isset($data->status) and $data->status == 'success')
  31. {
  32. $result = array();
  33. $pager = $data->data->pager;
  34. $jobs = $data->data->jobList;
  35. foreach($jobs as $job) $result[] = $this->format($job, 'deleted:bool,lastSync:datetime,synced:bool,product:idList');
  36. return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'jobs' => $result));
  37. }
  38. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  39. }
  40. else
  41. {
  42. $jobs = $this->loadModel('job')->getList(0, '', $orderBy, null, $this->param('engine', 'jenkins'), $pipeline);
  43. return $this->send(200, array('jobs' => array_values($jobs)));
  44. }
  45. return $this->sendError(400, 'error');
  46. }
  47. }