* Refactor the edit function.
This commit is contained in:
@@ -5,6 +5,11 @@ $config->caselib->form->create = array();
|
||||
$config->caselib->form->create['name'] = array('type' => 'string', 'control' => 'text', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->caselib->form->create['desc'] = array('type' => 'string', 'control' => 'editor', 'required' => false, 'default' => '', 'width' => 'full');
|
||||
|
||||
$config->caselib->form->edit = array();
|
||||
$config->caselib->form->edit['name'] = array('type' => 'string', 'control' => 'text', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->caselib->form->edit['desc'] = array('type' => 'string', 'control' => 'editor', 'required' => false, 'default' => '', 'width' => 'full');
|
||||
$config->caselib->form->edit['uid'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
|
||||
global $app, $lang;
|
||||
$app->loadLang('testcase');
|
||||
$app->loadModuleConfig('testcase');
|
||||
|
||||
@@ -61,24 +61,22 @@ class caselib extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用例库。
|
||||
* Edit a case lib.
|
||||
*
|
||||
* @param int $lib
|
||||
* @param int $libID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function edit($libID)
|
||||
public function edit(int $libID)
|
||||
{
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$changes = $this->caselib->update($libID);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
$formData = form::data($this->config->caselib->form->edit);
|
||||
$lib = $this->caselibZen->prepareEditExtras($formData, $libID);
|
||||
|
||||
if($changes)
|
||||
{
|
||||
$actionID = $this->loadModel('action')->create('caselib', $libID, 'edited');
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
}
|
||||
$this->caselib->update($lib);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$message = $this->executeHooks($libID);
|
||||
if(!$message) $message = $this->lang->saveSuccess;
|
||||
@@ -93,7 +91,7 @@ class caselib extends control
|
||||
$this->caselib->setLibMenu($libraries, $libID);
|
||||
|
||||
$this->view->title = $libraries[$libID] . $this->lang->colon . $this->lang->caselib->edit;
|
||||
$this->view->lib = $this->caselib->getById($libID);
|
||||
$this->view->lib = $this->caselib->getByID($libID);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
||||
+19
-20
@@ -71,36 +71,35 @@ class caselibModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用例库。
|
||||
* Update a caselib.
|
||||
*
|
||||
* @param int $libID
|
||||
* @param object $lib
|
||||
* @access public
|
||||
* @return bool|array
|
||||
* @return bool
|
||||
*/
|
||||
public function update($libID)
|
||||
public function update(object $lib): bool
|
||||
{
|
||||
$oldLib = $this->dao->select("*")->from(TABLE_TESTSUITE)->where('id')->eq((int)$libID)->fetch();
|
||||
$lib = fixer::input('post')
|
||||
->stripTags($this->config->caselib->editor->edit['id'], $this->config->allowedTags)
|
||||
->add('id', $libID)
|
||||
->add('lastEditedBy', $this->app->user->account)
|
||||
->add('lastEditedDate', helper::now())
|
||||
->remove('uid')
|
||||
->get();
|
||||
$lib = $this->loadModel('file')->processImgURL($lib, $this->config->caselib->editor->edit['id'], $this->post->uid);
|
||||
$this->dao->update(TABLE_TESTSUITE)->data($lib)
|
||||
$oldLib = $this->dao->select('*')->from(TABLE_TESTSUITE)->where('id')->eq($lib->id)->fetch();
|
||||
|
||||
$this->dao->update(TABLE_TESTSUITE)->data($lib, $skip = 'uid')
|
||||
->autoCheck()
|
||||
->batchcheck($this->config->caselib->edit->requiredFields, 'notempty')
|
||||
->checkFlow()
|
||||
->where('id')->eq($libID)
|
||||
->where('id')->eq($lib->id)
|
||||
->checkFlow()
|
||||
->exec();
|
||||
if(!dao::isError())
|
||||
{
|
||||
$this->file->updateObjectID($this->post->uid, $libID, 'caselib');
|
||||
return common::createChanges($oldLib, $lib);
|
||||
}
|
||||
return false;
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$this->loadModel('file')->updateObjectID($lib->uid, $lib->id, 'caselib');
|
||||
|
||||
$changes = common::createChanges($oldLib, $lib);
|
||||
if(!$changes) return true;
|
||||
|
||||
$actionID = $this->loadModel('action')->create('caselib', $lib->id, 'edited');
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -188,4 +188,24 @@ class caselibZen extends caselib
|
||||
|
||||
return $testcases;
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备编辑用例库的数据。
|
||||
* Prepare data for edit caselib.
|
||||
*
|
||||
* @param object $formData
|
||||
* @param int $libID
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function prepareEditExtras(object $formData, int $libID): object
|
||||
{
|
||||
$lib = $formData->add('id', $libID)
|
||||
->add('lastEditedBy', $this->app->user->account)
|
||||
->add('lastEditedDate', helper::now())
|
||||
->stripTags($this->config->caselib->editor->edit['id'], $this->config->allowedTags)
|
||||
->get();
|
||||
|
||||
return $this->loadModel('file')->processImgURL($lib, $this->config->caselib->editor->edit['id'], $lib->uid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user