* Remove testcaseModel::importFromLib and its unit test.
This commit is contained in:
@@ -1288,112 +1288,6 @@ class testcaseModel extends model
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import case from Lib.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param int $libID
|
||||
* @param int $branch
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function importFromLib($productID, $libID, $branch)
|
||||
{
|
||||
$data = fixer::input('post')->get();
|
||||
|
||||
$prevModule = 0;
|
||||
$prevBranch = 0;
|
||||
foreach($data->module as $i => $module)
|
||||
{
|
||||
if($module != 'ditto') $prevModule = $module;
|
||||
if($module == 'ditto') $data->module[$i] = $prevModule;
|
||||
}
|
||||
|
||||
$caseModules = array();
|
||||
$this->loadModel('testsuite');
|
||||
if(isset($data->branch))
|
||||
{
|
||||
foreach($data->branch as $i => $branch)
|
||||
{
|
||||
if($branch != 'ditto') $prevBranch = $branch;
|
||||
if($branch == 'ditto') $data->branch[$i] = $prevBranch;
|
||||
if(!isset($caseModules[$data->branch[$i]])) $caseModules[$data->branch[$i]] = $this->testsuite->getCanImportModules($productID, $libID, $data->branch[$i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$caseModules[$branch] = $this->loadModel('testsuite')->getCanImportModules($productID, $libID, $branch);
|
||||
}
|
||||
|
||||
$libCases = $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq(0)->andWhere('id')->in($data->caseIdList)->fetchAll('id');
|
||||
$libSteps = $this->dao->select('*')->from(TABLE_CASESTEP)->where('`case`')->in($data->caseIdList)->orderBy('id')->fetchGroup('case');
|
||||
$libFiles = $this->dao->select('*')->from(TABLE_FILE)->where('objectID')->in($data->caseIdList)->andWhere('objectType')->eq('testcase')->fetchGroup('objectID', 'id');
|
||||
$imported = '';
|
||||
foreach($libCases as $libCaseID => $case)
|
||||
{
|
||||
$case->fromCaseID = $case->id;
|
||||
$case->fromCaseVersion = (int)$case->version;
|
||||
$case->product = $productID;
|
||||
if(isset($data->module[$case->id])) $case->module = $data->module[$case->id];
|
||||
if(isset($data->branch[$case->id])) $case->branch = $data->branch[$case->id];
|
||||
unset($case->id);
|
||||
|
||||
$branch = isset($case->branch) ? $case->branch : 0;
|
||||
if(empty($caseModules[$branch][$case->fromCaseID][$case->module]))
|
||||
{
|
||||
$imported .= "$case->fromCaseID,";
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->dao->insert(TABLE_CASE)->data($case)->autoCheck()->exec();
|
||||
|
||||
if(!dao::isError())
|
||||
{
|
||||
$caseID = $this->dao->lastInsertID();
|
||||
if(isset($libSteps[$libCaseID]))
|
||||
{
|
||||
foreach($libSteps[$libCaseID] as $step)
|
||||
{
|
||||
$step->case = $caseID;
|
||||
unset($step->id);
|
||||
$this->dao->insert(TABLE_CASESTEP)->data($step)->exec();
|
||||
}
|
||||
}
|
||||
|
||||
/* If under the project module, the cases is imported need linking to the project. */
|
||||
if($this->app->tab == 'project')
|
||||
{
|
||||
$lastOrder = (int)$this->dao->select('*')->from(TABLE_PROJECTCASE)->where('project')->eq($this->session->project)->orderBy('order_desc')->limit(1)->fetch('order');
|
||||
|
||||
$this->dao->insert(TABLE_PROJECTCASE)
|
||||
->set('project')->eq($this->session->project)
|
||||
->set('product')->eq($case->product)
|
||||
->set('case')->eq($caseID)
|
||||
->set('version')->eq($case->version)
|
||||
->set('order')->eq(++ $lastOrder)
|
||||
->exec();
|
||||
}
|
||||
|
||||
/* Fix bug #1518. */
|
||||
$oldFiles = zget($libFiles, $libCaseID, array());
|
||||
foreach($oldFiles as $fileID => $file)
|
||||
{
|
||||
$file->objectID = $caseID;
|
||||
$file->addedBy = $this->app->user->account;
|
||||
$file->addedDate = helper::now();
|
||||
$file->downloads = 0;
|
||||
unset($file->id);
|
||||
$this->dao->insert(TABLE_FILE)->data($file)->exec();
|
||||
}
|
||||
$this->loadModel('action')->create('case', $caseID, 'fromlib', '', $case->lib);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($imported)) return $imported;
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import cases to lib.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user