From 94875cdc77fa541ffe4cabc9a497b7ec95249887 Mon Sep 17 00:00:00 2001 From: Indelog Date: Mon, 11 Oct 2021 13:37:37 +0200 Subject: [PATCH] Fix : Re-add bloc to set `$withtargettype` and `$withsourcetype` --- htdocs/core/class/commonobject.class.php | 25 +++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1de8d8cd752..864e2cdf337 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3712,19 +3712,34 @@ abstract class CommonObject $withtargettype = false; $withsourcetype = false; - $sourceid = (!empty($sourceid) ? $sourceid : $this->id); - $targetid = (!empty($targetid) ? $targetid : $this->id); - $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); - $targettype = (!empty($targettype) ? $targettype : $this->element); - $parameters = array('sourcetype'=>$sourcetype, 'sourceid'=>$sourceid, 'targettype'=>$targettype, 'targetid'=>$targetid); // Hook for explicitly set the targettype if it must be differtent than $this->element $reshook = $hookmanager->executeHooks('setLinkedObjectSourceTargetType', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook > 0) { if (!empty($hookmanager->resArray['sourcetype'])) $sourcetype = $hookmanager->resArray['sourcetype']; + if (!empty($hookmanager->resArray['sourceid'])) $sourceid = $hookmanager->resArray['sourceid']; if (!empty($hookmanager->resArray['targettype'])) $targettype = $hookmanager->resArray['targettype']; + if (!empty($hookmanager->resArray['targetid'])) $targetid = $hookmanager->resArray['targetid']; } + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) { + $justsource = true; // the source (id and type) is a search criteria + if (!empty($targettype)) { + $withtargettype = true; + } + } + if (!empty($targetid) && !empty($targettype) && empty($sourceid)) { + $justtarget = true; // the target (id and type) is a search criteria + if (!empty($sourcetype)) { + $withsourcetype = true; + } + } + + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); + $targetid = (!empty($targetid) ? $targetid : $this->id); + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); + $targettype = (!empty($targettype) ? $targettype : $this->element); + /*if (empty($sourceid) && empty($targetid)) { dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);