From f1f51cdbcd108e2a5b9b68cec7128fd1ce97c9da Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Fri, 3 Jun 2016 10:31:36 +1000 Subject: [PATCH] Fixed issue: Call attempts can exist with no calls - clear them out --- admin/systemsortprocess.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/admin/systemsortprocess.php b/admin/systemsortprocess.php index 545ebca1..ecb04da9 100644 --- a/admin/systemsortprocess.php +++ b/admin/systemsortprocess.php @@ -216,6 +216,33 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin $db->StartTrans(); + + //Delete all completed call attempts with no call in them + $sql = "SELECT ca.call_attempt_id FROM call_attempt as ca + JOIN `case` as cs ON (cs.case_id = ca.case_id and cs.questionnaire_id = '$questionnaire_id') + LEFT JOIN `call` as c ON (c.call_attempt_id = ca.call_attempt_id) + WHERE ca.end < CONVERT_TZ(NOW(),'System','UTC') + AND c.call_attempt_id IS NULL"; + + $rs = $db->GetAll($sql); + + $cad = count($rs); + + if ($cad > 0) + { + foreach($rs as $r) + { + $sql = "DELETE from call_attempt + WHERE call_attempt_id = '{$r['call_attempt_id']}'"; + $db->Execute($sql); + } + print T_("Deleted") . " $cad " . T_("call attempts with no calls"); + } + else + { + print T_("No call attempts without calls"); + } + //Set all cases as unavailable $sql = "UPDATE `case` SET sortorder = NULL