Add instead of replacing when updating motheure::increment

This commit is contained in:
xdrm-brackets 2017-10-13 19:43:39 +02:00
parent dad2125544
commit eb7f94dce9
1 changed files with 8 additions and 6 deletions

View File

@ -85,12 +85,17 @@
/* (1) Check if entry exists /* (1) Check if entry exists
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Check if there is an entry for the current machine */ /* (1) Check if there is an entry for the current machine */
$already_exists = is_array(Table::get('motheure') $fetched = Table::get('motheure')
->unique() ->unique()
->select('id_motheure') ->select('id_motheure')
->select('id_machine') ->select('id_machine')
->select('count')
->whereIdMachine($_SESSION['SATS']['id']) ->whereIdMachine($_SESSION['SATS']['id'])
->fetch()); ->fetch();
/* (2) Set variable to ease process */
$already_exists = is_array($fetched);
/* (2) If does not exist, create entry /* (2) If does not exist, create entry
@ -115,11 +120,8 @@
/* (1) Update entry */ /* (1) Update entry */
$updated = Table::get('motheure') $updated = Table::get('motheure')
->unique()
->whereIdMachine($_SESSION['SATS']['id']) ->whereIdMachine($_SESSION['SATS']['id'])
->edit([ ->edit([ 'count' => $count + $fetched['count'] ]);
'count' => $count
]);
/* (2) Propagate error */ /* (2) Propagate error */
return [ 'error' => ($updated) ? new Error(Err::Success) : new Error(Err::RepoError) ]; return [ 'error' => ($updated) ? new Error(Err::Success) : new Error(Err::RepoError) ];