fix: Added more safety checking into create_state_index() so we do not end up with stale state names but no translation (#6516)

This commit is contained in:
Neil Lathwood
2017-04-28 04:33:56 +01:00
committed by Tony Murray
parent 153f0de12f
commit d67d62eacb

View File

@ -1650,9 +1650,16 @@ function rrdtest($path, &$stdOutput, &$stdError)
function create_state_index($state_name)
{
if (dbFetchRow('SELECT * FROM state_indexes WHERE state_name = ?', array($state_name)) != true) {
$state_index_id = dbFetchCell('SELECT `state_index_id` FROM state_indexes WHERE state_name = ? LIMIT 1', array($state_name));
if (!is_numeric($state_index_id)) {
$insert = array('state_name' => $state_name);
return dbInsert($insert, 'state_indexes');
} else {
$translations = dbFetchRows('SELECT * FROM `state_translations` WHERE `state_index_id` = ?', array($state_index_id));
if (count($translations) === 0) {
// If we don't have any translations something has gone wrong so return the state_index_id so they get created.
return $state_index_id;
}
}
}