Skip to content

Commit

Permalink
Merge pull request #9357 from joseplluis/patch-3
Browse files Browse the repository at this point in the history
FIX undefined rights_class on modules may lose setup when module disabled
  • Loading branch information
eldy committed Sep 1, 2018
2 parents 0073819 + d70e548 commit 8bd231a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions htdocs/core/modules/DolibarrModules.class.php
Expand Up @@ -6,6 +6,7 @@
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018 Josep Lluís Amador <joseplluis@lliuretic.cat>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1328,7 +1329,7 @@ function insert_cronjobs()

// Search if cron entry already present
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
$sql.= " WHERE module_name = '".$this->db->escape(empty($this->rights_class)?strtolower($this->name):$this->rights_class)."'";
if ($class) $sql.= " AND classesname = '".$this->db->escape($class)."'";
if ($objectname) $sql.= " AND objectname = '".$this->db->escape($objectname)."'";
if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'";
Expand All @@ -1354,7 +1355,7 @@ function insert_cronjobs()
if(is_int($status)){ $sql.= ' status,'; }
$sql.= " entity, test)";
$sql.= " VALUES (";
$sql.= "'".$this->db->escape($this->rights_class)."', ";
$sql.= "'".$this->db->escape(empty($this->rights_class)?strtolower($this->name):$this->rights_class)."', ";
$sql.= "'".$this->db->idate($now)."', ";
$sql.= ($datestart ? "'".$this->db->idate($datestart)."'" : "NULL").", ";
$sql.= ($dateend ? "'".$this->db->idate($dateend)."'" : "NULL").", ";
Expand Down Expand Up @@ -1417,7 +1418,7 @@ function delete_cronjobs()
if (is_array($this->cronjobs))
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."cronjob";
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
$sql.= " WHERE module_name = '".$this->db->escape(empty($this->rights_class)?strtolower($this->name):$this->rights_class)."'";
$sql.= " AND entity = ".$conf->entity;

dol_syslog(get_class($this)."::delete_cronjobs", LOG_DEBUG);
Expand Down Expand Up @@ -1795,7 +1796,7 @@ function delete_permissions()
$err=0;

$sql = "DELETE FROM ".MAIN_DB_PREFIX."rights_def";
$sql.= " WHERE module = '".$this->db->escape($this->rights_class)."'";
$sql.= " WHERE module = '".$this->db->escape(empty($this->rights_class)?strtolower($this->name):$this->rights_class)."'";
$sql.= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::delete_permissions", LOG_DEBUG);
if (! $this->db->query($sql))
Expand Down Expand Up @@ -1833,7 +1834,7 @@ function insert_menus()
$menu->menu_handler='all';

//$menu->module=strtolower($this->name); TODO When right_class will be same than module name
$menu->module=$this->rights_class;
$menu->module=empty($this->rights_class)?strtolower($this->name):$this->rights_class;

if (! $this->menu[$key]['fk_menu'])
{
Expand Down Expand Up @@ -1929,7 +1930,7 @@ function delete_menus()
$err=0;

//$module=strtolower($this->name); TODO When right_class will be same than module name
$module=$this->rights_class;
$module=empty($this->rights_class)?strtolower($this->name):$this->rights_class;

$sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
$sql.= " WHERE module = '".$this->db->escape($module)."'";
Expand Down

0 comments on commit 8bd231a

Please sign in to comment.