2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Fixed bug: Error inserting case due to token random generation collision

Dev: Update to mt_rand function
Dev: Multiple tries on failure to generate unique token
This commit is contained in:
Adam Zammit
2015-11-26 21:07:30 +11:00
parent bf592f527b
commit 5b7f03761f

View File

@@ -57,9 +57,9 @@ function sRandomChars($length = 15,$pattern="23456789abcdefghijkmnpqrstuvwxyz")
for($i=0;$i<$length;$i++)
{
if(isset($key))
$key .= $pattern{rand(0,$patternlength)};
$key .= $pattern{mt_rand(0,$patternlength)};
else
$key = $pattern{rand(0,$patternlength)};
$key = $pattern{mt_rand(0,$patternlength)};
}
return $key;
}
@@ -354,8 +354,19 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
{
global $db;
$ttries = 0;
do {
$token = sRandomChars();
$sql = "SELECT count(*) as c
FROM `case`
WHERE token = '$token'";
$ttries++;
} while ($db->GetOne($sql) > 0 && $ttries < 10);
$sql = "INSERT INTO `case` (case_id, sample_id, questionnaire_id, last_call_id, current_operator_id, current_call_id, current_outcome_id,token)
VALUES (NULL, $sample_id, $questionnaire_id, NULL, $operator_id, NULL, '$current_outcome_id','$token')";
@@ -716,6 +727,7 @@ function get_case_id($operator_id, $create = false)
}
$r2 = $db->GetRow($sql);
if (empty($r2))
{