New: Add an error message when transactions are not closed.

This commit is contained in:
Laurent Destailleur 2012-02-10 16:37:41 +01:00
parent 45529b14ff
commit 8bcdfc8897
7 changed files with 35 additions and 16 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -74,6 +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();
foreach ($listofmenuhandler as $key => $val) foreach ($listofmenuhandler as $key => $val)
{ {
// Load sql init_menu_handler.sql file // Load sql init_menu_handler.sql file
@ -83,9 +84,21 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can
if (file_exists($fullpath)) if (file_exists($fullpath))
{ {
$db->begin();
$result=run_sql($fullpath,1,'',1,$key); $result=run_sql($fullpath,1,'',1,$key);
if ($result > 0)
{
$db->commit();
}
else
{
$errmsgs[]='Failed to initialize menu '.$key.'.';
$db->rollback();
} }
} }
}
$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"]);
@ -238,6 +251,9 @@ else
print '</div>'; print '</div>';
dol_htmloutput_errors($errmsgs);
if (! isset($_GET["action"]) || $_GET["action"] != 'edit') if (! isset($_GET["action"]) || $_GET["action"] != 'edit')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
@ -245,7 +261,8 @@ if (! isset($_GET["action"]) || $_GET["action"] != 'edit')
print '</div>'; print '</div>';
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -53,7 +53,7 @@ class DoliDBMssql
var $database_name; var $database_name;
//! Nom user base //! Nom user base
var $database_user; var $database_user;
//! 1 si une transaction est en cours, 0 sinon //! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened; var $transaction_opened;
//! Derniere requete executee //! Derniere requete executee
var $lastquery; var $lastquery;
@ -242,7 +242,7 @@ class DoliDBMssql
{ {
if ($this->db) if ($this->db)
{ {
//dol_syslog(get_class($this)."::disconnect",LOG_DEBUG); if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
$this->connected=0; $this->connected=0;
return mssql_close($this->db); return mssql_close($this->db);
} }

View File

@ -53,7 +53,7 @@ class DoliDBMysql
var $database_name; var $database_name;
//! Nom user base //! Nom user base
var $database_user; var $database_user;
//! 1 si une transaction est en cours, 0 sinon //! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened; var $transaction_opened;
//! Last executed request //! Last executed request
var $lastquery; var $lastquery;
@ -269,7 +269,7 @@ class DoliDBMysql
{ {
if ($this->db) if ($this->db)
{ {
//dol_syslog(get_class($this)."::disconnect",LOG_DEBUG); if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
$this->connected=0; $this->connected=0;
return mysql_close($this->db); return mysql_close($this->db);
} }

View File

@ -53,7 +53,7 @@ class DoliDBMysqli
var $database_name; var $database_name;
//! Nom user base //! Nom user base
var $database_user; var $database_user;
//! 1 si une transaction est en cours, 0 sinon //! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened; var $transaction_opened;
//! Last executed request //! Last executed request
var $lastquery; var $lastquery;
@ -273,7 +273,7 @@ class DoliDBMysqli
{ {
if ($this->db) if ($this->db)
{ {
//dol_syslog(get_class($this)."::disconnect",LOG_DEBUG); if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
$this->connected=0; $this->connected=0;
return mysqli_close($this->db); return mysqli_close($this->db);
} }

View File

@ -51,7 +51,8 @@ class DoliDBPgsql
var $database_selected; // 1 si base selectionne, 0 sinon var $database_selected; // 1 si base selectionne, 0 sinon
var $database_name; //! Nom base selectionnee var $database_name; //! Nom base selectionnee
var $database_user; //! Nom user base var $database_user; //! Nom user base
var $transaction_opened; // 1 si une transaction est en cours, 0 sinon //! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened;
var $lastquery; var $lastquery;
var $lastqueryerror; // Ajout d'une variable en cas d'erreur var $lastqueryerror; // Ajout d'une variable en cas d'erreur
@ -439,7 +440,7 @@ class DoliDBPgsql
{ {
if ($this->db) if ($this->db)
{ {
//dol_syslog(get_class($this)."::disconnect",LOG_DEBUG); if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
$this->connected=0; $this->connected=0;
return pg_close($this->db); return pg_close($this->db);
} }

View File

@ -53,7 +53,7 @@ class DoliDBSqlite
var $database_name; var $database_name;
//! Nom user base //! Nom user base
var $database_user; var $database_user;
//! 1 si une transaction est en cours, 0 sinon //! >=1 if a transaction is opened, 0 otherwise
var $transaction_opened; var $transaction_opened;
//! Last executed request //! Last executed request
var $lastquery; var $lastquery;
@ -393,7 +393,7 @@ class DoliDBSqlite
{ {
if ($this->db) if ($this->db)
{ {
//dol_syslog(get_class($this)."::disconnect",LOG_DEBUG); if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
$this->connected=0; $this->connected=0;
$this->db=null; // Clean this->db $this->db=null; // Clean this->db
return true; return true;

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2000-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2000-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr> * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
@ -229,9 +229,10 @@ function getEntity($element=false, $shared=false)
function dol_shutdown() function dol_shutdown()
{ {
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
$disconnectdone=false; $disconnectdone=false; $depth=0;
if (is_object($db) && ! empty($db->connected)) $disconnectdone=$db->close(); print 'xx'.$db->connected;
dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced)':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG)); 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));
} }