|
@@ -2544,7 +2544,12 @@ class User extends CommonObject
|
|
|
dol_syslog(get_class($this)."::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
|
|
|
foreach($this->users as $key => $val)
|
|
|
{
|
|
|
- $this->build_path_from_id_user($key,0); // Process a branch from the root user key (this user has no parent)
|
|
|
+ $result = $this->build_path_from_id_user($key,0); // Process a branch from the root user key (this user has no parent)
|
|
|
+ if ($result < 0)
|
|
|
+ {
|
|
|
+ $this->error='ErrorLoopInHierarchy';
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Exclude leaf including $deleteafterid from tree
|
|
@@ -2601,10 +2606,10 @@ class User extends CommonObject
|
|
|
* Function called by get_full_tree().
|
|
|
*
|
|
|
* @param int $id_user id_user entry to update
|
|
|
- * @param int $protection Deep counter to avoid infinite loop
|
|
|
- * @return void
|
|
|
+ * @param int $protection Deep counter to avoid infinite loop (no more required, a protection is added with array useridfound)
|
|
|
+ * @return int < 0 if KO (infinit loop), >= 0 if OK
|
|
|
*/
|
|
|
- function build_path_from_id_user($id_user,$protection=1000)
|
|
|
+ function build_path_from_id_user($id_user,$protection=0)
|
|
|
{
|
|
|
dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG);
|
|
|
|
|
@@ -2612,7 +2617,7 @@ class User extends CommonObject
|
|
|
{
|
|
|
// Already defined
|
|
|
dol_syslog(get_class($this)."::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
|
|
|
- return;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
// Define fullpath and fullname
|
|
@@ -2620,9 +2625,16 @@ class User extends CommonObject
|
|
|
$this->users[$id_user]['fullname'] = $this->users[$id_user]['lastname'];
|
|
|
$i=0; $cursor_user=$id_user;
|
|
|
|
|
|
- while ((empty($protection) || $i < $protection) && ! empty($this->parentof[$cursor_user]))
|
|
|
+ $useridfound=array($id_user);
|
|
|
+ while (! empty($this->parentof[$cursor_user]))
|
|
|
{
|
|
|
- $this->users[$id_user]['fullpath'] = '_'.$this->parentof[$cursor_user].$this->users[$id_user]['fullpath'];
|
|
|
+ if (in_array($this->parentof[$cursor_user], $useridfound))
|
|
|
+ {
|
|
|
+ dol_syslog("The hierarchy of user has a recursive loop", LOG_WARNING);
|
|
|
+ return -1; // Should not happen. Protection against looping hierarchy
|
|
|
+ }
|
|
|
+ $useridfound[]=$this->parentof[$cursor_user];
|
|
|
+ $this->users[$id_user]['fullpath'] = '_'.$this->parentof[$cursor_user].$this->users[$id_user]['fullpath'];
|
|
|
$this->users[$id_user]['fullname'] = $this->users[$this->parentof[$cursor_user]]['lastname'].' >> '.$this->users[$id_user]['fullname'];
|
|
|
$i++; $cursor_user=$this->parentof[$cursor_user];
|
|
|
}
|
|
@@ -2630,7 +2642,7 @@ class User extends CommonObject
|
|
|
// We count number of _ to have level
|
|
|
$this->users[$id_user]['level']=dol_strlen(preg_replace('/[^_]/i','',$this->users[$id_user]['fullpath']));
|
|
|
|
|
|
- return;
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
/**
|