Permalink
Browse files

.#0008518: database error when removing testcase from testplan

(array) cast needed
bav variable
  • Loading branch information...
fmancardi committed Dec 22, 2018
2 parents c26db69 + 1ed0d6c commit f57eb7d56d9c6d69dcb61e19148e735c8191a35c
Showing with 92 additions and 74 deletions.
  1. +1 −1 lib/functions/exec.inc.php
  2. +9 −15 lib/functions/print.inc.php
  3. +81 −57 lib/functions/testplan.class.php
  4. +1 −1 lib/plan/planAddTC.php
@@ -143,7 +143,7 @@ function write_execution(&$db,&$execSign,&$exec_data,&$issueTracker) {
$execSet[$tcversion_id] = $execution_id;
//
$tcvRelations = $tcaseMgr->getTCVRelationsRaw($tcversion_id);
$tcvRelations = (array)$tcaseMgr->getTCVRelationsRaw($tcversion_id);
if( count($tcvRelations) > 0 ) {
$itemSet = array_keys($tcvRelations);
$tcaseMgr->closeOpenTCVRelation($itemSet,LINK_TC_RELATION_CLOSED_BY_EXEC);
@@ -8,7 +8,7 @@
* @filesource print.inc.php
*
* @package TestLink
* @copyright 2007-2017, TestLink community
* @copyright 2007-2018, TestLink community
* @uses printDocument.php
*
*
@@ -1317,7 +1317,7 @@ function renderTestCaseForPrinting(&$db,&$node,&$options,$env,$context,$indentLe
if($fitem['is_image']) {
$code .= "<li>{$safeFileName}</li>";
$pathname = $repoDir . $item['file_path'];
$pathname = $repoDir . $fitem['file_path'];
list($iWidth, $iHeight, $iT, $iA) = getimagesize($pathname);
$iDim = ' width=' . $iWidth . ' height=' . $iHeight;
$code .= '<li><img ' . $iDim .
@@ -1443,15 +1443,13 @@ function renderTestCaseForPrinting(&$db,&$node,&$options,$env,$context,$indentLe
// collect REQ for TC
if ($options['requirement'])
{
$requirements = $req_mgr->get_all_for_tcase($id);
$requirements = (array)$req_mgr->get_all_for_tcase($id);
$code .= '<tr><td width="' . $cfg['firstColWidth'] . '" valign="top"><span class="label">'.
$labels['reqs'].'</span>';
$code .= '<td colspan="' . ($cfg['tableColspan']-1) . '">';
if (sizeof($requirements))
{
foreach ($requirements as $req)
{
if (sizeof($requirements)) {
foreach ($requirements as $req) {
$code .= htmlspecialchars($req['req_doc_id'] . ": " . $req['title']) . "<br />";
}
}
@@ -1469,16 +1467,12 @@ function renderTestCaseForPrinting(&$db,&$node,&$options,$env,$context,$indentLe
$code .= '<tr><td width="' . $cfg['firstColWidth'] . '" valign="top"><span class="label">'.
$labels['keywords'].':</span></td>';
$code .= '<td colspan="' . ($cfg['tableColspan']-1) . '">';
$kwSet = $tc_mgr->getKeywords($id,null,array('fields' => 'keyword_id,keywords.keyword'));
if (sizeof($kwSet))
{
foreach ($kwSet as $kw)
{
$kwSet = (array)$tc_mgr->getKeywords($id,null,array('fields' => 'keyword_id,keywords.keyword'));
if (sizeof($kwSet)) {
foreach ($kwSet as $kw) {
$code .= htmlspecialchars($kw['keyword']) . "<br />";
}
}
else
{
} else {
$code .= '&nbsp;' . $labels['none'] . '<br/>';
}
$code .= "</td></tr>\n";
@@ -1153,14 +1153,11 @@ function get_linked_and_newest_tcversions($id,$tcase_id=null)
* @param integer $id : test plan id
* @param array $items: assoc array key=tc_id value=tcversion_id
*
* @internal revisions:
* 20100725 - asimon - BUGID 3497 and hopefully also 3530
*/
function unlink_tcversions($id,&$items)
{
function unlink_tcversions($id,&$items) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
if(is_null($items))
{
if(is_null($items)) {
return;
}
@@ -1171,11 +1168,9 @@ function unlink_tcversions($id,&$items)
$platformInfo = $this->platform_mgr->getLinkedToTestplanAsMap($id);
$platformLabel = lang_get('platform');
$dummy = null;
foreach($items['items'] as $tcase_id => $elem)
{
foreach($elem as $platform_id => $tcversion_id)
{
$dummy = null;
foreach($items['items'] as $tcase_id => $elem) {
foreach($elem as $platform_id => $tcversion_id) {
$dummy[] = "(tcversion_id = {$tcversion_id} AND platform_id = {$platform_id})";
}
}
@@ -1202,23 +1197,68 @@ function unlink_tcversions($id,&$items)
$where_clause = " ( {$where_clause} ) ";
// First get the executions id if any exist
$sql = " SELECT id AS execution_id FROM {$this->tables['executions']} " .
" WHERE testplan_id = {$id} AND ${where_clause}";
$sql = " /* $debugMsg */ SELECT id AS execution_id
FROM {$this->tables['executions']}
WHERE testplan_id = {$id} AND ${where_clause}";
$exec_ids = $this->db->fetchRowsIntoMap($sql,'execution_id');
if( !is_null($exec_ids) and count($exec_ids) > 0 )
{
if( !is_null($exec_ids) and count($exec_ids) > 0 ) {
// has executions
$exec_ids = array_keys($exec_ids);
$exec_id_where= " WHERE execution_id IN (" . implode(",",$exec_ids) . ")";
$exec_id_list = implode(",",$exec_ids);
$exec_id_where= " WHERE execution_id IN ($exec_id_list)";
// Remove bugs if any exist
$sql=" DELETE FROM {$this->tables['execution_bugs']} {$exec_id_where} ";
// This will remove the bug @step level if any exists.
$sql = " /* $debugMsg */ DELETE FROM {$this->tables['execution_bugs']}
{$exec_id_where} ";
$result = $this->db->exec_query($sql);
// now remove executions
$sql=" DELETE FROM {$this->tables['executions']} " .
" WHERE testplan_id = {$id} AND ${where_clause}";
// Remove CF exec values
$sql = " /* $debugMsg */
DELETE FROM {$this->tables['cfield_execution_values']}
{$exec_id_where} ";
$result = $this->db->exec_query($sql);
// execution attachments
$dummy = " /* $debugMsg */ SELECT id FROM {$this->tables['attachments']}
WHERE fk_table = 'executions'
AND fk_id IN ({$exec_id_list}) ";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
// Work on Execution on Test Case Steps
// Attachments
$dummy = " /* $debugMsg */ SELECT id FROM {$this->tables['attachments']}
WHERE fk_table = 'execution_tcsteps'
AND fk_id IN (
SELECT id FROM {$this->tables['execution_tcsteps']}
{$exec_id_where} )";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
// Remove test case STEP executions if any exists
// execution_id is an attribute.
$sql = "/* $debugMsg */ DELETE FROM {$this->tables['execution_tcsteps']}
{$exec_id_where} ";
$result = $this->db->exec_query($sql);
// Grand Finale now remove executions
$sql = " /* $debugMsg */ DELETE FROM {$this->tables['executions']}
WHERE testplan_id = {$id} AND ${where_clause}";
$result = $this->db->exec_query($sql);
}
@@ -1228,8 +1268,7 @@ function unlink_tcversions($id,&$items)
" WHERE testplan_id={$id} AND {$where_clause} ";
$link_ids = $this->db->fetchRowsIntoMap($sql,'link_id');
$features = array_keys($link_ids);
if( count($features) == 1)
{
if( count($features) == 1) {
$features=$features[0];
}
$this->assignment_mgr->delete_by_feature_id($features);
@@ -1240,13 +1279,10 @@ function unlink_tcversions($id,&$items)
" WHERE testplan_id={$id} AND {$where_clause} ";
$result = $this->db->exec_query($sql);
foreach($items['items'] as $tcase_id => $elem)
{
foreach($elem as $platform_id => $tcversion)
{
foreach($items['items'] as $tcase_id => $elem) {
foreach($elem as $platform_id => $tcversion) {
$addInfo='';
if( isset($platformInfo[$platform_id]) )
{
if( isset($platformInfo[$platform_id]) ) {
$addInfo = ' - ' . $platformLabel . ':' . $platformInfo[$platform_id];
}
$auditMsg=TLS("audit_tc_removed_from_testplan",
@@ -1847,9 +1883,8 @@ function deleteUserRoles($id,$users=null,$opt=null)
/**
* Delete test plan and all related link to other items
*
*/
function delete($id)
{
*/
function delete($id) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
$id = intval($id);
@@ -1885,26 +1920,21 @@ function delete($id)
" WHERE execution_id IN ({$execIDSetSQL}) ";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs))
{
foreach($rs as $fik => $v)
{
deleteAttachment($db,$fik,false);
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
// execution attachments
$dummy = " SELECT id FROM {$this->tables['attachments']} " .
" WHERE fk_table = 'executions' " .
" AND fk_id IN ({$execIDSetSQL}) ";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs))
{
foreach($rs as $fik => $v)
{
deleteAttachment($db,$fik,false);
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
@@ -1918,8 +1948,7 @@ function delete($id)
$the_sql[]="DELETE FROM {$this->tables['builds']} WHERE testplan_id={$id}";
foreach($the_sql as $sql)
{
foreach($the_sql as $sql) {
$this->db->exec_query($sql);
}
@@ -7913,26 +7942,21 @@ function delete($id)
" WHERE execution_id IN ({$execIDSetSQL}) ";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs))
{
foreach($rs as $fik => $v)
{
deleteAttachment($db,$fik,false);
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
// execution attachments
$dummy = " SELECT id FROM {$this->tables['attachments']} " .
" WHERE fk_table = 'executions' " .
" AND fk_id IN ({$execIDSetSQL}) ";
$rs = $this->db->fetchRowsIntoMap($dummy,'id');
if(!is_null($rs))
{
foreach($rs as $fik => $v)
{
deleteAttachment($db,$fik,false);
if(!is_null($rs)) {
foreach($rs as $fik => $v) {
deleteAttachment($this->db,$fik,false);
}
}
@@ -65,7 +65,7 @@
switch($args->doAction) {
case 'doAddRemove':
// Remember: checkboxes exist only if are checked
$gui->itemQty = count($args->testcases2add);
$gui->itemQty = count((array)$args->testcases2add);
if( !is_null($args->testcases2add) ) {
addToTestPlan($db,$args,$gui,$tplan_mgr,$tcase_mgr);

0 comments on commit f57eb7d

Please sign in to comment.