* testcase: refactor the deleteScene method.

This commit is contained in:
liugang
2023-09-04 13:43:42 +08:00
parent 253df95277
commit 5ab508d1f1
+17 -24
View File
@@ -1519,44 +1519,37 @@ class testcase extends control
}
/**
* Delete scene.
* Delete a scene and its children.
*
* @param int $sceneId
* @param int $sceneID
* @param string $confirm
* @access public
* @return void
*/
public function deleteScene($sceneID, $confirm = 'no')
public function deleteScene(int $sceneID, string $confirm = 'no')
{
$scene = $this->dao->select('*')->from(VIEW_SCENECASE)->where('id')->eq($sceneID)->andWhere('isCase')->eq(2)->fetch();
if($confirm == 'no') return print(js::confirm(sprintf($this->lang->testcase->confirmDeleteScene,addslashes($scene->title)), $this->createLink('testcase', 'deleteScene', "sceneID=$sceneID&confirm=yes")));
$childrenCount = $this->dao->select('count(*) as count')->from(VIEW_SCENECASE)->where('parent')->eq($sceneID)->andWhere('deleted')->eq(0)->fetch('count');
if($childrenCount)
$scene = $this->testcase->getSceneByID($sceneID);
$count = $this->dao->select('COUNT(*) AS count')->from(TABLE_SCENE)->where('deleted')->eq('0')->andWhere('parent')->eq($sceneID)->fetch('count');
if($count)
{
if($confirm != "wait") return print(js::confirm(sprintf($this->lang->testcase->hasChildren), $this->createLink('testcase', 'deleteScene', "sceneID=$sceneID&confirm=wait")));
$all = $this->dao->select('id,isCase')->from(VIEW_SCENECASE)->where('path')->like($scene->path . '%')->andWhere('deleted')->eq(0)->fetchAll();
foreach($all as $v)
if($confirm != 'yes')
{
if($v->isCase == 2)
{
$this->testcase->delete(TABLE_SCENE, $v->id - CHANGEVALUE);
}
else
{
$this->testcase->delete(TABLE_CASE, $v->id);
}
$confirmURL = inlink('deleteScene', "sceneID={$sceneID}&confirm=yes");
return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$this->lang->testcase->hasChildren}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '$confirmURL'});});"));
}
$this->loadModel('action');
$scenes = $this->dao->select('id')->from(TABLE_SCENE)->where('deleted')->eq('0')->andWhere('path')->like($scene->path . '%')->fetchPairs();
$this->dao->update(TABLE_SCENE)->set('deleted')->eq('1')->where('deleted')->eq(0)->andWhere('path')->like($scene->path . '%')->exec();
foreach($scenes as $sceneID) $this->action->create('scene', $sceneID, 'deleted', '', $extra = ACTIONMODEL::CAN_UNDELETED);
}
else
{
$this->testcase->delete(TABLE_SCENE, $sceneID-CHANGEVALUE);
$this->testcase->delete(TABLE_SCENE, $sceneID);
}
echo js::reload('parent');
$locateLink = $this->session->caseList ? $this->session->caseList : inlink('browse', "productID={$scene->product}");
return $this->send(array('result' => 'success', 'load' => $locateLink));
}
/**