Fix: add updateObjectLink common function
This commit is contained in:
parent
d686c52b63
commit
e171cec236
@ -1630,6 +1630,52 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update object linked of a current object
|
||||||
|
*
|
||||||
|
* @param int $sourceid Object source id
|
||||||
|
* @param string $sourcetype Object source type
|
||||||
|
* @param int $targetid Object target id
|
||||||
|
* @param string $targettype Object target type
|
||||||
|
* @return int >0 if OK, <0 if KO
|
||||||
|
*/
|
||||||
|
function updateObjectLinked($sourceid='', $sourcetype='', $targetid='', $targettype='')
|
||||||
|
{
|
||||||
|
$updatesource=false;
|
||||||
|
$updatetarget=false;
|
||||||
|
|
||||||
|
if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true;
|
||||||
|
else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true;
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET ";
|
||||||
|
if ($updatesource)
|
||||||
|
{
|
||||||
|
$sql.= "fk_source = ".$sourceid;
|
||||||
|
$sql.= ", sourcetype = '".$sourcetype."'";
|
||||||
|
$sql.= " WHERE fk_target = ".$this->id;
|
||||||
|
$sql.= " AND targettype = '".$this->element."'";
|
||||||
|
}
|
||||||
|
else if ($updatetarget)
|
||||||
|
{
|
||||||
|
$sql.= "fk_target = ".$targetid;
|
||||||
|
$sql.= ", targettype = '".$targettype."'";
|
||||||
|
$sql.= " WHERE fk_source = ".$this->id;
|
||||||
|
$sql.= " AND sourcetype = '".$this->element."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::updateObjectLinked sql=".$sql, LOG_DEBUG);
|
||||||
|
if ($this->db->query($sql))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog(get_class($this)."::updateObjectLinked error=".$this->error, LOG_ERR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all links between an object $this
|
* Delete all links between an object $this
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user