bug.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * The bug 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 bugEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. *
  17. * @param int $bugID
  18. * @access public
  19. * @return string
  20. */
  21. public function get($bugID)
  22. {
  23. $this->resetOpenApp($this->param('tab', 'product'));
  24. $control = $this->loadController('bug', 'view');
  25. $control->view($bugID);
  26. $data = $this->getData();
  27. if(!$data or !isset($data->status)) return $this->send400('error');
  28. if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message);
  29. $bug = $data->data->bug;
  30. /* Set product name and status */
  31. $bug->productName = $data->data->product->name;
  32. $bug->productStatus = $data->data->product->status;
  33. /* Set module title */
  34. $moduleTitle = '';
  35. if(empty($bug->module)) $moduleTitle = '/';
  36. if($bug->module)
  37. {
  38. $modulePath = $data->data->modulePath;
  39. foreach($modulePath as $key => $module)
  40. {
  41. $moduleTitle .= $module->name;
  42. if(isset($modulePath[$key + 1])) $moduleTitle .= '/';
  43. }
  44. }
  45. $bug->moduleTitle = $moduleTitle;
  46. $openedBuilds = array();
  47. foreach(explode(',', $bug->openedBuild) as $buildID)
  48. {
  49. if(empty($buildID)) continue;
  50. $openedBuild = new stdclass();
  51. $openedBuild->id = $buildID;
  52. $openedBuild->title = zget($data->data->builds, $buildID, '');
  53. $openedBuilds[] = $openedBuild;
  54. }
  55. $bug->openedBuild = $openedBuilds;
  56. if($bug->resolvedBuild)
  57. {
  58. $resolvedBuild = new stdclass();
  59. $resolvedBuild->id = $bug->resolvedBuild;
  60. $resolvedBuild->title = zget($data->data->builds, $bug->resolvedBuild, '');
  61. $bug->resolvedBuild = $resolvedBuild;
  62. }
  63. $bug->actions = $this->loadModel('action')->processActionForAPI($data->data->actions, $data->data->users, $this->lang->bug);
  64. $preAndNext = $data->data->preAndNext;
  65. $bug->preAndNext = array();
  66. $bug->preAndNext['pre'] = $preAndNext->pre ? $preAndNext->pre->id : '';
  67. $bug->preAndNext['next'] = $preAndNext->next ? $preAndNext->next->id : '';
  68. return $this->send(200, $this->format($bug, 'activatedDate:time,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,mailto:userList,resolvedBy:user,resolvedDate:time,closedBy:user,closedDate:time,lastEditedBy:user,lastEditedDate:time,deadline:date,deleted:bool'));
  69. }
  70. /**
  71. * PUT method.
  72. *
  73. * @param int $bugID
  74. * @access public
  75. * @return string
  76. */
  77. public function put($bugID)
  78. {
  79. $control = $this->loadController('bug', 'edit');
  80. $oldBug = $this->loadModel('bug')->getByID($bugID);
  81. /* Set $_POST variables. */
  82. $fields = 'uid,title,project,execution,openedBuild,assignedTo,pri,severity,type,story,resolvedBy,resolvedBuild,resolvedDate,closedBy,resolution,product,plan,task,module,steps,mailto,keywords,deadline,os,browser,feedbackBy';
  83. $this->batchSetPost($fields, $oldBug);
  84. $this->setPost('notifyEmail', implode(',', $this->request('notifyEmail', array())));
  85. $control->edit($bugID);
  86. $data = $this->getData();
  87. if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message);
  88. if(!isset($data->status)) return $this->sendError(400, 'error');
  89. $bug = $this->bug->getByID($bugID);
  90. return $this->send(200, $this->format($bug, 'activatedDate:time,openedBy:user,openedDate:time,assignedTo:user,assignedDate:time,mailto:userList,resolvedBy:user,resolvedDate:time,closedBy:user,closedDate:time,lastEditedBy:user,lastEditedDate:time,deadline:date,deleted:bool'));
  91. }
  92. /**
  93. * DELETE method.
  94. *
  95. * @param int $bugID
  96. * @access public
  97. * @return string
  98. */
  99. public function delete($bugID)
  100. {
  101. $control = $this->loadController('bug', 'delete');
  102. if(!$this->app->user->admin)
  103. {
  104. $bug = $this->loadModel('bug')->getByID($bugID);
  105. $projects = explode(',', "0,{$this->app->user->view->projects}");
  106. if(!in_array($bug->project, $projects)) return $this->sendError(400, 'No access to the project that the bug belongs to');
  107. }
  108. $control->delete($bugID, 'yes');
  109. $this->getData();
  110. return $this->sendSuccess(200, 'success');
  111. }
  112. }