Better error message when missing grant privileges

This commit is contained in:
Laurent Destailleur 2019-06-05 10:42:59 +02:00
parent 06e0ec5e0c
commit d3d0ce4649
2 changed files with 8 additions and 1 deletions

View File

@ -930,11 +930,17 @@ class DoliDBMysqli extends DoliDB
dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
}
}
// Redo with localhost forced (sometimes user is created on %)
$sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'@'localhost'";
$resql=$this->query($sql);
$sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'";
dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
$resql=$this->query($sql);
if (! $resql)
{
$this->error = "Connected user not allowed to GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '*****'";
return -1;
}

View File

@ -573,6 +573,7 @@ if (! $error && $db->connected && $action == "set")
// Create user
$result=$db->DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name);
// Create user bis
if ($databasefortest == 'mysql')
{
@ -611,7 +612,7 @@ if (! $error && $db->connected && $action == "set")
print $langs->trans("UserCreation").' : ';
print $dolibarr_main_db_user;
print '</td>';
print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error()."</td></tr>";
print '<td>'.$langs->trans("Error").': '.$db->errno().' '.$db->error().($db->error ? '. '.$db->error : '')."</td></tr>";
}
}