ztfsubmit.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * The host 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 Ke Zhao <zhaoke@easycorp.ltd>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class ztfSubmitEntry extends baseEntry
  13. {
  14. /**
  15. * Listen ztf task finish submit.
  16. *
  17. * @access public
  18. * @return void
  19. */
  20. public function post()
  21. {
  22. /* Check authorize. */
  23. $header = getallheaders();
  24. $token = isset($header['Authorization']) ? substr($header['Authorization'], 7) : '';
  25. if(!$token) return $this->sendError(401, 'Unauthorized');
  26. $now = helper::now();
  27. $this->dao = $this->loadModel('common')->dao;
  28. $id = $this->dao->select('id')->from(TABLE_ZAHOST)
  29. ->where('tokenSN')->eq($token)
  30. ->andWhere('tokenTime')->gt($now)->fi()
  31. ->fetch('id');
  32. if(!$id) return $this->sendError(400, 'Secret error.');
  33. $post = file_get_contents('php://input');
  34. $post = json_decode($post);
  35. $this->loadModel('testresult');
  36. if(!empty($post->task))
  37. {
  38. $post->log = !empty($post->data->log) ? $post->data->log: $post->error;
  39. $this->app->user = new stdClass;
  40. $this->app->user->account = '';
  41. if(!empty($post->data->funcResult))
  42. {
  43. $result = $this->loadModel('testtask')->parseZTFFuncResult($post->data->funcResult, "", 0, 0, 0);
  44. }
  45. else
  46. {
  47. $result = array();
  48. }
  49. unset($post->data);
  50. if(!empty($result['results'][0]))
  51. {
  52. $this->dao->update(TABLE_TESTRESULT)
  53. ->set('caseResult')->eq($result['results'][0][0]->caseResult)
  54. ->set('stepResults')->eq($result['results'][0][0]->stepResults)
  55. ->set('ZTFResult')->eq(json_encode($post))
  56. ->where('id')->eq($post->task)
  57. ->exec();
  58. }
  59. else
  60. {
  61. $this->dao->update(TABLE_TESTRESULT)
  62. ->set('ZTFResult')->eq(json_encode($post))
  63. ->set('caseResult')->eq('n/a')
  64. ->where('id')->eq($post->task)->exec();
  65. }
  66. }
  67. return $this->sendSuccess(200, 'success');
  68. }
  69. }