Merge pull request #24378 from hregis/fix_menu_force_entity

FIX menu force entity = 0 if core module
This commit is contained in:
Laurent Destailleur 2023-03-31 02:27:56 +02:00 committed by GitHub
commit ce237713c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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 >= 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);
@ -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

View File

@ -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);