Skip to content

Commit

Permalink
Fix travis
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 3, 2018
1 parent da7b433 commit f93f5bd
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -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"
Expand Down
123 changes: 74 additions & 49 deletions htdocs/core/class/menubase.class.php
Expand Up @@ -124,61 +124,86 @@ function create($user=null)
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

// 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)
$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;

$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;
}
}

Expand Down
68 changes: 35 additions & 33 deletions htdocs/core/modules/DolibarrModules.class.php
Expand Up @@ -953,7 +953,7 @@ function _active()
$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++;

Expand Down Expand Up @@ -1672,54 +1672,56 @@ function insert_permissions($reinitadminperms=0, $force_entity=null, $notrigger=
$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;
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);

}
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)
{
Expand Down

0 comments on commit f93f5bd

Please sign in to comment.