* Add build data functions for batch edit bugs.
This commit is contained in:
@@ -140,6 +140,23 @@ $config->bug->form->batchCreate['oses'] = array('required' => false, 'ty
|
||||
$config->bug->form->batchCreate['browsers'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchCreate['keywords'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
|
||||
$config->bug->form->batchEdit = array();
|
||||
$config->bug->form->batchEdit['types'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['severities'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['pris'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['titles'] = array('required' => true, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['branches'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['modules'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['plans'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['assignedTos'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['deadlines'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['os'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['browsers'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['keywords'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['resolvedBys'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['resolutions'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
$config->bug->form->batchEdit['duplicateBugs'] = array('required' => false, 'type' => 'array', 'default' => array());
|
||||
|
||||
$config->bug->form->confirm = array();
|
||||
$config->bug->form->confirm['pri'] = array('required' => false, 'type' => 'int', 'default' => 3);
|
||||
$config->bug->form->confirm['type'] = array('required' => false, 'type' => 'string', 'default' => '');
|
||||
|
||||
@@ -371,15 +371,15 @@ class bug extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量编辑bug。
|
||||
* 批量编辑 bugs。
|
||||
* Batch edit bugs.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param int|string $branch
|
||||
* @param int $productID
|
||||
* @param string $branch
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function batchEdit(int $productID = 0, int|string $branch = 0)
|
||||
public function batchEdit(int $productID = 0, string $branch = '0')
|
||||
{
|
||||
/* Set menu in product tab. */
|
||||
if($this->app->tab == 'product')
|
||||
@@ -389,6 +389,8 @@ class bug extends control
|
||||
|
||||
if($this->post->titles)
|
||||
{
|
||||
$bugs = $this->bugZen->buildBugsForBatchEdit();
|
||||
|
||||
/* Batch update the bugs. */
|
||||
$allChanges = $this->bug->batchUpdate();
|
||||
|
||||
|
||||
@@ -1963,4 +1963,112 @@ class bugZen extends bug
|
||||
$actionURL = $this->createLink('bug', 'linkBugs', "bugID={$bug->id}&bySearch=true&excludeBugs={$excludeBugs}&queryID=myQueryID", '', true);
|
||||
$this->bug->buildSearchForm($bug->product, $this->products, $queryID, $actionURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为批量编辑 bugs 构造数据。
|
||||
* Build bugs for the batch edit.
|
||||
*
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function buildBugsForBatchEdit(): array
|
||||
{
|
||||
/* Get bug ID list. */
|
||||
$bugIdList = $this->post->bugIDList ? $this->post->bugIDList : array();
|
||||
if(empty($bugIdList)) return array();
|
||||
|
||||
/* Get input data. */
|
||||
$data = form::data($this->config->bug->form->batchEdit)->get();
|
||||
|
||||
/* Get extend fields and old bugs. */
|
||||
$extendFields = $this->bug->getFlowExtendFields();
|
||||
$oldBugs = $this->bug->getByIdList($bugIdList);
|
||||
|
||||
/* Initialize variable. */
|
||||
$bugs = array();
|
||||
$now = helper::now();
|
||||
foreach($bugIdList as $bugID)
|
||||
{
|
||||
$oldBug = $oldBugs[$bugID];
|
||||
|
||||
$os = array_filter($data->os[$bugID]);
|
||||
$browsers = array_filter($data->browsers[$bugID]);
|
||||
$duplicateBug = $data->duplicateBugs[$bugID] ? $data->duplicateBugs[$bugID] : $oldBug->duplicateBug;
|
||||
|
||||
/* Init bug. */
|
||||
$bug = new stdclass();
|
||||
$bug->id = $bugID;
|
||||
$bug->lastEditedBy = $this->app->user->account;
|
||||
$bug->lastEditedDate = $now;
|
||||
$bug->type = zget($data->types, $bugID);
|
||||
$bug->severity = zget($data->severities, $bugID);
|
||||
$bug->pri = zget($data->pris, $bugID);
|
||||
$bug->title = zget($data->titles, $bugID);
|
||||
$bug->plan = zget($data->plans, $bugID, 0);
|
||||
$bug->branch = zget($data->branches, $bugID, 0);
|
||||
$bug->module = zget($data->modules, $bugID, $oldBug->module);
|
||||
$bug->assignedTo = $oldBug->status == 'closed' ? $oldBug->assignedTo : $data->assignedTos[$bugID];
|
||||
$bug->deadline = zget($data->deadlines, $bugID);
|
||||
$bug->resolvedBy = zget($data->resolvedBys, $bugID);
|
||||
$bug->keywords = zget($data->keywords, $bugID);
|
||||
$bug->os = implode(',', $os);
|
||||
$bug->browser = implode(',', $browsers);
|
||||
$bug->resolution = zget($data->resolutions, $bugID);
|
||||
$bug->duplicateBug = $bug->resolution != '' && $bug->resolution != 'duplicate' ? 0 : $duplicateBug;
|
||||
|
||||
/* Process bug. */
|
||||
$bugs[$bugID] = $this->buildDataForBatchEdit($bug, $oldBug, $extendFields);
|
||||
unset($bug);
|
||||
}
|
||||
return $bugs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为批量编辑 bug 构造数据。
|
||||
* Construct data for batch edit bugs.
|
||||
*
|
||||
* @param object $bug
|
||||
* @param object $oldBug
|
||||
* @param array $extendFields
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function buildDataForBatchEdit(object $bug, object $oldBug, array $extendFields): object
|
||||
{
|
||||
$now = helper::now();
|
||||
|
||||
/* If assignee is changes, set the assigned date. */
|
||||
if($bug->assignedTo != $oldBug->assignedTo) $bug->assignedDate = $now;
|
||||
|
||||
/* If resolution is not empty, set the confirmed. */
|
||||
if($bug->resolution != '') $bug->confirmed = 1;
|
||||
|
||||
/* If the bug is resolved, set resolved date and bug status. */
|
||||
if(($bug->resolvedBy != '' || $bug->resolution != '') && strpos(',resolved,closed,', ",{$oldBug->status},") === false)
|
||||
{
|
||||
$bug->resolvedDate = $now;
|
||||
$bug->status = 'resolved';
|
||||
}
|
||||
|
||||
/* If the bug without solver is resolved, set solver. */
|
||||
if($bug->resolution != '' && $bug->resolvedBy == '') $bug->resolvedBy = $this->app->user->account;
|
||||
|
||||
/* If the bug without assignee is resolved, set assignee and assigned date. */
|
||||
if($bug->resolution != '' && $bug->assignedTo == '')
|
||||
{
|
||||
$bug->assignedTo = $oldBug->openedBy;
|
||||
$bug->assignedDate = $now;
|
||||
}
|
||||
|
||||
/* Set extend fields. */
|
||||
foreach($extendFields as $extendField)
|
||||
{
|
||||
$bug->{$extendField->field} = $this->post->{$extendField->field}[$bugID];
|
||||
if(is_array($bug->{$extendField->field})) $bug->{$extendField->field} = implode(',', $bug->{$extendField->field});
|
||||
|
||||
$bug->{$extendField->field} = htmlSpecialString($bug->{$extendField->field});
|
||||
}
|
||||
|
||||
return $bug;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user