control.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php
  2. /**
  3. * The control file of release module 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 release
  9. * @version $Id: control.php 4178 2013-01-20 09:32:11Z wwccss $
  10. * @link https://www.zentao.net
  11. */
  12. class release extends control
  13. {
  14. /**
  15. * 公共函数,设置产品菜单及页面基础数据。
  16. * Common action, set the menu and basic data.
  17. *
  18. * @param int $productID
  19. * @param string $branch
  20. * @access public
  21. * @return void
  22. */
  23. public function commonAction($productID, $branch = '')
  24. {
  25. $this->loadModel('product')->setMenu($productID, $branch);
  26. $product = $this->product->getById($productID);
  27. if(empty($product)) $this->locate($this->createLink('product', 'create'));
  28. $products = $this->product->getPairs('all', 0, '', 'all');
  29. $this->product->checkAccess($productID, $products);
  30. $this->view->product = $product;
  31. $this->view->branch = $branch;
  32. $this->view->branches = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($product->id);
  33. }
  34. /**
  35. * 发布列表。
  36. * Browse releases.
  37. *
  38. * @param int $productID
  39. * @param string $branch
  40. * @param string $type all|normal|terminate
  41. * @param string $orderBy
  42. * @param string $param
  43. * @param int $recTotal
  44. * @param int $recPerPage
  45. * @param int $pageID
  46. * @param string $from
  47. * @param int $blockID
  48. * @access public
  49. * @return void
  50. */
  51. public function browse($productID, $branch = 'all', $type = 'all', $orderBy = 't1.date_desc', $param = '', $recTotal = 0, $recPerPage = 20, $pageID = 1, $from = 'product', $blockID = 0)
  52. {
  53. if($from === 'doc' || $from == 'ai')
  54. {
  55. $this->app->loadLang('doc');
  56. $products = $this->loadModel('product')->getPairs('nodeleted');
  57. if(empty($products)) return $this->send(array('result' => 'fail', 'message' => $this->lang->doc->tips->noProduct));
  58. if(!$productID) $productID = key($products);
  59. $this->view->products = $products;
  60. }
  61. $this->commonAction($productID, $branch);
  62. $this->app->loadClass('pager', true);
  63. $pager = new pager($recTotal, $recPerPage, $pageID);
  64. $uri = $this->app->getURI(true);
  65. $this->session->set('releaseList', $uri, 'product');
  66. $this->session->set('buildList', $uri);
  67. $showBranch = $this->view->product->type != 'normal';
  68. if(!$showBranch)
  69. {
  70. unset($this->config->release->dtable->fieldList['branch']);
  71. unset($this->config->release->search['fields']['branch']);
  72. unset($this->config->release->search['params']['branch']);
  73. }
  74. $sort = $orderBy;
  75. if(strpos($sort, 'branchName_') !== false) $sort = str_replace('branchName_', 'branch_', $sort);
  76. $queryID = $type == 'bySearch' ? (int)$param : 0;
  77. $actionURL = $this->createLink('release', 'browse', "productID={$productID}&branch={$branch}&type=bySearch&orderBy={$sort}&param=myQueryID&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID&from=$from&blockID=$blockID");
  78. $this->releaseZen->buildSearchForm($queryID, $actionURL, $this->view->product, $branch);
  79. $releaseQuery = $type == 'bySearch' ? $this->releaseZen->getSearchQuery($queryID) : '';
  80. $currentReleases = $this->release->getList($productID, $branch, $type, $sort, $releaseQuery, $pager);
  81. $children = implode(',', array_column($currentReleases, 'releases'));
  82. $childReleases = $this->release->getListByCondition(explode(',', $children), 0, true);
  83. $releases = $this->release->processReleaseListData($currentReleases, $childReleases);
  84. foreach($releases as $release)
  85. {
  86. $release->desc = str_replace('&nbsp;', ' ', strip_tags($release->desc));
  87. $release->branchName = trim($release->branchName, ',');
  88. $release->branch = trim($release->branch, ',');
  89. }
  90. $this->view->title = $this->view->product->name . $this->lang->hyphen . $this->lang->release->browse;
  91. $this->view->releases = $releases;
  92. $this->view->pageSummary = $this->release->getPageSummary($currentReleases, $type);
  93. $this->view->type = $type;
  94. $this->view->orderBy = $orderBy;
  95. $this->view->param = $param;
  96. $this->view->pager = $pager;
  97. $this->view->showBranch = $showBranch;
  98. $this->view->branchPairs = $this->loadModel('branch')->getPairs($productID);
  99. $this->view->appList = $this->loadModel('system')->getPairs();
  100. $this->view->childReleases = $childReleases;
  101. $this->view->from = $from;
  102. $this->view->blockID = $blockID;
  103. $this->view->idList = '';
  104. if($from === 'doc')
  105. {
  106. $content = $this->loadModel('doc')->getDocBlockContent($blockID);
  107. $this->view->idList = zget($content, 'idList', '');
  108. }
  109. $this->display();
  110. }
  111. /**
  112. * 创建一个发布。
  113. * Create a release.
  114. *
  115. * @param int $productID
  116. * @param string $branch
  117. * @param string $status
  118. * @access public
  119. * @return void
  120. */
  121. public function create($productID, $branch = 'all', $status = 'wait')
  122. {
  123. if(!empty($_POST))
  124. {
  125. $releaseData = $this->releaseZen->buildReleaseForCreate($productID, (int)$branch);
  126. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  127. if(!empty($_FILES['releaseFiles'])) $_FILES['files'] = $_FILES['releaseFiles'];
  128. unset($_FILES['releaseFiles']);
  129. $releaseID = $this->release->create($releaseData, $this->post->sync ? true : false);
  130. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  131. $this->loadModel('action')->create('release', $releaseID, 'opened');
  132. $result = $this->executeHooks($releaseID);
  133. $message = $result ? $result : $this->lang->saveSuccess;
  134. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $message, 'id' => $releaseID));
  135. if(isInModal()) return $this->send(array('result' => 'success', 'message' => $message, 'closeModal' => true, 'callback' => 'refreshProductBuild'));
  136. return $this->send(array('result' => 'success', 'message' => $message, 'load' => inlink('view', "releaseID={$releaseID}")));
  137. }
  138. $builds = $this->loadModel('build')->getBuildPairs(array($productID), $branch, 'notrunk|withbranch|hasproject', 0, 'execution', '', false);
  139. $releasedBuilds = $this->release->getReleasedBuilds($productID, $branch);
  140. foreach($releasedBuilds as $build) unset($builds[$build]);
  141. $this->commonAction($productID, $branch);
  142. unset($this->lang->release->statusList['fail']);
  143. unset($this->lang->release->statusList['terminate']);
  144. $this->view->title = $this->view->product->name . $this->lang->hyphen . $this->lang->release->create;
  145. $this->view->productID = $productID;
  146. $this->view->builds = $builds;
  147. $this->view->users = $this->loadModel('user')->getPairs('noclosed');
  148. $this->view->lastRelease = $this->release->getLast($productID, (int)$branch);
  149. $this->view->status = $status;
  150. $this->view->appList = $this->loadModel('system')->getList($productID);
  151. $this->display();
  152. }
  153. /**
  154. * 编辑一个发布。
  155. * Edit a release.
  156. *
  157. * @param int $releaseID
  158. * @access public
  159. * @return void
  160. */
  161. public function edit($releaseID)
  162. {
  163. $release = $this->release->getByID($releaseID);
  164. $release->files = $this->loadModel('file')->getByObject('release', $releaseID);
  165. if(!empty($_POST))
  166. {
  167. if($this->post->status == 'wait')
  168. {
  169. $this->config->release->edit->requiredFields = str_replace(',releasedDate', '', $this->config->release->edit->requiredFields);
  170. }
  171. else
  172. {
  173. $this->config->release->edit->requiredFields = str_replace(',date', '', $this->config->release->edit->requiredFields);
  174. }
  175. $releaseData = form::data(null, $releaseID)->setIF($this->post->build === false, 'build', 0)->get();
  176. $releaseData->releases = '';
  177. $system = $this->loadModel('system')->fetchByID($releaseData->system);
  178. if($system->integrated == '1')
  179. {
  180. $releases = (array)$this->post->releases;
  181. $releaseData->build = '';
  182. $releaseData->releases = trim(implode(',', array_filter($releases)), ',');
  183. if(!$releaseData->releases) dao::$errors['releases[' . key($releases) . ']'][] = sprintf($this->lang->error->notempty, $this->lang->release->name);
  184. }
  185. if(dao::isError()) return $this->sendError(dao::getError());
  186. $changes = $this->release->update($releaseData, $release);
  187. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  188. if($changes)
  189. {
  190. $actionID = $this->loadModel('action')->create('release', $releaseID, 'Edited');
  191. if(!empty($changes)) $this->action->logHistory($actionID, $changes);
  192. }
  193. $result = $this->executeHooks($releaseID);
  194. $message = $result ? $result : $this->lang->saveSuccess;
  195. return $this->send(array('result' => 'success', 'message' => $message, 'load' => inlink('view', "releaseID={$releaseID}")));
  196. }
  197. /* Get release and build. */
  198. $this->commonAction($release->product);
  199. $builds = $this->loadModel('build')->getBuildPairs(array($release->product), $release->branch, 'notrunk|withbranch|hasproject', 0, 'project', $release->build, false);
  200. $releasedBuilds = $this->release->getReleasedBuilds($release->product);
  201. foreach($releasedBuilds as $releasedBuild)
  202. {
  203. if(strpos(',' . trim($release->build, ',') . ',', ",{$releasedBuild},") === false) unset($builds[$releasedBuild]);
  204. }
  205. $appList = $this->loadModel('system')->getList($release->product);
  206. if($release->system && !isset($appList[$release->system])) $appList[$release->system] = $this->system->fetchByID($release->system);
  207. $this->view->title = $this->view->product->name . $this->lang->hyphen . $this->lang->release->edit;
  208. $this->view->release = $release;
  209. $this->view->builds = $builds;
  210. $this->view->users = $this->loadModel('user')->getPairs('noclosed');
  211. $this->view->appList = $appList;
  212. $this->display();
  213. }
  214. /**
  215. * 查看一个发布。
  216. * View a release.
  217. *
  218. * @param int $releaseID
  219. * @param string $type story|bug|leftBug
  220. * @param string $link
  221. * @param string $param
  222. * @param string $orderBy
  223. * @param int $recTotal
  224. * @param int $recPerPage
  225. * @param int $pageID
  226. * @access public
  227. * @return void
  228. */
  229. public function view($releaseID, $type = 'story', $link = 'false', $param = '', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 100, $pageID = 1)
  230. {
  231. $release = $this->release->getByID($releaseID, true);
  232. if(!$release) return $this->sendError($this->lang->notFound, $this->createLink('product', 'index'));
  233. $uri = $this->app->getURI(true);
  234. if(!empty($release->build)) $this->session->set('buildList', $uri, 'project');
  235. if($type == 'story') $this->session->set('storyList', $uri, 'product');
  236. if($type == 'bug' || $type == 'leftBug') $this->session->set('bugList', $uri, 'qa');
  237. /* Load pager. */
  238. $this->app->loadClass('pager', true);
  239. if($this->app->getViewType() == 'mhtml') $recPerPage = 10;
  240. $sort = common::appendOrder($orderBy);
  241. if(strpos($sort, 'pri_') !== false) $sort = str_replace('pri_', 'priOrder_', $sort);
  242. $sort .= ',buildID_asc';
  243. $storyPager = new pager($type == 'story' ? $recTotal : 0, $recPerPage, $type == 'story' ? $pageID : 1);
  244. $bugPager = new pager($type == 'bug' ? $recTotal : 0, $recPerPage, $type == 'bug' ? $pageID : 1);
  245. $leftBugPager = new pager($type == 'leftBug' ? $recTotal : 0, $recPerPage, $type == 'leftBug' ? $pageID : 1);
  246. $this->releaseZen->assignVarsForView($release, $type, $link, $param, $orderBy, $storyPager, $bugPager, $leftBugPager);
  247. $this->commonAction($release->product);
  248. if($this->app->tab == 'project')
  249. {
  250. $projectID = (int)$this->session->project;
  251. $this->loadModel('project')->setMenu($projectID);
  252. $this->view->project = $this->project->getByID($projectID);
  253. }
  254. $this->executeHooks($releaseID);
  255. $this->view->appList = $this->loadModel('system')->getPairs();
  256. $this->view->linkedReleases = $release->releases ? $this->release->getListByCondition(explode(',', $release->releases)) : array();
  257. $this->view->includedApps = $this->release->getListByCondition(array(), $release->id);
  258. $this->display();
  259. }
  260. /**
  261. * Notify for release.
  262. *
  263. * @param int $releaseID
  264. * @access public
  265. * @return void
  266. * @param int $projectID
  267. */
  268. public function notify($releaseID, $projectID = 0)
  269. {
  270. if(strtolower($this->server->request_method) == "post")
  271. {
  272. if(isset($_POST['notify']))
  273. {
  274. $notify = implode(',', $this->post->notify);
  275. $this->dao->update(TABLE_RELEASE)->set('notify')->eq($notify)->where('id')->eq($releaseID)->exec();
  276. $this->release->sendmail($releaseID);
  277. $this->loadModel('action')->create('release', $releaseID, 'notified');
  278. }
  279. $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  280. }
  281. if($this->app->tab == 'project' && $projectID != 0)
  282. {
  283. $project = $this->loadModel('project')->getByID($this->session->project);
  284. if(!$project->hasProduct)
  285. {
  286. unset($this->lang->release->notifyList['FB']);
  287. unset($this->lang->release->notifyList['PO']);
  288. unset($this->lang->release->notifyList['QD']);
  289. }
  290. if(!$project->multiple) unset($this->lang->release->notifyList['ET']);
  291. }
  292. $this->view->release = $this->release->getById($releaseID);
  293. $this->view->actions = $this->loadModel('action')->getList('release', $releaseID);
  294. $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed');
  295. $this->display();
  296. }
  297. /**
  298. * 删除发布。
  299. * Delete a release.
  300. *
  301. * @param int $releaseID
  302. * @access public
  303. * @return void
  304. */
  305. public function delete($releaseID)
  306. {
  307. $release = $this->release->fetchByID($releaseID);
  308. $this->release->delete(TABLE_RELEASE, $releaseID);
  309. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  310. if($release && $release->system) $this->loadModel('system')->setSystemRelease($release->system, $releaseID);
  311. $message = $this->executeHooks($releaseID) ?: $this->lang->saveSuccess;
  312. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $message));
  313. $locate = $this->session->releaseList ? $this->session->releaseList : $this->createLink($this->app->rawModule, 'browse', "productID={$release->product}");
  314. return $this->send(array('result' => 'success', 'load' => $locate));
  315. }
  316. /**
  317. * 导出需求列表和Bug列表。
  318. * Export story list and bug list.
  319. *
  320. * @param int $releaseID
  321. * @access public
  322. * @return void
  323. */
  324. public function export($releaseID)
  325. {
  326. if(!empty($_POST))
  327. {
  328. $release = $this->release->getByID($releaseID, true);
  329. $type = $this->post->type;
  330. $fileName = $this->post->fileName;
  331. if(empty($fileName)) return $this->sendError(sprintf($this->lang->error->notempty, $this->lang->release->fileName));
  332. $html = '';
  333. if($type == 'story' || $type == 'all') $html .= $this->releaseZen->buildStoryDataForExport($release);
  334. if($type == 'bug' || $type == 'all') $html .= $this->releaseZen->buildBugDataForExport($release, 'bug');
  335. if($type == 'leftbug' || $type == 'all') $html .= $this->releaseZen->buildBugDataForExport($release, 'leftbug');
  336. $html = "<html><head><meta charset='utf-8'><title>{$fileName}</title><style>table, th, td{font-size:12px; border:1px solid gray; border-collapse:collapse;}</style></head><body>$html</body></html>";
  337. $this->loadModel('file')->sendDownHeader($fileName, 'html', $html);
  338. }
  339. $this->display();
  340. }
  341. /**
  342. * 关联需求。
  343. * Link stories
  344. *
  345. * @param int $releaseID
  346. * @param string $browseType
  347. * @param int $param
  348. * @param int $recTotal
  349. * @param int $recPerPage
  350. * @param int $pageID
  351. * @access public
  352. * @return void
  353. */
  354. public function linkStory($releaseID = 0, $browseType = '', $param = 0, $recTotal = 0, $recPerPage = 100, $pageID = 1)
  355. {
  356. if(!empty($_POST['stories']))
  357. {
  358. $this->release->linkStory($releaseID, $this->post->stories);
  359. if(dao::isError()) return $this->sendError(dao::getError());
  360. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type=story"), 'closeModal' => true));
  361. }
  362. $this->loadModel('story');
  363. $this->session->set('storyList', $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type=story&link=true&param=" . helper::safe64Encode("&browseType=$browseType&queryID=$param")), 'product');
  364. $release = $this->release->getByID($releaseID);
  365. $this->commonAction($release->product);
  366. $queryID = ($browseType == 'bySearch') ? (int)$param : 0;
  367. $this->releaseZen->buildLinkStorySearchForm($release, $queryID);
  368. $builds = $this->loadModel('build')->getByList(explode(',', $release->build));
  369. $executionIdList = array();
  370. foreach($builds as $build)
  371. {
  372. if(!empty($build->execution)) $executionIdList[$build->execution] = (int)$build->execution;
  373. if(empty($build->execution) && !empty($build->project)) $executionIdList[$build->project] = (int)$build->project;
  374. }
  375. /* Load pager. */
  376. $this->app->loadClass('pager', true);
  377. $pager = new pager($recTotal, $recPerPage, $pageID);
  378. $excludeStoryIdList = $this->releaseZen->getExcludeStoryIdList($release);
  379. if($browseType == 'bySearch')
  380. {
  381. $allStories = $this->story->getBySearch($release->product, $release->branch, $queryID, 'id_desc', $executionIdList, 'story', $excludeStoryIdList, 'draft,reviewing,changing', $pager);
  382. }
  383. else
  384. {
  385. $allStories = $this->story->batchGetExecutionStories(implode(',', $executionIdList), $release->product, 't1.`order`_desc', 'byBranch', $release->branch, 'story', $excludeStoryIdList, $pager);
  386. }
  387. $this->view->allStories = $allStories;
  388. $this->view->release = $release;
  389. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  390. $this->view->browseType = $browseType;
  391. $this->view->param = $param;
  392. $this->view->grades = $this->loadModel('story')->getGradePairs('story', 'all');
  393. $this->view->showGrade = $this->config->edition == 'ipd';
  394. $this->view->pager = $pager;
  395. if($this->app->tab == 'project') $this->view->projectID = $release->project;
  396. $this->display();
  397. }
  398. /**
  399. * 移除关联的需求。
  400. * Unlink a story.
  401. *
  402. * @param int $releaseID
  403. * @param int $storyID
  404. * @access public
  405. * @return void
  406. */
  407. public function unlinkStory($releaseID, $storyID)
  408. {
  409. $this->release->unlinkStory($releaseID, $storyID);
  410. if(dao::isError()) return $this->sendError(dao::getError());
  411. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID=$releaseID&type=story")));
  412. }
  413. /**
  414. * 批量解除发布跟需求的关联。
  415. * Batch unlink story.
  416. *
  417. * @param int $releaseID
  418. * @access public
  419. * @return void
  420. */
  421. public function batchUnlinkStory($releaseID)
  422. {
  423. $this->release->batchUnlinkStory($releaseID, (array)$this->post->storyIdList);
  424. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type=story")));
  425. }
  426. /**
  427. * 发布批量关联Bug。
  428. * Link bugs.
  429. *
  430. * @param int $releaseID
  431. * @param string $browseType bug|leftBug|bySearch
  432. * @param int $param
  433. * @param string $type bug|leftBug
  434. * @param int $recTotal
  435. * @param int $recPerPage
  436. * @param int $pageID
  437. * @access public
  438. * @return void
  439. */
  440. public function linkBug($releaseID = 0, $browseType = '', $param = 0, $type = 'bug', $recTotal = 0, $recPerPage = 100, $pageID = 1)
  441. {
  442. if(!empty($_POST['bugs']))
  443. {
  444. $this->release->linkBug($releaseID, $type, (array)$this->post->bugs);
  445. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type={$type}")));
  446. }
  447. $this->session->set('bugList', $this->createLink($this->app->rawModule, 'view', "releaseID=$releaseID&type=$type&link=true&param=" . helper::safe64Encode("&browseType=$browseType&queryID=$param")), 'qa');
  448. /* Set menu. */
  449. $this->loadModel('bug');
  450. $release = $this->release->getByID($releaseID);
  451. $this->commonAction($release->product);
  452. /* Build the search form. */
  453. $queryID = $browseType == 'bySearch' ? (int)$param : 0;
  454. $this->releaseZen->buildLinkBugSearchForm($release, $queryID, $type);
  455. /* Load pager. */
  456. $this->app->loadClass('pager', true);
  457. $pager = new pager($recTotal, $recPerPage, $pageID);
  458. $builds = $this->loadModel('build')->getByList(explode(',', $release->build));
  459. $allBugs = array();
  460. $releaseBugs = $type == 'bug' ? $release->bugs : $release->leftBugs;
  461. if($browseType == 'bySearch')
  462. {
  463. $allBugs = $this->bug->getBySearch('bug', $release->product, $release->branch, 0, 0 , $queryID, $releaseBugs, 'id_desc', $pager);
  464. }
  465. else
  466. {
  467. $functionName = $type == 'bug' ? 'getReleaseBugs' : 'getProductLeftBugs';
  468. $allBugs = $this->bug->$functionName(array_keys($builds), $release->product, $release->branch, $releaseBugs, $pager);
  469. }
  470. $this->view->allBugs = $allBugs;
  471. $this->view->releaseBugs = empty($releaseBugs) ? array() : $this->bug->getByIdList($releaseBugs);
  472. $this->view->release = $release;
  473. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  474. $this->view->browseType = $browseType;
  475. $this->view->param = $param;
  476. $this->view->type = $type;
  477. $this->view->pager = $pager;
  478. if($this->app->tab == 'project') $this->view->projectID = $release->project;
  479. $this->display();
  480. }
  481. /**
  482. * 移除关联的Bug。
  483. * Unlink linked bug.
  484. *
  485. * @param int $releaseID
  486. * @param int $bugID
  487. * @param string $type
  488. * @access public
  489. * @return void
  490. */
  491. public function unlinkBug($releaseID, $bugID, $type = 'bug')
  492. {
  493. $this->release->unlinkBug($releaseID, $bugID, $type);
  494. /* if ajax request, send result. */
  495. if(dao::isError())
  496. {
  497. $response['result'] = 'fail';
  498. $response['message'] = dao::getError();
  499. }
  500. else
  501. {
  502. $response['result'] = 'success';
  503. $response['message'] = '';
  504. $response['load'] = $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type={$type}");
  505. }
  506. return $this->send($response);
  507. }
  508. /**
  509. * 批量解除发布跟Bug的关联。
  510. * Batch unlink story.
  511. *
  512. * @param int $releaseID
  513. * @param string $type bug|leftBug
  514. * @access public
  515. * @return void
  516. */
  517. public function batchUnlinkBug($releaseID, $type = 'bug')
  518. {
  519. $this->release->batchUnlinkBug($releaseID, $type, (array)$this->post->bugIdList);
  520. return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type={$type}")));
  521. }
  522. /**
  523. * 发布页面。
  524. * Publish page.
  525. *
  526. * @param int $releaseID
  527. * @access public
  528. * @return void
  529. */
  530. public function publish($releaseID)
  531. {
  532. $release = $this->release->getByID($releaseID);
  533. if($_POST)
  534. {
  535. if(!$this->post->releasedDate)
  536. {
  537. dao::$errors['releasedDate'] = sprintf($this->lang->error->notempty, $this->lang->release->releasedDate);
  538. return $this->sendError(dao::getError());
  539. }
  540. $this->release->changeStatus($releaseID, $this->post->status, $this->post->releasedDate);
  541. if(dao::isError()) return $this->sendError(dao::getError());
  542. $this->loadModel('action')->create('release', $releaseID, 'published', $this->post->comment, $this->post->status);
  543. return $this->sendSuccess(array('load' => true, 'closeModal' => true));
  544. }
  545. $this->view->release = $release;
  546. $this->display();
  547. }
  548. /**
  549. * 激活/停止维护发布。
  550. * Change status.
  551. *
  552. * @param int $releaseID
  553. * @param string $action play|pause
  554. * @access public
  555. * @return void
  556. */
  557. public function changeStatus($releaseID, $action)
  558. {
  559. $status = 'normal';
  560. if($action == 'pause') $status = 'terminate';
  561. if($action == 'active')
  562. {
  563. $hasOld = false;
  564. $actions = $this->loadModel('action')->getList('release', $releaseID);
  565. foreach(array_reverse($actions) as $releaseAction)
  566. {
  567. foreach($releaseAction->history as $history)
  568. {
  569. if($history->field == 'status')
  570. {
  571. $status = $history->old;
  572. $hasOld = true;
  573. break;
  574. }
  575. }
  576. if($hasOld) break;
  577. }
  578. }
  579. $this->release->changeStatus($releaseID, $status);
  580. if(dao::isError()) return $this->sendError(dao::getError());
  581. $this->loadModel('action')->create('release', $releaseID, 'changestatus', '', $action);
  582. return $this->sendSuccess(array('load' => true));
  583. }
  584. /**
  585. * 获取生成应用和发布的联动组件。
  586. * Get system and release combobox.
  587. *
  588. * @param int $systemID
  589. * @param string $linkedRelease
  590. * @param int $releaseID
  591. * @access public
  592. * @return void
  593. */
  594. public function ajaxLoadSystemBlock($systemID, $linkedRelease = '', $releaseID = 0)
  595. {
  596. $system = $this->loadModel('system')->fetchByID($systemID);
  597. $children = explode(',', $system->children);
  598. $appList = $this->system->getByIdList($children);
  599. $releases = $this->release->getListBySystem($children, $releaseID);
  600. $this->view->appList = $appList;
  601. $this->view->releases = $releases;
  602. $this->view->linkedRelease = $linkedRelease ? explode(',', $linkedRelease) : array();
  603. $this->display();
  604. }
  605. }