New: Increase speed when switching to auguria module. Add error management.
This commit is contained in:
parent
8bcdfc8897
commit
9d2afc5fea
@ -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;
|
if (isset($_POST["MAIN_MENUFRONT_SMARTPHONE"])) $listofmenuhandler[preg_replace('/((_back|_front)office)?\.php/i','',$_POST["MAIN_MENUFRONT_SMARTPHONE"])]=1;
|
||||||
|
|
||||||
// Initialize menu handlers
|
// Initialize menu handlers
|
||||||
$errmsgs=array();
|
$error=0; $errmsgs=array();
|
||||||
foreach ($listofmenuhandler as $key => $val)
|
foreach ($listofmenuhandler as $key => $val)
|
||||||
{
|
{
|
||||||
// Load sql init_menu_handler.sql file
|
// 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))
|
if (file_exists($fullpath))
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
$result=run_sql($fullpath,1,'',1,$key);
|
|
||||||
|
$result=run_sql($fullpath,1,'',1,$key,'none');
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$error++;
|
||||||
$errmsgs[]='Failed to initialize menu '.$key.'.';
|
$errmsgs[]='Failed to initialize menu '.$key.'.';
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->close();
|
if (! $error)
|
||||||
|
{
|
||||||
|
$db->close();
|
||||||
|
|
||||||
// We make a header redirect because we need to change menu NOW.
|
// We make a header redirect because we need to change menu NOW.
|
||||||
header("Location: ".$_SERVER["PHP_SELF"]);
|
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||||
exit;
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -251,7 +256,7 @@ else
|
|||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
|
|
||||||
dol_htmloutput_errors($errmsgs);
|
dol_htmloutput_errors('',$errmsgs);
|
||||||
|
|
||||||
|
|
||||||
if (! isset($_GET["action"]) || $_GET["action"] != 'edit')
|
if (! isset($_GET["action"]) || $_GET["action"] != 'edit')
|
||||||
|
|||||||
@ -108,13 +108,14 @@ function versiondolibarrarray()
|
|||||||
* @param int $entity Entity targeted for multicompany module
|
* @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 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 $handler Handler targeted for menu
|
||||||
|
* @param string $okerror Family of errors we accept ('default', 'none')
|
||||||
* @return int <=0 if KO, >0 if OK
|
* @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;
|
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;
|
$ok=0;
|
||||||
$error=0;
|
$error=0;
|
||||||
@ -317,24 +318,25 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='')
|
|||||||
$errno=$db->errno();
|
$errno=$db->errno();
|
||||||
if (! $silent) print '<!-- Result = '.$errno.' -->'."\n";
|
if (! $silent) print '<!-- Result = '.$errno.' -->'."\n";
|
||||||
|
|
||||||
$okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
|
// Define list of errors we accept (array $okerrors)
|
||||||
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
$okerrors=array( // By default
|
||||||
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
'DB_ERROR_TABLE_ALREADY_EXISTS',
|
||||||
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist
|
'DB_ERROR_COLUMN_ALREADY_EXISTS',
|
||||||
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
|
||||||
'DB_ERROR_NOSUCHTABLE',
|
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist
|
||||||
'DB_ERROR_NOSUCHFIELD',
|
'DB_ERROR_RECORD_ALREADY_EXISTS',
|
||||||
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
'DB_ERROR_NOSUCHTABLE',
|
||||||
'DB_ERROR_NO_INDEX_TO_DROP',
|
'DB_ERROR_NOSUCHFIELD',
|
||||||
'DB_ERROR_CANNOT_CREATE', // Qd contrainte deja existante
|
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
|
||||||
'DB_ERROR_CANT_DROP_PRIMARY_KEY',
|
'DB_ERROR_NO_INDEX_TO_DROP',
|
||||||
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS'
|
'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 ($okerror == 'none') $okerrors=array();
|
||||||
{
|
|
||||||
//if (! $silent) print $langs->trans("OK");
|
// Is it an error we accept
|
||||||
}
|
if (! in_array($errno,$okerrors))
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (! $silent) print '<tr><td valign="top" colspan="2">';
|
if (! $silent) print '<tr><td valign="top" colspan="2">';
|
||||||
if (! $silent) print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$newsql."<br>".$db->error()."</div></td>";
|
if (! $silent) print '<div class="error">'.$langs->trans("Error")." ".$db->errno().": ".$newsql."<br>".$db->error()."</div></td>";
|
||||||
|
|||||||
@ -230,7 +230,6 @@ function dol_shutdown()
|
|||||||
{
|
{
|
||||||
global $conf,$user,$langs,$db;
|
global $conf,$user,$langs,$db;
|
||||||
$disconnectdone=false; $depth=0;
|
$disconnectdone=false; $depth=0;
|
||||||
print 'xx'.$db->connected;
|
|
||||||
if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); }
|
if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); }
|
||||||
dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG));
|
dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user