builds.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * The builds 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 Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class buildsEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $projectID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($projectID = 0)
  22. {
  23. if(empty($projectID)) $projectID = $this->param('project', 0);
  24. if(empty($projectID)) return $this->sendError(400, "Need project id.");
  25. $control = $this->loadController('projectbuild', 'browse');
  26. $control->browse($projectID, $this->param('type', 'all'), $this->param('param', 0), $this->param('order', 't1.date_desc,t1.id_desc'));
  27. $data = $this->getData();
  28. if(!isset($data->status)) return $this->sendError(400, 'error');
  29. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  30. $result = array();
  31. foreach($data->data->builds as $build)
  32. {
  33. $result[] = $this->format($build, 'bugs:idList,stories:idList,builder:user,deleted:bool');
  34. }
  35. return $this->send(200, array('total' => count($result), 'builds' => $result));
  36. }
  37. /**
  38. * POST method.
  39. *
  40. * @param int $projectID
  41. * @access public
  42. * @return string
  43. */
  44. public function post($projectID = 0)
  45. {
  46. $control = $this->loadController('build', 'create');
  47. if(!$projectID) $projectID = $this->param('project', 0);
  48. $project = $this->loadModel('project')->getByID($projectID);
  49. if(!$project) return $this->sendError(404, 'Error project id');
  50. $this->setPost('project', $projectID);
  51. $fields = 'execution,product,name,builder,date,scmPath,filePath,desc,branch';
  52. $this->batchSetPost($fields);
  53. $this->requireFields('execution,product,name,builder,date');
  54. $executionID = isset($_POST['execution']) ? $_POST['execution'] : 0;
  55. $control->create($executionID, 0, $projectID);
  56. $data = $this->getData();
  57. if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
  58. if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message);
  59. $build = $this->loadModel('build')->getByID($data->id);
  60. return $this->send(201, $build);
  61. }
  62. }