| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518 |
- <?php
- /**
- * The model file of release module of ZenTaoPMS.
- *
- * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
- * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
- * @author Chunsheng Wang <chunsheng@cnezsoft.com>
- * @package release
- * @version $Id: model.php 4129 2013-01-18 01:58:14Z wwccss $
- * @link https://www.zentao.net
- */
- ?>
- <?php
- class releaseModel extends model
- {
- /**
- * 通过ID获取发布信息。
- * Get release information by ID.
- *
- * @param int $releaseID
- * @param bool $setImgSize
- * @access public
- * @return object|false
- */
- public function getByID($releaseID, $setImgSize = false)
- {
- if(common::isTutorialMode()) return $this->loadModel('tutorial')->getRelease();
- $release = $this->dao->select('t1.*, t2.name as productName, t2.type as productType')
- ->from(TABLE_RELEASE)->alias('t1')
- ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
- ->where('t1.id')->eq((int)$releaseID)
- ->orderBy('t1.id DESC')
- ->fetch();
- if(!$release) return false;
- $release->builds = $this->dao->select('id, branch, filePath, scmPath, name, execution, project')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchAll();
- $release->project = trim($release->project, ',');
- $release->branch = trim($release->branch, ',');
- $release->build = trim($release->build, ',');
- $release->branches = array();
- $branchIdList = explode(',', trim($release->branch, ','));
- foreach($branchIdList as $branchID) $release->branches[$branchID] = $branchID;
- $this->loadModel('file');
- $release = $this->file->replaceImgURL($release, 'desc');
- $release->files = $this->file->getByObject('release', $releaseID);
- if(!empty($release->builds) && is_array($release->builds))
- {
- foreach($release->builds as $build) $release->files = array_merge($release->files, $this->file->getByObject('build', (int)$build->id));
- }
- if($setImgSize) $release->desc = $this->file->setImgSize($release->desc);
- $release->isInclude = false;
- if($this->app->rawMethod == 'edit')
- {
- if($this->dao->select('id')->from(TABLE_RELEASE)->where("FIND_IN_SET($releaseID, `releases`)")->fetch()) $release->isInclude = true;
- if(!$release->isInclude)
- {
- $deployID = $this->dao->select('t1.deploy')->from(TABLE_DEPLOYPRODUCT)->alias('t1')
- ->leftJoin(TABLE_DEPLOY)->alias('t2')->on('t1.deploy = t2.id')
- ->where('t1.`release`')->eq($releaseID)
- ->andWhere('t2.deleted')->eq(0)
- ->fetch();
- if($deployID) $release->isInclude = true;
- }
- }
- return $release;
- }
- /**
- * 获取发布列表。
- * Get release list.
- *
- * @param array $idList
- * @access public
- * @return array
- */
- public function getPairs($idList = array())
- {
- return $this->dao->select('id, name')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->beginIF($idList)->andWhere('id')->in($idList)->fi()
- ->fetchPairs();
- }
- /**
- * 通过条件获取发布列表信息。
- * Get release list information by condition.
- *
- * @param array $idList
- * @param int $includeRelease
- * @param bool $showRelated
- * @access public
- * @return array
- */
- public function getListByCondition($idList = array(), $includeRelease = 0, $showRelated = false)
- {
- $releases = $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->beginIF($idList)->andWhere('id')->in($idList)->fi()
- ->beginIF($includeRelease)->andWhere("FIND_IN_SET($includeRelease, `releases`)")->fi()
- ->fetchAll('id', false);
- if(!$showRelated) return $releases;
- $projectIdList = '';
- $productIdList = [];
- foreach($releases as $release)
- {
- $projectIdList .= trim($release->project, ',') . ',';
- $productIdList[$release->product] = $release->product;
- }
- $projectPairs = $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchPairs();
- $builds = $this->dao->select("t1.id, t1.name, t1.branch, t1.project, t1.execution, IF(t2.name IS NOT NULL, t2.name, '') AS projectName")
- ->from(TABLE_BUILD)->alias('t1')
- ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
- ->where("t1.product")->in($productIdList)
- ->fetchAll('id');
- if(!empty($builds))
- {
- $branches = [];
- foreach($builds as $build)
- {
- foreach(explode(',', $build->branch) as $branchID) $branches[(int)$branchID] = (int)$branchID;
- }
- $branches = $this->dao->select('id,name')->from(TABLE_BRANCH)->where('id')->in($branches)->fetchPairs('id');
- foreach($builds as $build)
- {
- $branchNames = [];
- foreach(explode(',', $build->branch) as $branchID)
- {
- $branchNames[] = isset($branches[$branchID]) ? $branches[$branchID] : $this->lang->trunk;
- }
- $build->branchName = implode(',', $branchNames);
- }
- }
- $this->loadModel('branch');
- foreach($releases as $release)
- {
- $releaseBuilds = array();
- foreach(explode(',', $release->build) as $buildID)
- {
- if(!$buildID || !isset($builds[$buildID])) continue;
- $releaseBuilds[$buildID] = $builds[$buildID];
- }
- $release->builds = $releaseBuilds;
- $branchName = array();
- foreach(explode(',', trim($release->branch, ',')) as $releaseBranch) $branchName[] = $releaseBranch === '0' ? $this->lang->branch->main : $this->branch->getByID($releaseBranch);
- $branchName = implode(',', $branchName);
- $release->branchName = empty($branchName) ? $this->lang->branch->main : $branchName;
- $release->projectName = array();
- foreach(explode(',', trim($release->project, ',')) as $projectID) $release->projectName[$projectID] = zget($projectPairs, $projectID, '');
- $release->projectName = implode(' ', $release->projectName);
- }
- return $releases;
- }
- /**
- * 获取发布列表信息。
- * Get release list information.
- *
- * @param int $productID
- * @param string $branch
- * @param string $type all|review|bySearch|normal|terminate
- * @param string $orderBy
- * @param string $releaseQuery
- * @param object $pager
- * @access public
- * @return object[]
- */
- public function getList($productID, $branch = 'all', $type = 'all', $orderBy = 't1.date_desc', $releaseQuery = '', $pager = null)
- {
- if(common::isTutorialMode()) return $this->loadModel('tutorial')->getReleases();
- $releases = $this->dao->select('t1.*, t2.name as productName, t2.type as productType')->from(TABLE_RELEASE)->alias('t1')
- ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
- ->where('t1.deleted')->eq(0)
- ->beginIF($productID)->andWhere('t1.product')->eq((int)$productID)->fi()
- ->beginIF($branch !== 'all')->andWhere("FIND_IN_SET($branch, t1.branch)")->fi()
- ->beginIF(!in_array($type, array('all', 'review', 'bySearch')))->andWhere('t1.status')->eq($type)->fi()
- ->beginIF($type == 'review')->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)")->fi()
- ->beginIF($type == 'bySearch')->andWhere($releaseQuery)->fi()
- ->orderBy($orderBy)
- ->page($pager)
- ->fetchAll('id', false);
- $projectIdList = '';
- foreach($releases as $release) $projectIdList .= trim($release->project, ',') . ',';
- $projectPairs = $this->dao->select('id,name')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchPairs();
- $builds = $this->dao->select("t1.id, t1.name, t1.branch, t1.project, t1.execution, IF(t2.name IS NOT NULL, t2.name, '') AS projectName")
- ->from(TABLE_BUILD)->alias('t1')
- ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
- ->where("t1.product")->eq($productID)
- ->fetchAll('id');
- if(!empty($builds))
- {
- $branches = [];
- foreach($builds as $build)
- {
- foreach(explode(',', $build->branch) as $branchID) $branches[(int)$branchID] = (int)$branchID;
- }
- $branches = $this->dao->select('id,name')->from(TABLE_BRANCH)->where('id')->in($branches)->fetchPairs('id');
- foreach($builds as $build)
- {
- $branchNames = [];
- foreach(explode(',', $build->branch) as $branchID)
- {
- $branchNames[] = isset($branches[$branchID]) ? $branches[$branchID] : $this->lang->trunk;
- }
- $build->branchName = implode(',', $branchNames);
- }
- }
- $this->loadModel('branch');
- foreach($releases as $release)
- {
- $releaseBuilds = array();
- foreach(explode(',', $release->build) as $buildID)
- {
- if(!$buildID || !isset($builds[$buildID])) continue;
- $releaseBuilds[] = $builds[$buildID];
- }
- $release->builds = $releaseBuilds;
- $branchName = array();
- if($release->productType != 'normal')
- {
- foreach(explode(',', trim($release->branch, ',')) as $releaseBranch) $branchName[] = $releaseBranch === '0' ? $this->lang->branch->main : $this->branch->getByID($releaseBranch);
- $branchName = implode(',', $branchName);
- }
- $release->branchName = empty($branchName) ? $this->lang->branch->main : $branchName;
- $release->projectName = array();
- foreach(explode(',', trim($release->project, ',')) as $projectID) $release->projectName[$projectID] = zget($projectPairs, $projectID, '');
- $release->projectName = implode(' ', $release->projectName);
- }
- return $releases;
- }
- /**
- * 获取产品下的最新创建的发布。
- * Get last release.
- *
- * @param int $productID
- * @param int $branch
- * @access public
- * @return object|false
- */
- public function getLast($productID, $branch = 0)
- {
- return $this->dao->select('id, name')->from(TABLE_RELEASE)
- ->where('product')->eq($productID)
- ->beginIF($branch)->andWhere('branch')->eq($branch)->fi()
- ->orderBy('id DESC')
- ->fetch();
- }
- /**
- * 获取指定应用下的所有发布。
- * Get releases by system.
- *
- * @param array $systemList
- * @param int $filterRelease
- * @access public
- * @return array
- */
- public function getListBySystem($systemList, $filterRelease = 0)
- {
- return $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->andWhere('system')->in($systemList)
- ->beginIF($filterRelease)->andWhere('id')->ne($filterRelease)->fi()
- ->orderBy('id DESC')
- ->fetchAll('id');
- }
- /**
- * 获取产品下发布的版本ID列表。
- * Get released builds from product.
- *
- * @param int $productID
- * @param string $branch
- * @access public
- * @return array
- */
- public function getReleasedBuilds($productID, $branch = 'all')
- {
- $releases = $this->dao->select('branch,shadow,build')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->andWhere('product')->eq($productID)
- ->fetchAll();
- $buildIdList = array();
- foreach($releases as $release)
- {
- if($branch != 'all' && $branch !== '')
- {
- $inBranch = false;
- foreach(explode(',', trim($release->branch, ',')) as $branchID)
- {
- if($branchID === '') continue;
- if(strpos(",{$branch},", ",{$branchID},") !== false) $inBranch = true;
- }
- if(!$inBranch) continue;
- }
- $builds = explode(',', $release->build);
- $buildIdList = array_merge($buildIdList, $builds);
- $buildIdList[] = $release->shadow;
- }
- return $buildIdList;
- }
- /**
- * 获取关联给定需求的发布。
- * Get releases by story id.
- *
- * @param int $storyID
- * @access public
- * @return array
- */
- public function getStoryReleases($storyID)
- {
- if(empty($storyID)) return array();
- return $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->andWhere("CONCAT(',', stories, ',')")->like("%,$storyID,%")
- ->orderBy('id_desc')
- ->fetchAll('id');
- }
- /**
- * 获取发布列表统计信息。
- * Get summary info of release browse page.
- *
- * @param array $releases
- * @param string $type
- * @access public
- * @return string
- */
- public function getPageSummary($releases, $type)
- {
- if($type != 'all') return sprintf($this->lang->release->pageSummary, count($releases));
- $totalNormal = 0;
- $totalTerminate = 0;
- foreach($releases as $release)
- {
- if($release->status == 'normal') $totalNormal ++;
- if($release->status == 'terminate') $totalTerminate ++;
- }
- return sprintf($this->lang->release->pageAllSummary, count($releases), $totalNormal, $totalTerminate);
- }
- /**
- * 创建一个发布。
- * Create a release.
- *
- * @param object $release
- * @param bool $isSync
- * @access public
- * @return int|false
- */
- public function create($release, $isSync)
- {
- /* Auto create shadow build. */
- if($release->name)
- {
- $shadowBuild = new stdclass();
- $shadowBuild->product = $release->product;
- $shadowBuild->branch = $release->branch;
- $shadowBuild->project = isset($release->project) ? (int)$release->project : 0;
- $shadowBuild->builds = $release->build;
- $shadowBuild->name = $release->name;
- $shadowBuild->date = $release->date;
- $shadowBuild->createdBy = $this->app->user->account;
- $shadowBuild->createdDate = helper::now();
- }
- if($release->build) $release = $this->processReleaseForCreate($release, $isSync);
- $release = $this->loadModel('file')->processImgURL($release, $this->config->release->editor->create['id'], (string)$this->post->uid);
- if($release->status == 'wait') $this->config->release->create->requiredFields = str_replace(',releasedDate', '', $this->config->release->create->requiredFields);
- if($release->status == 'normal') $this->config->release->create->requiredFields = str_replace(',date', '', $this->config->release->create->requiredFields);
- $this->dao->insert(TABLE_RELEASE)->data($release)
- ->autoCheck()
- ->batchCheck($this->config->release->create->requiredFields, 'notempty')
- ->check('name', 'unique', "`system` = '{$release->system}' AND `deleted` = '0'")
- ->checkFlow();
- if(dao::isError()) return false;
- $this->dao->exec();
- $releaseID = $this->dao->lastInsertID();
- if(isset($shadowBuild))
- {
- $this->dao->insert(TABLE_BUILD)->data($shadowBuild)->exec();
- if(dao::isError()) return false;
- $release->shadow = $this->dao->lastInsertID();
- $this->dao->update(TABLE_RELEASE)->data(array('shadow' => $release->shadow))->where('id')->eq($releaseID)->exec();
- }
- $this->file->updateObjectID($this->post->uid, $releaseID, 'release');
- $this->file->saveUpload('release', $releaseID);
- $this->loadModel('score')->create('release', 'create', $releaseID);
- /* Set stage to released. */
- if($release->stories)
- {
- $this->loadModel('story');
- $this->loadModel('action');
- $storyIdList = array_unique(array_filter(explode(',', $release->stories)));
- foreach($storyIdList as $storyID)
- {
- $storyID = (int)$storyID;
- $this->story->setStage($storyID);
- $this->action->create('story', $storyID, 'linked2release', '', $releaseID);
- }
- }
- if($release->system) $this->loadModel('system')->setSystemRelease($release->system, $releaseID, $release->createdDate);
- $this->processRelated($releaseID, $release);
- return $releaseID;
- }
- /**
- * 处理待创建的发布字段。
- * Process release fields for create.
- *
- * @param object $release
- * @param bool $isSync
- * @access public
- * @return object
- */
- public function processReleaseForCreate($release, $isSync)
- {
- $this->loadModel('story');
- $this->loadModel('bug');
- $builds = $this->dao->select('id,project,branch,builds,stories,bugs')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchAll('id');
- $linkedBuilds = array();
- foreach($builds as $build)
- {
- $build->builds = trim($build->builds, ',');
- if(empty($build->builds)) continue;
- $linkedBuilds = array_merge($linkedBuilds, explode(',', $build->builds));
- }
- if($linkedBuilds) $builds += $this->dao->select('id,project,branch,builds,stories,bugs')->from(TABLE_BUILD)->where('id')->in($linkedBuilds)->fetchAll('id');
- $branches = array();
- $projects = array();
- foreach($builds as $build)
- {
- foreach(explode(',', $build->branch) as $buildBranch)
- {
- if(!isset($branches[$buildBranch])) $branches[$buildBranch] = $buildBranch;
- }
- $projects[$build->project] = $build->project;
- if($isSync)
- {
- $build->stories = trim($build->stories, ',');
- $build->bugs = trim($build->bugs, ',');
- if($build->stories)
- {
- $release->stories .= ',' . $build->stories;
- $this->story->updateStoryReleasedDate($build->stories, $release->date);
- }
- if($build->bugs) $release->bugs .= ',' . $build->bugs;
- }
- }
- $release->build = ',' . trim($release->build, ',') . ',';
- $release->branch = ',' . trim(implode(',', $branches), ',') . ',';
- $release->project = ',' . trim(implode(',', $projects), ',') . ',';
- return $release;
- }
- /**
- * 更新一个发布。
- * Update a release.
- *
- * @param object $release
- * @param object $oldRelease
- * @access public
- * @return array|false
- */
- public function update($release, $oldRelease)
- {
- $release = $this->loadModel('file')->processImgURL($release, $this->config->release->editor->edit['id'], (string)$this->post->uid);
- /* update release project and branch */
- if($release->build)
- {
- $builds = $this->dao->select('project, branch')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchAll();
- $branches = array();
- $projects = array();
- foreach($builds as $build)
- {
- foreach(explode(',', $build->branch) as $buildBranch)
- {
- if(!isset($branches[$buildBranch])) $branches[$buildBranch] = $buildBranch;
- }
- $projects[$build->project] = $build->project;
- }
- $release->build = ',' . trim($release->build, ',') . ',';
- $release->branch = ',' . trim(implode(',', $branches), ',') . ',';
- $release->project = ',' . trim(implode(',', $projects), ',') . ',';
- }
- if($release->status == 'wait') $release->releasedDate = null;
- $this->dao->update(TABLE_RELEASE)->data($release, 'deleteFiles,renameFiles,files')
- ->autoCheck()
- ->batchCheck($this->config->release->edit->requiredFields, 'notempty')
- ->check('name', 'unique', "`id` != '{$oldRelease->id}' AND `system` = '{$release->system}' AND `deleted` = '0'")
- ->checkFlow()
- ->where('id')->eq($oldRelease->id)
- ->exec();
- if(dao::isError()) return false;
- if($oldRelease->status != $release->status && $release->status == 'normal') $this->setStoriesStage($oldRelease->id);
- $shadowBuild = array();
- if($release->name != $oldRelease->name) $shadowBuild['name'] = $release->name;
- if($release->build != $oldRelease->build) $shadowBuild['builds'] = $release->build;
- if($release->date != $oldRelease->date) $shadowBuild['date'] = $release->date;
- if($shadowBuild) $this->dao->update(TABLE_BUILD)->data($shadowBuild)->where('id')->eq($oldRelease->shadow)->exec();
- $this->file->processFileDiffsForObject('release', $oldRelease, $release);
- $this->processRelated($oldRelease->id, $release);
- $release = $this->file->replaceImgURL($release, 'desc');
- return common::createChanges($oldRelease, $release);
- }
- /**
- * 获取通知的人员。
- * Get notify persons.
- *
- * @param object $release
- * @access public
- * @return array
- */
- public function getNotifyPersons($release)
- {
- if(empty($release->notify)) return array();
- /* Get notify users. */
- $notifyPersons = array();
- $managerFields = '';
- $notifyList = explode(',', $release->notify);
- foreach($notifyList as $notify)
- {
- if($notify == 'PO' || $notify == 'QD' || $notify == 'feedback')
- {
- $managerFields .= $notify . ',';
- }
- elseif($notify == 'SC' && !empty($release->build))
- {
- $stories = implode(',', $this->dao->select('id,stories')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchPairs('id', 'stories'));
- $stories .= ',' . $this->dao->select('stories')->from(TABLE_RELEASE)->where('id')->eq($release->id)->fetch('stories');
- $stories = trim(str_replace(',,', ',', $stories), ',');
- if(empty($stories)) continue;
- $openedByList = $this->dao->select('openedBy')->from(TABLE_STORY)->where('id')->in($stories)->fetchPairs();
- $notifyPersons += $openedByList;
- }
- elseif($notify == 'ET' && !empty($release->build))
- {
- $releaseBuilds = $this->dao->select('id, builds')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchAll('id');
- $allBuilds = array_keys($releaseBuilds);
- foreach($releaseBuilds as $releaseBuild)
- {
- if(empty($releaseBuild->builds)) continue;
- $allBuilds = array_merge($allBuilds, explode(',', $releaseBuild->builds));
- }
- $members = $this->dao->select('t2.account')->from(TABLE_BUILD)->alias('t1')
- ->leftJoin(TABLE_TEAM)->alias('t2')->on('t2.root = t1.execution')
- ->where('t1.id')->in(array_filter(array_unique($allBuilds)))
- ->andWhere('t2.type')->eq('execution')
- ->fetchPairs();
- if(empty($members)) continue;
- $notifyPersons += $members;
- }
- elseif($notify == 'PT' && !empty($release->build))
- {
- $members = $this->dao->select('t2.account')->from(TABLE_RELEASE)->alias('t1')
- ->leftJoin(TABLE_TEAM)->alias('t2')->on("FIND_IN_SET(t2.root, t1.project)")
- ->where('t1.id')->eq($release->id)
- ->andWhere('t2.type')->eq('project')
- ->fetchPairs();
- if(empty($members)) continue;
- $notifyPersons += $members;
- }
- elseif($notify == 'CT' && !empty($release->mailto))
- {
- $notifyPersons += explode(',', trim($release->mailto, ','));
- }
- }
- if(empty($managerFields)) return $notifyPersons;
- $managerFields = trim($managerFields, ',');
- $managerUsers = $this->dao->select($managerFields)->from(TABLE_PRODUCT)->where('id')->eq($release->product)->fetch();
- foreach($managerUsers as $account)
- {
- if(!isset($notifyPersons[$account])) $notifyPersons[$account] = $account;
- }
- return $notifyPersons;
- }
- /**
- * 发布批量关联需求。
- * Link stories to a release.
- *
- * @param int $releaseID
- * @param array $stories
- * @access public
- * @return bool
- */
- public function linkStory($releaseID, $stories)
- {
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- foreach($stories as $i => $storyID)
- {
- if(strpos(",{$release->stories},", ",{$storyID},") !== false) unset($stories[$i]);
- }
- $this->loadModel('story')->updateStoryReleasedDate($release->stories, $release->date);
- $release->stories .= ',' . implode(',', $stories);
- $this->dao->update(TABLE_RELEASE)->set('stories')->eq($release->stories)->where('id')->eq($releaseID)->exec();
- if($release->stories)
- {
- $this->loadModel('action');
- $product = $this->loadModel('product')->getByID($release->product);
- foreach($stories as $storyID)
- {
- /* Reset story stagedBy field for auto compute stage. */
- $storyID = (int)$storyID;
- $this->dao->update(TABLE_STORY)->set('stagedBy')->eq('')->where('id')->eq($storyID)->exec();
- if($product->type != 'normal') $this->dao->update(TABLE_STORYSTAGE)->set('stagedBy')->eq('')->where('story')->eq($storyID)->andWhere('branch')->eq($release->branch)->exec();
- if($release->status == 'normal') $this->story->setStage($storyID);
- $this->action->create('story', $storyID, 'linked2release', '', $releaseID);
- }
- $this->updateRelated($releaseID, 'story', $release->stories);
- }
- return !dao::isError();
- }
- /**
- * 移除关联的需求。
- * Unlink a story.
- *
- * @param int $releaseID
- * @param int $storyID
- * @access public
- * @return bool
- */
- public function unlinkStory($releaseID, $storyID)
- {
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- $release->stories = trim(str_replace(",$storyID,", ',', ",$release->stories,"), ',');
- $this->dao->update(TABLE_RELEASE)->set('stories')->eq($release->stories)->where('id')->eq((int)$releaseID)->exec();
- $this->loadModel('action')->create('story', $storyID, 'unlinkedfromrelease', '', $releaseID);
- $this->loadModel('story')->setStage($storyID);
- $this->deleteRelated($releaseID, 'story', $storyID);
- return !dao::isError();
- }
- /**
- * 批量解除发布跟需求的关联。
- * Batch unlink story.
- *
- * @param int $releaseID
- * @param array $storyIdList
- * @access public
- * @return bool
- */
- public function batchUnlinkStory($releaseID, $storyIdList)
- {
- if(empty($storyIdList)) return true;
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- $release->stories = ",$release->stories,";
- foreach($storyIdList as $storyID) $release->stories = str_replace(",$storyID,", ',', $release->stories);
- $release->stories = trim($release->stories, ',');
- $this->dao->update(TABLE_RELEASE)->set('stories')->eq($release->stories)->where('id')->eq((int)$releaseID)->exec();
- $this->loadModel('action');
- foreach($storyIdList as $unlinkStoryID)
- {
- $unlinkStoryID = (int)$unlinkStoryID;
- $this->action->create('story', $unlinkStoryID, 'unlinkedfromrelease', '', $releaseID);
- $this->loadModel('story')->setStage($unlinkStoryID);
- }
- $this->deleteRelated($releaseID, 'story', $storyIdList);
- return !dao::isError();
- }
- /**
- *
- * 发布批量关联Bug。
- * Link bugs.
- *
- * @param int $releaseID
- * @param string $type bug|leftBug
- * @param array $bugs
- * @access public
- * @return bool
- */
- public function linkBug($releaseID, $type = 'bug', $bugs = array())
- {
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- $field = $type == 'bug' ? 'bugs' : 'leftBugs';
- foreach($bugs as $i => $bugID)
- {
- if(strpos(",{$release->$field},", ",{$bugID},") !== false) unset($bugs[$i]);
- }
- $release->$field .= ',' . implode(',', $bugs);
- $this->dao->update(TABLE_RELEASE)->set($field)->eq($release->$field)->where('id')->eq($releaseID)->exec();
- $this->loadModel('action');
- foreach($bugs as $bugID) $this->action->create('bug', (int)$bugID, 'linked2release', '', $releaseID);
- $this->updateRelated($releaseID, $type, $release->$field);
- return !dao::isError();
- }
- /**
- * 移除关联的Bug。
- * Unlink bug.
- *
- * @param int $releaseID
- * @param int $bugID
- * @param string $type bug|leftBug
- * @access public
- * @return bool
- */
- public function unlinkBug($releaseID, $bugID, $type = 'bug')
- {
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- $field = $type == 'bug' ? 'bugs' : 'leftBugs';
- $release->{$field} = trim(str_replace(",$bugID,", ',', ",{$release->$field},"), ',');
- $this->dao->update(TABLE_RELEASE)->set($field)->eq($release->$field)->where('id')->eq($releaseID)->exec();
- $this->loadModel('action')->create('bug', $bugID, 'unlinkedfromrelease', '', $releaseID);
- $this->deleteRelated($releaseID, $type, $bugID);
- return !dao::isError();
- }
- /**
- * 批量解除发布跟Bug的关联。
- * Batch unlink bug.
- *
- * @param int $releaseID
- * @param string $type bug|leftBug
- * @param array $bugIdList
- * @access public
- * @return bool
- */
- public function batchUnlinkBug($releaseID, $type = 'bug', $bugIdList = array())
- {
- if(empty($bugIdList)) return true;
- $release = $this->getByID($releaseID);
- if(!$release) return false;
- $field = $type == 'bug' ? 'bugs' : 'leftBugs';
- $release->$field = ",{$release->$field},";
- foreach($bugIdList as $bugID) $release->$field = str_replace(",$bugID,", ',', $release->$field);
- $release->$field = trim($release->$field, ',');
- $this->dao->update(TABLE_RELEASE)->set($field)->eq($release->$field)->where('id')->eq($releaseID)->exec();
- $this->loadModel('action');
- foreach($bugIdList as $unlinkBugID) $this->action->create('bug', (int)$unlinkBugID, 'unlinkedfromrelease', '', $releaseID);
- $this->deleteRelated($releaseID, $type, $bugIdList);
- return !dao::isError();
- }
- /**
- * 激活/停止维护发布。
- * Change status.
- *
- * @param int $releaseID
- * @param string $status normal|fail|terminate
- * @param string $releasedDate
- * @access public
- * @return bool
- */
- public function changeStatus($releaseID, $status, $releasedDate = '')
- {
- $this->dao->update(TABLE_RELEASE)
- ->set('status')->eq($status)
- ->beginIF($releasedDate)->set('releasedDate')->eq($releasedDate)->fi()
- ->where('id')->eq($releaseID)
- ->exec();
- if($status == 'normal') $this->setStoriesStage($releaseID);
- return !dao::isError();
- }
- /**
- * 判断按钮是否可点击。
- * Judge btn is clickable or not.
- *
- * @param object $release
- * @param string $action
- * @access public
- * @return bool
- */
- public static function isClickable($release, $action)
- {
- if(!empty($release->deleted)) return false;
- global $app;
- if($app->rawMethod == 'browse' && !empty($release->releases) && $action == 'view') return false;
- $action = strtolower($action);
- if($action == 'notify') return ($release->bugs || $release->stories) && $release->status == 'normal';
- if($action == 'play') return $release->status == 'terminate';
- if($action == 'pause') return $release->status == 'normal';
- if($action == 'publish') return $release->status == 'wait' || $release->status == 'fail';
- if(!empty($release->releases) && ($action == 'linkstory' || $action == 'linkbug')) return false;
- return true;
- }
- /**
- * 发送邮件给相关用户。
- * Send mail to release related users.
- *
- * @param int $releaseID
- * @access public
- * @return void
- */
- public function sendmail($releaseID)
- {
- if(empty($releaseID)) return;
- $this->app->loadConfig('mail');
- /* Load module and get vars. */
- $release = $this->getByID($releaseID);
- $suffix = empty($release->product) ? '' : ' - ' . $this->loadModel('product')->getByID($release->product)->name;
- $subject = 'Release #' . $release->id . ' ' . $release->name . $suffix;
- $stories = $this->dao->select('*')->from(TABLE_STORY)->where('id')->in($release->stories)->andWhere('deleted')->eq(0)->fetchAll('id');
- $bugs = $this->dao->select('*')->from(TABLE_BUG)->where('id')->in($release->bugs)->andWhere('deleted')->eq(0)->fetchAll();
- $leftBugs = $this->dao->select('*')->from(TABLE_BUG)->where('id')->in($release->leftBugs)->andWhere('deleted')->eq(0)->fetchAll();
- /* Get mail content. */
- $modulePath = $this->app->getModulePath('', 'release');
- $oldcwd = getcwd();
- $viewFile = $modulePath . 'ui/mail.html.php';
- chdir($modulePath . 'view');
- if(file_exists($modulePath . 'ext/ui/mail.html.php'))
- {
- $viewFile = $modulePath . 'ext/ui/mail.html.php';
- chdir($modulePath . 'ext/view');
- }
- ob_start();
- include $viewFile;
- foreach(glob($modulePath . 'ext/ui/mail.*.html.hook.php') as $hookFile) include $hookFile;
- $mailContent = ob_get_contents();
- ob_end_clean();
- chdir($oldcwd);
- if(strpos(",{$release->notify},", ',FB,') !== false) $this->sendMail2Feedback($release, $subject);
- /* Get the sender. */
- $sendUsers = $this->getNotifyList($release);
- if(!$sendUsers) return;
- list($toList, $ccList) = $sendUsers;
- /* Send it. */
- $this->loadModel('mail')->send($toList, $subject, $mailContent, $ccList);
- }
- /**
- * 获取发送邮件的人员。
- * Get notify list.
- *
- * @param object $release
- * @access public
- * @return false|array
- */
- public function getNotifyList($release)
- {
- /* Set toList and ccList. */
- $toList = $this->app->user->account;
- $ccList = $release->mailto . ',';
- /* Get notifiy persons. */
- $notifyPersons = array();
- if(!empty($release->notify)) $notifyPersons = $this->getNotifyPersons($release);
- foreach($notifyPersons as $account)
- {
- if(strpos($ccList, ",{$account},") === false) $ccList .= ",$account,";
- }
- $ccList = trim($ccList, ',');
- if(empty($toList))
- {
- if(empty($ccList)) return false;
- if(strpos($ccList, ',') === false)
- {
- $toList = $ccList;
- $ccList = '';
- }
- else
- {
- $commaPos = strpos($ccList, ',');
- $toList = substr($ccList, 0, $commaPos);
- $ccList = substr($ccList, $commaPos + 1);
- }
- }
- return array($toList, $ccList);
- }
- /**
- * 获取通过动作触发的邮件通知人员。
- * Get toList and ccList.
- *
- * @param object $release
- * @param string $actionType
- * @access public
- * @return bool|array
- */
- public function getToAndCcList($release, $actionType = '')
- {
- /* Set toList and ccList. */
- $toList = $release->createdBy;
- $ccList = isset($release->mailto) ? str_replace(' ', '', trim($release->mailto, ',')) : '';
- $product = $this->loadModel('product')->fetchByID($release->product);
- if($product) $ccList .= ',' . $product->PO . ',' . $product->RD;
- if(empty($toList))
- {
- if(empty($ccList)) return false;
- if(strpos($ccList, ',') === false)
- {
- $toList = $ccList;
- $ccList = '';
- }
- else
- {
- $commaPos = strpos($ccList, ',');
- $toList = substr($ccList, 0, $commaPos);
- $ccList = substr($ccList, $commaPos + 1);
- }
- }
- return array($toList, $ccList);
- }
- /**
- * 发送邮件给反馈用户。
- * Send mail to feedback user.
- *
- * @param object $release
- * @param string $subject
- * @access public
- * @return void
- */
- public function sendMail2Feedback($release, $subject)
- {
- if(!$release->stories && !$release->bugs) return;
- $stories = explode(',', trim($release->stories, ','));
- $bugs = explode(',', trim($release->bugs, ','));
- $storyNotifyList = $this->dao->select('id,title,notifyEmail')->from(TABLE_STORY)
- ->where('id')->in($stories)
- ->andWhere('notifyEmail')->ne('')
- ->fetchGroup('notifyEmail', 'id');
- $bugNotifyList = $this->dao->select('id,title,notifyEmail')->from(TABLE_BUG)
- ->where('id')->in($bugs)
- ->andWhere('notifyEmail')->ne('')
- ->fetchGroup('notifyEmail', 'id');
- /* Get notify email and object name. */
- $toList = array();
- $emails = array();
- $storyNames = array();
- $bugNames = array();
- foreach($storyNotifyList as $notifyEmail => $storyList)
- {
- $email = new stdClass();
- $email->account = $notifyEmail;
- $email->email = $notifyEmail;
- $email->realname = '';
- $emails[$notifyEmail] = $email;
- $toList[$notifyEmail] = $notifyEmail;
- foreach($storyList as $story) $storyNames[] = $story->title;
- }
- foreach($bugNotifyList as $notifyEmail => $bugList)
- {
- $email = new stdClass();
- $email->account = $notifyEmail;
- $email->email = $notifyEmail;
- $email->realname = '';
- $emails[$notifyEmail] = $email;
- $toList[$notifyEmail] = $notifyEmail;
- foreach($bugList as $bug) $bugNames[] = $bug->title;
- }
- if(empty($toList)) return;
- $storyNames = implode(',', $storyNames);
- $bugNames = implode(',', $bugNames);
- $mailContent = sprintf($this->lang->release->mailContent, $release->name);
- if($storyNames) $mailContent .= sprintf($this->lang->release->storyList, $storyNames);
- if($bugNames) $mailContent .= sprintf($this->lang->release->bugList, $bugNames);
- $this->loadModel('mail')->send(implode(',', $toList), $subject, $mailContent, '', false, $emails);
- }
- /**
- * 构造发布详情页面的操作按钮。
- * Build release view action menu.
- *
- * @param object $release
- * @access public
- * @return array
- */
- public function buildOperateViewMenu($release)
- {
- $canBeChanged = common::canBeChanged('release', $release);
- if($release->deleted || !$canBeChanged || isInModal()) return array();
- $menu = array();
- $params = "releaseID={$release->id}";
- if(common::hasPriv('release', 'changeStatus', $release))
- {
- $changedStatus = $release->status == 'normal' ? 'terminate' : 'normal';
- $menu[] = array(
- 'text' => $this->lang->release->changeStatusList[$changedStatus],
- 'icon' => $release->status == 'normal' ? 'pause' : 'play',
- 'url' => helper::createLink($this->app->rawModule, 'changeStatus', "{$params}&status={$changedStatus}"),
- 'class' => 'btn ghost ajax-submit',
- 'data-confirm' => $release->status == 'normal' ? $this->lang->release->confirmTerminate : $this->lang->release->confirmActivate
- );
- }
- if(common::hasPriv('release', 'edit'))
- {
- $menu[] = array(
- 'text' => $this->lang->edit,
- 'icon' => 'edit',
- 'url' => helper::createLink($this->app->rawModule, 'edit', $params),
- 'class' => 'btn ghost'
- );
- }
- if(common::hasPriv('release', 'delete'))
- {
- $menu[] = array(
- 'text' => $this->lang->delete,
- 'icon' => 'trash',
- 'url' => helper::createLink($this->app->rawModule, 'delete', $params),
- 'class' => 'btn ghost ajax-submit',
- 'data-confirm' => $this->lang->release->confirmDelete
- );
- }
- return $menu;
- }
- /**
- * 获取未删除的发布数量。
- * Get count of the releases.
- *
- * @param string $type all|milestone
- * @access public
- * @return int
- */
- public function getReleaseCount($type = 'all')
- {
- return $this->dao->select('COUNT(t1.id) as releaseCount')->from(TABLE_RELEASE)->alias('t1')
- ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
- ->where('t1.deleted')->eq(0)
- ->andWhere('t2.deleted')->eq(0)
- ->andWhere('t2.shadow')->eq(0)
- ->beginIF(!$this->app->user->admin)->andWhere('t1.product')->in($this->app->user->view->products)->fi()
- ->beginIF($type == 'milestone')->andWhere('t1.marker')->eq(1)->fi()
- ->fetch('releaseCount');
- }
- /**
- * 获取发布列表区块的数据。
- * Get the data for the release list block.
- *
- * @param int $projectID
- * @param string $orderBy
- * @param int $limit
- * @access public
- * @return object[]
- */
- public function getReleasesBlockData($projectID = 0, $orderBy = 'id_desc', $limit = 0)
- {
- return $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->andWhere('shadow')->eq(0)
- ->beginIF($projectID)->andWhere('project')->eq($projectID)->fi()
- ->beginIF(!$this->app->user->admin)->andWhere('product')->in($this->app->user->view->products)->fi()
- ->orderBy($orderBy)
- ->limit($limit)
- ->fetchAll();
- }
- /**
- * 获取产品下的发布列表信息。
- * Get the release list information under the product.
- *
- * @param array $productIdList
- * @access public
- * @return array
- */
- public function getGroupByProduct($productIdList = array())
- {
- return $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq(0)
- ->andWhere('status')->eq('normal')
- ->beginIF(!empty($productIdList))->andWhere('product')->in($productIdList)->fi()
- ->fetchGroup('product');
- }
- /**
- * 通过产品ID列表获取产品下近期的发布列表。
- * statisticRecentReleases
- *
- * @param array $productIdList
- * @param string $date
- * @param string $orderBy
- * @access public
- * @return object[]
- */
- public function statisticRecentReleases($productIdList, $date = '', $orderBy = 'date_asc')
- {
- return $this->dao->select('*')->from(TABLE_RELEASE)
- ->where('deleted')->eq('0')
- ->andWhere('product')->in($productIdList)
- ->beginIF($date)->andWhere('date')->lt($date)->fi()
- ->orderBy($orderBy)
- ->fetchAll('product');
- }
- /**
- * 根据发布状态和权限生成列表中操作列按钮。
- * Build table action menu for release browse page.
- *
- * @param object $release
- * @access public
- * @return array
- */
- public function buildActionList($release)
- {
- $actions = array();
- $canBeChanged = common::canBeChanged('release', $release);
- if(!$canBeChanged) return $actions;
- if(common::hasPriv('release', 'linkStory')) $actions[] = 'linkStory';
- if(common::hasPriv('release', 'linkBug')) $actions[] = 'linkBug';
- if(common::hasPriv('release', 'changeStatus')) $actions[] = $release->status == 'normal' ? 'pause' : 'play';
- if(common::hasPriv('release', 'edit')) $actions[] = 'edit';
- if(common::hasPriv('release', 'notify')) $actions[] = 'notify';
- if(common::hasPriv('release', 'delete')) $actions[] = 'delete';
- return $actions;
- }
- /**
- * 获取发布关联的需求列表。
- * Get the story list linked with the release.
- *
- * @param string $storyIdList
- * @param string $branch
- * @param string $orderBy
- * @param object $pager
- * @access public
- * @return array
- */
- public function getStoryList($storyIdList, $branch, $orderBy = '', $pager = null)
- {
- $stories = $this->dao->select("t1.*,t2.id as buildID, t2.name as buildName, IF(t1.`pri` = 0, {$this->config->maxPriValue}, t1.`pri`) as priOrder")->from(TABLE_STORY)->alias('t1')
- ->leftJoin(TABLE_BUILD)->alias('t2')->on("FIND_IN_SET(t1.id, t2.stories)")
- ->where('t1.id')->in($storyIdList)
- ->andWhere('t1.deleted')->eq(0)
- ->beginIF($orderBy)->orderBy($orderBy)->fi()
- ->fetchAll('id');
- $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story', false);
- if(!empty($pager))
- {
- $pager->recTotal = count($stories);
- $stories = array_chunk($stories, $pager->recPerPage);
- $stories = empty($stories) ? $stories : $stories[$pager->pageID - 1];
- }
- $stages = $this->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->in($storyIdList)->andWhere('branch')->in($branch)->fetchPairs('story', 'stage');
- foreach($stories as $index => $story)
- {
- if(isset($stages[$story->id])) $stories[$index]->stage = $stages[$story->id];
- }
- return $stories;
- }
- /**
- * 获取发布关联的Bug列表。
- * Get the bug list linked with the release.
- *
- * @param string $bugIdList
- * @param string $orderBy
- * @param object $pager
- * @param string $type linked|left
- * @access public
- * @return array
- */
- public function getBugList($bugIdList, $orderBy = '', $pager = null, $type = 'linked')
- {
- $bugs = array();
- if($bugIdList)
- {
- $bugs = $this->dao->select("*, IF(`severity` = 0, {$this->config->maxPriValue}, `severity`) as severityOrder")->from(TABLE_BUG)
- ->where('id')->in($bugIdList)
- ->andWhere('deleted')->eq(0)
- ->beginIF($orderBy)->orderBy($orderBy)->fi()
- ->page($pager)
- ->fetchAll();
- $this->loadModel('common')->saveQueryCondition($this->dao->get(), $type == 'linked' ? 'linkedBug' : 'leftBugs');
- }
- return $bugs;
- }
- /**
- * 删除发布。
- * Delete a release.
- *
- * @param string $table
- * @param int $releaseID
- * @access public
- * @return bool
- */
- public function delete($table, $releaseID)
- {
- $release = $this->fetchByID($releaseID);
- if(!$release) return false;
- parent::delete(TABLE_RELEASE, $releaseID);
- if($release->shadow) $this->dao->update(TABLE_BUILD)->set('deleted')->eq(1)->where('id')->eq($release->shadow)->exec();
- $builds = $this->dao->select('*')->from(TABLE_BUILD)->where('id')->in($release->build)->fetchAll();
- foreach($builds as $build)
- {
- if(empty($build->execution) && $build->createdDate == $release->createdDate) parent::delete(TABLE_BUILD, $build->id);
- }
- return !dao::isError();
- }
- /*
- * 当发布的状态变为正常时,设置需求的阶段。
- * Set the stage of the stories when the release status is normal.
- *
- * @param int $releaseID
- * @access public
- * @return void
- */
- /**
- * @param int $releaseID
- */
- public function setStoriesStage($releaseID)
- {
- $release = $this->getByID($releaseID);
- if(!$release) return;
- $storyIdList = array_unique(array_filter(explode(',', $release->stories)));
- if(empty($storyIdList)) return;
- /* Reset story stagedBy field for auto compute stage. */
- $this->dao->update(TABLE_STORY)->set('stagedBy')->eq('')->where('id')->in($storyIdList)->exec();
- $this->loadModel('story');
- foreach($storyIdList as $storyID) $this->story->setStage((int)$storyID);
- }
- /**
- * 处理发布关联的对象。
- * Process the related objects of the release.
- *
- * @param int $releaseID
- * @param object $release
- * @access public
- * @return void
- */
- public function processRelated($releaseID, $release)
- {
- if(!empty($release->project)) $this->updateRelated($releaseID, 'project', $release->project);
- if(!empty($release->build)) $this->updateRelated($releaseID, 'build', $release->build);
- if(!empty($release->branch)) $this->updateRelated($releaseID, 'branch', $release->branch);
- if(!empty($release->releases)) $this->updateRelated($releaseID, 'release', $release->releases);
- if(!empty($release->stories)) $this->updateRelated($releaseID, 'story', $release->stories);
- if(!empty($release->bugs)) $this->updateRelated($releaseID, 'bug', $release->bugs);
- if(!empty($release->leftBugs)) $this->updateRelated($releaseID, 'leftBug', $release->leftBugs);
- }
- /**
- * 更新发布关联的对象。
- * Update the related objects of the release.
- *
- * @param int $releaseID
- * @param string $objectType
- * @param int|string|array $objectIdList
- * @access public
- * @return bool
- */
- public function updateRelated($releaseID, $objectType, $objectIdList)
- {
- if(empty($objectIdList)) return false;
- if(is_int($objectIdList)) $objectIdList = [$objectIdList];
- if(is_string($objectIdList)) $objectIdList = explode(',', $objectIdList);
- if(!is_array($objectIdList)) return false;
- if(empty($objectIdList)) return false;
- $objectIdList = array_unique(array_filter($objectIdList));
- $this->dao->delete()->from(TABLE_RELEASERELATED)->where('release')->eq($releaseID)->andWhere('objectType')->eq($objectType)->exec();
- $related = new stdClass();
- $related->release = $releaseID;
- $related->objectType = $objectType;
- foreach($objectIdList as $objectID)
- {
- $related->objectID = $objectID;
- $this->dao->insert(TABLE_RELEASERELATED)->data($related)->exec();
- }
- return !dao::isError();
- }
- /**
- * 删除发布关联的对象。
- * Delete the related objects of the release.
- *
- * @param int $releaseID
- * @param string $objectType
- * @param int|string|array $objectIdList
- * @access public
- * @return bool
- */
- public function deleteRelated($releaseID, $objectType, $objectIdList)
- {
- if(empty($objectIdList)) return false;
- if(is_string($objectIdList)) $objectIdList = explode(',', $objectIdList);
- if(!is_int($objectIdList) && !is_array($releaseID)) return false;
- if(empty($objectIdList)) return false;
- if(is_array($objectIdList)) $objectIdList = array_unique(array_filter($objectIdList));
- $this->dao->delete()->from(TABLE_RELEASERELATED)->where('release')->eq($releaseID)->andWhere('objectType')->eq($objectType)->andWhere('objectID')->in($objectIdList)->exec();
- return !dao::isError();
- }
- /**
- * 处理发布列表展示数据。
- * Process release list display data.
- *
- * @param array $releaseList
- * @param array $childReleases
- * @param bool $addActionsAndBuildLink
- * @access public
- * @return array
- */
- public function processReleaseListData($releaseList, $childReleases = array(), $addActionsAndBuildLink = true)
- {
- $releases = array();
- $this->loadModel('project');
- $this->loadModel('execution');
- foreach($releaseList as $release)
- {
- $buildCount = count($release->builds);
- $release->rowID = $release->id;
- $release->rowspan = $buildCount;
- if($addActionsAndBuildLink) $release->actions = $this->buildActionList($release);
- $releases = array_merge($releases, $this->processReleaseBuilds($release, $addActionsAndBuildLink));
- if(empty($release->releases)) continue;
- foreach(explode(',', $release->releases) as $childID)
- {
- if(isset($childReleases[$childID]))
- {
- $child = clone $childReleases[$childID];
- $child = current($this->processReleaseListData(array($child)));
- $child->rowID = "{$release->id}-{$childID}";
- $child->parent = $release->id;
- $releases = array_merge($releases, $this->processReleaseBuilds($child, $addActionsAndBuildLink));
- }
- }
- }
- return $releases;
- }
- /**
- * 处理发布构建信息。
- * Process release builds.
- *
- * @param object $release
- * @param bool $addActionsAndBuildLink
- * @access public
- * @return array
- */
- public function processReleaseBuilds($release, $addActionsAndBuildLink)
- {
- $releases = array();
- if(!empty($release->builds))
- {
- foreach($release->builds as $build)
- {
- $releaseInfo = clone $release;
- if($addActionsAndBuildLink)
- {
- $moduleName = $build->execution ? 'build' : 'projectbuild';
- $canClickable = false;
- if($moduleName == 'projectbuild' && $this->project->checkPriv((int)$build->project)) $canClickable = true;
- if($moduleName == 'build' && $this->execution->checkPriv((int)$build->execution)) $canClickable = true;
- $build->link = $canClickable ? helper::createLink($moduleName, 'view', "buildID={$build->id}") : '';
- }
- $releaseInfo->build = $build;
- $releaseInfo->projectName = $build->projectName;
- $releases[] = $releaseInfo;
- }
- }
- else
- {
- $releases[] = $release;
- }
- return $releases;
- }
- }
|