fixing if-config exists check

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