From 898a4bad159925ac7bdf327af0d118f85fb461e5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 29 Mar 2023 14:30:32 +0200 Subject: [PATCH 1/2] FIX menu force entity = 0 if core module --- htdocs/core/class/menubase.class.php | 10 ++++++++-- htdocs/core/modules/DolibarrModules.class.php | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 3630d137136..19b5535493f 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -49,6 +49,11 @@ class Menubase */ public $id; + /** + * @var int Entity + */ + public $entity; + /** * @var string Menu handler */ @@ -185,6 +190,7 @@ class Menubase if (!isset($this->enabled)) { $this->enabled = '1'; } + $this->entity = (isset($this->entity) ? (int) $this->entity : $conf->entity); $this->menu_handler = trim((string) $this->menu_handler); $this->module = trim((string) $this->module); $this->type = trim((string) $this->type); @@ -246,7 +252,7 @@ class Menubase $sql .= " AND fk_menu = ".((int) $this->fk_menu); $sql .= " AND position = ".((int) $this->position); $sql .= " AND url = '".$this->db->escape($this->url)."'"; - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity IN (0, ".$conf->entity.")"; $result = $this->db->query($sql); if ($result) { @@ -275,7 +281,7 @@ class Menubase $sql .= "usertype"; $sql .= ") VALUES ("; $sql .= " '".$this->db->escape($this->menu_handler)."',"; - $sql .= " '".$this->db->escape($conf->entity)."',"; + $sql .= " '".$this->db->escape($this->entity)."',"; $sql .= " '".$this->db->escape($this->module)."',"; $sql .= " '".$this->db->escape($this->type)."',"; $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 6c43c945b65..62dbd494082 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1986,7 +1986,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it public function insert_menus() { // phpcs:enable - global $user; + global $conf, $user; if (!is_array($this->menu) || empty($this->menu)) { return 0; @@ -1998,6 +1998,9 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $err = 0; + // Common module + $entity = ((!empty($this->always_enabled) || !empty($this->core_enabled)) ? 0 : $conf->entity); + $this->db->begin(); foreach ($this->menu as $key => $value) { @@ -2049,6 +2052,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $menu->user = $this->menu[$key]['user']; $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0; $menu->position = $this->menu[$key]['position']; + $menu->entity = $entity; if (!$err) { $result = $menu->create($user); // Save menu entry into table llx_menu @@ -2092,7 +2096,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; $sql .= " WHERE module = '".$this->db->escape($module)."'"; - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity IN (0, ".$conf->entity.")"; dol_syslog(get_class($this)."::delete_menus", LOG_DEBUG); $resql = $this->db->query($sql); From 48333a7205fb77737741612e18d164c5212b1be1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 29 Mar 2023 15:09:43 +0200 Subject: [PATCH 2/2] FIX wrong test --- htdocs/core/class/menubase.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 19b5535493f..2965db0f7c5 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -190,7 +190,7 @@ class Menubase if (!isset($this->enabled)) { $this->enabled = '1'; } - $this->entity = (isset($this->entity) ? (int) $this->entity : $conf->entity); + $this->entity = (isset($this->entity) && (int) $this->entity >= 0 ? (int) $this->entity : $conf->entity); $this->menu_handler = trim((string) $this->menu_handler); $this->module = trim((string) $this->module); $this->type = trim((string) $this->type);