Code for update more similar than insert
This commit is contained in:
parent
13e71306ac
commit
9731a7fedc
@ -1345,6 +1345,7 @@ abstract class CommonObject
|
|||||||
* @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none'
|
* @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none'
|
||||||
* @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY')
|
* @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY')
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
|
* @see updateExtraField
|
||||||
*/
|
*/
|
||||||
function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='')
|
function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='')
|
||||||
{
|
{
|
||||||
@ -4511,6 +4512,7 @@ abstract class CommonObject
|
|||||||
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
|
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
|
||||||
* @param User $userused Object user
|
* @param User $userused Object user
|
||||||
* @return int -1=error, O=did nothing, 1=OK
|
* @return int -1=error, O=did nothing, 1=OK
|
||||||
|
* @see updateExtraField, setValueFrom
|
||||||
*/
|
*/
|
||||||
function insertExtraFields($trigger='',$userused=null)
|
function insertExtraFields($trigger='',$userused=null)
|
||||||
{
|
{
|
||||||
@ -4666,9 +4668,8 @@ abstract class CommonObject
|
|||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (! $error && $trigger)
|
||||||
if ($trigger)
|
|
||||||
{
|
{
|
||||||
// Call trigger
|
// Call trigger
|
||||||
$this->context=array('extrafieldaddupdate'=>1);
|
$this->context=array('extrafieldaddupdate'=>1);
|
||||||
@ -4676,7 +4677,6 @@ abstract class CommonObject
|
|||||||
if ($result < 0) $error++;
|
if ($result < 0) $error++;
|
||||||
// End call trigger
|
// End call trigger
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
@ -4694,15 +4694,19 @@ abstract class CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an exta field value for the current object.
|
* Update an exta field value for the current object.
|
||||||
* Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
* Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
||||||
* This function delte record with all extrafields and insert them again from the array $this->array_options.
|
|
||||||
*
|
*
|
||||||
* @param string $key Key of the extrafield
|
* @param string $key Key of the extrafield
|
||||||
|
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
|
||||||
|
* @param User $userused Object user
|
||||||
* @return int -1=error, O=did nothing, 1=OK
|
* @return int -1=error, O=did nothing, 1=OK
|
||||||
|
* @see setValueFrom
|
||||||
*/
|
*/
|
||||||
function updateExtraField($key)
|
function updateExtraField($key, $trigger, $userused)
|
||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs,$user;
|
||||||
|
|
||||||
|
if (empty($userused)) $userused=$user;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@ -4769,7 +4773,21 @@ abstract class CommonObject
|
|||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $resql)
|
if (! $resql)
|
||||||
{
|
{
|
||||||
|
$error++;
|
||||||
$this->error=$this->db->lasterror();
|
$this->error=$this->db->lasterror();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error && $trigger)
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$this->context=array('extrafieldupdate'=>1);
|
||||||
|
$result=$this->call_trigger($trigger, $userused);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call trigger
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error)
|
||||||
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user