From f93f5bd6e0f18de77e27735290e85a3e46040867 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Jul 2018 13:49:41 +0200 Subject: [PATCH] Fix travis --- .travis.yml | 3 +- htdocs/core/class/menubase.class.php | 121 +++++++++++------- htdocs/core/modules/DolibarrModules.class.php | 70 +++++----- 3 files changed, 111 insertions(+), 83 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51b62e240e9..98dcca4cf20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -341,7 +341,8 @@ script: #cat $TRAVIS_BUILD_DIR/upgrade500600.log #cat $TRAVIS_BUILD_DIR/upgrade500600-2.log #cat $TRAVIS_BUILD_DIR/upgrade500600-3.log - #cat /tmp/dolibarr_install.log + #cat $TRAVIS_BUILD_DIR/upgrade600700-2.log + cat /tmp/dolibarr_install.log - | echo "Unit testing" diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index c123356f9ab..48880633563 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -124,61 +124,86 @@ class Menubase else dol_print_error($this->db); } - // TODO // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql + $sql = "SELECT count(*)"; + $sql.= " FROM ".MAIN_DB_PREFIX."menu"; + $sql.= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'"; + $sql.= " AND fk_menu = ".((int) $this->db->escape($this->fk_menu)); + $sql.= " AND position = ".((int) $this->position); + $sql.= " AND url = '".$this->db->escape($this->url)."'"; + $sql.= " AND entity = ".$conf->entity; - // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; - $sql.= "menu_handler,"; - $sql.= "entity,"; - $sql.= "module,"; - $sql.= "type,"; - $sql.= "mainmenu,"; - $sql.= "leftmenu,"; - $sql.= "fk_menu,"; - $sql.= "fk_mainmenu,"; - $sql.= "fk_leftmenu,"; - $sql.= "position,"; - $sql.= "url,"; - $sql.= "target,"; - $sql.= "titre,"; - $sql.= "langs,"; - $sql.= "perms,"; - $sql.= "enabled,"; - $sql.= "usertype"; - $sql.= ") VALUES ("; - $sql.= " '".$this->db->escape($this->menu_handler)."',"; - $sql.= " '".$this->db->escape($conf->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 - $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").","; - $sql.= " '".$this->db->escape($this->fk_menu)."',"; - $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; - $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; - $sql.= " '".(int) $this->position."',"; - $sql.= " '".$this->db->escape($this->url)."',"; - $sql.= " '".$this->db->escape($this->target)."',"; - $sql.= " '".$this->db->escape($this->titre)."',"; - $sql.= " '".$this->db->escape($this->langs)."',"; - $sql.= " '".$this->db->escape($this->perms)."',"; - $sql.= " '".$this->db->escape($this->enabled)."',"; - $sql.= " '".$this->db->escape($this->user)."'"; - $sql.= ")"; - - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) + $result=$this->db->query($sql); + if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); - dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); + $row = $this->db->fetch_row($result); - return $this->id; + if ($row[0] == 0) // If not found + { + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; + $sql.= "menu_handler,"; + $sql.= "entity,"; + $sql.= "module,"; + $sql.= "type,"; + $sql.= "mainmenu,"; + $sql.= "leftmenu,"; + $sql.= "fk_menu,"; + $sql.= "fk_mainmenu,"; + $sql.= "fk_leftmenu,"; + $sql.= "position,"; + $sql.= "url,"; + $sql.= "target,"; + $sql.= "titre,"; + $sql.= "langs,"; + $sql.= "perms,"; + $sql.= "enabled,"; + $sql.= "usertype"; + $sql.= ") VALUES ("; + $sql.= " '".$this->db->escape($this->menu_handler)."',"; + $sql.= " '".$this->db->escape($conf->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 + $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").","; + $sql.= " ".((int) $this->fk_menu).","; + $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; + $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; + $sql.= " ".((int) $this->position).","; + $sql.= " '".$this->db->escape($this->url)."',"; + $sql.= " '".$this->db->escape($this->target)."',"; + $sql.= " '".$this->db->escape($this->titre)."',"; + $sql.= " '".$this->db->escape($this->langs)."',"; + $sql.= " '".$this->db->escape($this->perms)."',"; + $sql.= " '".$this->db->escape($this->enabled)."',"; + $sql.= " '".$this->db->escape($this->user)."'"; + $sql.= ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); + dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); + + return $this->id; + } + else + { + $this->error="Error ".$this->db->lasterror(); + return -1; + } + } + else + { + dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING); + $this->error = 'Error Menu entry already exists'; + return 0; + } } else { - $this->error="Error ".$this->db->lasterror(); - return -1; + return -1; } } diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index a5211b11b5e..527bf945547 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -953,7 +953,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($this->const_name)."'"; $sql.= " AND entity IN (0, ".$entity.")"; - dol_syslog(get_class($this)."::_active delect activation constant", LOG_DEBUG); + dol_syslog(get_class($this)."::_active delete activation constant", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) $err++; @@ -1672,54 +1672,56 @@ class DolibarrModules // Can not be abstract, because we need to insta $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."rights_def"; $sql.= " WHERE id = ".$r_id." AND entity = ".$entity; $resqlselect=$this->db->query($sql); - - $obj = $this->db->fetch_object($resqlselect); - if ($obj->nb == 0) + if ($resqlselect) { - if (dol_strlen($r_perms) ) + $obj = $this->db->fetch_object($resqlselect); + if ($obj->nb == 0) { - if (dol_strlen($r_subperms) ) + if (dol_strlen($r_perms) ) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def"; - $sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)"; - $sql.= " VALUES "; - $sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')"; + if (dol_strlen($r_subperms) ) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def"; + $sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)"; + $sql.= " VALUES "; + $sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')"; + } + else + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def"; + $sql.= " (id, entity, libelle, module, type, bydefault, perms)"; + $sql.= " VALUES "; + $sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')"; + } } else { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def"; - $sql.= " (id, entity, libelle, module, type, bydefault, perms)"; - $sql.= " VALUES "; - $sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def "; + $sql .= " (id, entity, libelle, module, type, bydefault)"; + $sql .= " VALUES "; + $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")"; } - } - else - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def "; - $sql .= " (id, entity, libelle, module, type, bydefault)"; - $sql .= " VALUES "; - $sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")"; - } - $resqlinsert=$this->db->query($sql,1); + $resqlinsert=$this->db->query($sql,1); - if (! $resqlinsert) - { - if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") + if (! $resqlinsert) { - $this->error=$this->db->lasterror(); - $err++; - break; - } - else dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO); + if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") + { + $this->error=$this->db->lasterror(); + $err++; + break; + } + else dol_syslog(get_class($this)."::insert_permissions record already exists", LOG_INFO); + } + + $this->db->free($resqlinsert); } - $this->db->free($resqlinsert); + $this->db->free($resqlselect); } - $this->db->free($resqlselect); - // If we want to init permissions on admin users if ($reinitadminperms) {