Fix regression on fetchObjectLinked when used in loop on a static object

This commit is contained in:
Laurent Destailleur 2022-04-12 10:34:50 +02:00
parent cb15a21e41
commit 98c7139859
2 changed files with 9 additions and 10 deletions

View File

@ -1630,8 +1630,6 @@ class Facture extends CommonInvoice
*/ */
public function fetch($rowid, $ref = '', $ref_ext = '', $notused = '', $fetch_situation = false) public function fetch($rowid, $ref = '', $ref_ext = '', $notused = '', $fetch_situation = false)
{ {
global $conf;
if (empty($rowid) && empty($ref) && empty($ref_ext)) { if (empty($rowid) && empty($ref) && empty($ref_ext)) {
return -1; return -1;
} }

View File

@ -126,10 +126,9 @@ abstract class CommonObject
public $linkedObjects; public $linkedObjects;
/** /**
* @var boolean is linkedObjects full loaded. Loaded by ->fetchObjectLinked * @var boolean Array of boolean with object id as key and value as true if linkedObjects full loaded. Loaded by ->fetchObjectLinked. Important for pdf generation time reduction.
* important for pdf generation time reduction
*/ */
public $linkedObjectsFullLoaded = false; public $linkedObjectsFullLoaded = array();
/** /**
* @var Object To store a cloned copy of object before to edit it and keep track of old properties * @var Object To store a cloned copy of object before to edit it and keep track of old properties
@ -3781,9 +3780,11 @@ abstract class CommonObject
{ {
global $conf, $hookmanager, $action; global $conf, $hookmanager, $action;
// important for pdf generation time reduction // Important for pdf generation time reduction
// this boolean is true if $this->linkedObjects has already been loaded with all objects linked without filter // This boolean is true if $this->linkedObjects has already been loaded with all objects linked without filter
if ($this->linkedObjectsFullLoaded) return 1; if ($this->id > 0 && !empty($this->linkedObjectsFullLoaded[$this->id])) {
return 1;
}
$this->linkedObjectsIds = array(); $this->linkedObjectsIds = array();
$this->linkedObjects = array(); $this->linkedObjects = array();
@ -3846,8 +3847,8 @@ abstract class CommonObject
} else { } else {
$sql .= "(fk_source = ".((int) $sourceid)." AND sourcetype = '".$this->db->escape($sourcetype)."')"; $sql .= "(fk_source = ".((int) $sourceid)." AND sourcetype = '".$this->db->escape($sourcetype)."')";
$sql .= " ".$clause." (fk_target = ".((int) $targetid)." AND targettype = '".$this->db->escape($targettype)."')"; $sql .= " ".$clause." (fk_target = ".((int) $targetid)." AND targettype = '".$this->db->escape($targettype)."')";
if ($sourceid == $this->id && $sourcetype == $this->element && $targetid == $this->id && $targettype == $this->element && $clause == 'OR') { if ($this->id > 0 && $sourceid == $this->id && $sourcetype == $this->element && $targetid == $this->id && $targettype == $this->element && $clause == 'OR') {
$this->linkedObjectsFullLoaded = true; $this->linkedObjectsFullLoaded[$this->id] = true;
} }
} }
$sql .= " ORDER BY ".$orderby; $sql .= " ORDER BY ".$orderby;