fixing if-config exists check

This commit is contained in:
Pepijn Over 2014-04-15 22:06:04 +02:00
parent a3cad31754
commit 110c42ed5d
1 changed files with 10 additions and 7 deletions

View File

@ -163,13 +163,10 @@ function psm_load_conf() {
function psm_update_conf($key, $value) {
global $db;
$result = $db->save(
PSM_DB_PREFIX.'config',
array('value' => $value),
array('key' => $key)
);
// save returns the # rows updated, if 0, key doenst exist yet
if($result === 0) {
// check if key exists
$exists = psm_get_conf($key, false);
if($exists === false) {
// add new config record
$db->save(
PSM_DB_PREFIX . 'config',
array(
@ -177,6 +174,12 @@ function psm_update_conf($key, $value) {
'value' => $value,
)
);
} else {
$db->save(
PSM_DB_PREFIX.'config',
array('value' => $value),
array('key' => $key)
);
}
$GLOBALS['sm_config'][$key] = $value;
}