diff --git a/htdocs/admin/menus.php b/htdocs/admin/menus.php index 9b63b00f195..23c7ee04983 100644 --- a/htdocs/admin/menus.php +++ b/htdocs/admin/menus.php @@ -74,7 +74,7 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can if (isset($_POST["MAIN_MENUFRONT_SMARTPHONE"])) $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENUFRONT_SMARTPHONE"])]=1; // Initialize menu handlers - $errmsgs=array(); + $error=0; $errmsgs=array(); foreach ($listofmenuhandler as $key => $val) { // Load sql init_menu_handler.sql file @@ -85,24 +85,29 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can if (file_exists($fullpath)) { $db->begin(); - $result=run_sql($fullpath,1,'',1,$key); + + $result=run_sql($fullpath,1,'',1,$key,'none'); if ($result > 0) { $db->commit(); } else { + $error++; $errmsgs[]='Failed to initialize menu '.$key.'.'; $db->rollback(); } } } - $db->close(); - - // We make a header redirect because we need to change menu NOW. - header("Location: ".$_SERVER["PHP_SELF"]); - exit; + if (! $error) + { + $db->close(); + + // We make a header redirect because we need to change menu NOW. + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } } @@ -251,7 +256,7 @@ else print ''; -dol_htmloutput_errors($errmsgs); +dol_htmloutput_errors('',$errmsgs); if (! isset($_GET["action"]) || $_GET["action"] != 'edit') diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 116e4835b20..d64192c28d0 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -108,13 +108,14 @@ function versiondolibarrarray() * @param int $entity Entity targeted for multicompany module * @param int $usesavepoint 1=Run a savepoint before each request and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). * @param string $handler Handler targeted for menu + * @param string $okerror Family of errors we accept ('default', 'none') * @return int <=0 if KO, >0 if OK */ -function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='') +function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$okerror='default') { global $db, $conf, $langs, $user; - dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile." silent=".$silent." entity=".$entity." usesavepoint=".$usesavepoint." handler=".$handler, LOG_DEBUG); + dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile." silent=".$silent." entity=".$entity." usesavepoint=".$usesavepoint." handler=".$handler." okerror=".$okerror, LOG_DEBUG); $ok=0; $error=0; @@ -317,24 +318,25 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='') $errno=$db->errno(); if (! $silent) print ''."\n"; - $okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS', - 'DB_ERROR_COLUMN_ALREADY_EXISTS', - 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', - 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist - 'DB_ERROR_RECORD_ALREADY_EXISTS', - 'DB_ERROR_NOSUCHTABLE', - 'DB_ERROR_NOSUCHFIELD', - 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', - 'DB_ERROR_NO_INDEX_TO_DROP', - 'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante - 'DB_ERROR_CANT_DROP_PRIMARY_KEY', - 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' + // Define list of errors we accept (array $okerrors) + $okerrors=array( // By default + 'DB_ERROR_TABLE_ALREADY_EXISTS', + 'DB_ERROR_COLUMN_ALREADY_EXISTS', + 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', + 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist + 'DB_ERROR_RECORD_ALREADY_EXISTS', + 'DB_ERROR_NOSUCHTABLE', + 'DB_ERROR_NOSUCHFIELD', + 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', + 'DB_ERROR_NO_INDEX_TO_DROP', + 'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante + 'DB_ERROR_CANT_DROP_PRIMARY_KEY', + 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ); - if (in_array($errno,$okerror)) - { - //if (! $silent) print $langs->trans("OK"); - } - else + if ($okerror == 'none') $okerrors=array(); + + // Is it an error we accept + if (! in_array($errno,$okerrors)) { if (! $silent) print '