diff --git a/module/testcase/control.php b/module/testcase/control.php index 5dacaa8585..f8b92e0efd 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1982,7 +1982,13 @@ class testcase extends control /* Record the ID of the parent scene, so that the parent scene will be selected by default when creating a scene next time. */ helper::setcookie('lastCaseScene', (int)$this->post->parent); - $this->testcase->createScene(); + $scene = form::data($this->config->testcase->form->createScene) + ->add('openedBy', $this->app->user->account) + ->add('openedDate', helper::now()) + ->cleanInt('product,module,branch,parent') + ->get(); + + $this->testcase->createScene($scene); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $useSession = $this->app->tab != 'qa' && $this->session->caseList && strpos($this->session->caseList, 'dynamic') === false; diff --git a/module/testcase/model.php b/module/testcase/model.php index 9475af119e..20843b8954 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -2723,14 +2723,8 @@ class testcaseModel extends model * @access public * @return bool */ - public function createScene(): bool + public function createScene(object $scene): bool { - $scene = fixer::input('post') - ->add('openedBy', $this->app->user->account) - ->add('openedDate', helper::now()) - ->cleanInt('product,module,branch,parent') - ->get(); - $this->dao->insert(TABLE_SCENE)->data($scene) ->autoCheck() ->batchCheck($this->config->testcase->createscene->requiredFields, 'notempty') @@ -2740,20 +2734,21 @@ class testcaseModel extends model if(dao::isError()) return false; $sceneID = $this->dao->lastInsertID(); + + $scene->path = ',' . $sceneID . ','; + $scene->grade = 1; + if($scene->parent) { $parent = $this->getSceneByID($scene->parent); - - $scene->path = $parent->path . $sceneID . ','; - $scene->grade = ++$parent->grade; - $scene->product = $parent->product; - $scene->branch = $parent->branch; - $scene->module = $parent->module; - } - else - { - $scene->path = ',' . $sceneID . ','; - $scene->grade = 1; + if($parent) + { + $scene->path = $parent->path . $sceneID . ','; + $scene->grade = ++$parent->grade; + $scene->product = $parent->product; + $scene->branch = $parent->branch; + $scene->module = $parent->module; + } } $this->dao->update(TABLE_SCENE)->data($scene)->where('id')->eq($sceneID)->exec();