Skip to content
Permalink
Browse files

fix: #0008851: Create and Link an existing keywork fails with a DB error

  • Loading branch information
fmancardi committed Jan 21, 2020
1 parent 49e820c commit 570e5e7b5c4214c90c9aeaed4aff469ea2ccd9a9
Showing with 33 additions and 22 deletions.
  1. +3 −1 lib/functions/testproject.class.php
  2. +14 −6 lib/functions/tlKeyword.class.php
  3. +16 −15 lib/keywords/keywordsEdit.php
@@ -1143,9 +1143,11 @@ public function addKeyword($testprojectID,$keyword,$notes) {
$kw->initialize(null,$testprojectID,$keyword,$notes);
$op = array('status' => tlKeyword::E_DBERROR, 'id' => -1,
'msg' => 'ko DB Error');

$op['status'] = $kw->writeToDB($this->db);
$op['id'] = $kw->dbID;

if ($op['status'] >= tl::OK) {
$op['id'] = $kw->dbID;
logAuditEvent(TLS("audit_keyword_created",$keyword),"CREATE",$op['id'],"keywords");
} else {
$op['msg'] = tlKeyword::getError($op['status']);
@@ -219,10 +219,15 @@ protected function checkKeyword(&$db) {
$this->name = trim($this->name);
$this->notes = trim($this->notes);

$result = tlKeyword::doesKeywordExist($db,$this->name,$this->testprojectID,$this->dbID);
$op = tlKeyword::doesKeywordExist($db,$this->name,$this->testprojectID,
$this->dbID);

$result = $op['status'];
$this->dbID = $op['kwID'];
if ($result >= tl::OK) {
$result = tlKeyword::checkKeywordName($this->name);
}
}

return $result;
}

@@ -337,7 +342,9 @@ static public function checkKeywordName($name)
* @return integer return tl::OK if the keyword is found, else tlKeyword::E_NAMEALREADYEXISTS
*/
static public function doesKeywordExist(&$db,$name,$tprojectID,$kwID = null) {
$result = tl::OK;

$op = array('status' => tl::OK, 'kwID' => $kwID);

$tables = tlObjectWithDB::getDBTables("keywords");

$name = $db->prepare_string(strtoupper($name));
@@ -349,10 +356,11 @@ static public function doesKeywordExist(&$db,$name,$tprojectID,$kwID = null) {
$query .= " AND id <> " .$kwID;
}

if ($db->fetchFirstRow($query)) {
$result = self::E_NAMEALREADYEXISTS;
if (($rs=$db->fetchFirstRow($query))) {
$op['status'] = self::E_NAMEALREADYEXISTS;
$op['kwID'] = $rs['id'];
}
return $result;
return $op;
}

//BEGIN interface iSerializationToXML
@@ -50,7 +50,9 @@
if($op->status == 1) {
$tpl = $op->template;
} else {
$tpl = $tplCfg->default_template;
$tpl = (property_exists($op,'template')
&& null != $op->template) ? $op->template :
$tplCfg->default_template;
$gui->user_feedback = getKeywordErrorMessage($op->status);
}

@@ -68,7 +70,7 @@
$gui->submitCode="return dialog_onSubmit($gui->dialogName)";
}

if( $setUpDialog ) {
if ($setUpDialog) {
$gui->dialogName = 'kw_dialog';
$gui->bodyOnLoad = "dialog_onLoad($gui->dialogName)";
$gui->bodyOnUnload = "dialog_onUnload($gui->dialogName)";
@@ -237,7 +239,7 @@ function do_delete(&$args,&$guiObj,&$tproject_mgr) {

/*
* initialize variables to launch user interface (smarty template)
* to get information to accomplish create task.
* to get information to accomplish create and link task.
*/
function cfl(&$argsObj,&$guiObj) {
$guiObj->submit_button_action = 'do_cfl';
@@ -252,17 +254,19 @@ function cfl(&$argsObj,&$guiObj) {
}

/*
* Creates the keyword
* Creates & Link the keyword
*/
function do_cfl(&$args,&$guiObj,&$tproject_mgr) {
$guiObj->submit_button_action = 'do_cfl';
$guiObj->submit_button_label = lang_get('btn_save');
$guiObj->submit_button_label = lang_get('btn_create_and_link');
$guiObj->main_descr = lang_get('keyword_management');
$guiObj->action_descr = lang_get('create_keyword');
$guiObj->action_descr = lang_get('create_keyword_and_link');

$op = $tproject_mgr->addKeyword($args->tproject_id,$args->keyword,$args->notes);

if( $op['status'] ) {
$ret = new stdClass();
if ($op['status'] >= tl::OK) {
$ret->template = 'keywordsView.tpl';
$tcaseMgr = new testcase($tproject_mgr->db);
$tbl = tlObject::getDBTables('nodes_hierarchy');
$sql = "SELECT parent_id FROM {$tbl['nodes_hierarchy']}
@@ -272,15 +276,11 @@ function do_cfl(&$args,&$guiObj,&$tproject_mgr) {
$tcaseMgr->addKeywords($tcase_id,$args->tcversion_id,
array($op['id']));
}

$ret = new stdClass();
$ret->template = 'keywordsView.tpl';
$ret->status = $op['status'];
return $ret;
}



/**
*
*/
@@ -289,23 +289,24 @@ function getKeywordErrorMessage($code) {
switch($code) {
case tlKeyword::E_NAMENOTALLOWED:
$msg = lang_get('keywords_char_not_allowed');
break;
break;

case tlKeyword::E_NAMELENGTH:
$msg = lang_get('empty_keyword_no');
break;
break;

case tlKeyword::E_DBERROR:
case ERROR:
$msg = lang_get('kw_update_fails');
break;
break;

case tlKeyword::E_NAMEALREADYEXISTS:
$msg = lang_get('keyword_already_exists');
break;
break;

default:
$msg = 'ok';
break;
}
return $msg;
}

0 comments on commit 570e5e7

Please sign in to comment.
You can’t perform that action at this time.