Merge branch 'develop' of https://github.com/Dolibarr/dolibarr into develop

This commit is contained in:
Laurent Destailleur 2012-02-07 18:49:35 +01:00
commit 581a87d9e4

View File

@ -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
* *