From 8bcdfc8897e12600d757f80e7001797a53c66c9a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Feb 2012 16:37:41 +0100 Subject: [PATCH] New: Add an error message when transactions are not closed. --- htdocs/admin/menus.php | 21 +++++++++++++++++++-- htdocs/core/db/mssql.class.php | 4 ++-- htdocs/core/db/mysql.class.php | 4 ++-- htdocs/core/db/mysqli.class.php | 4 ++-- htdocs/core/db/pgsql.class.php | 5 +++-- htdocs/core/db/sqlite.class.php | 4 ++-- htdocs/core/lib/functions.lib.php | 9 +++++---- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/htdocs/admin/menus.php b/htdocs/admin/menus.php index 9d56ca1ddba..9b63b00f195 100644 --- a/htdocs/admin/menus.php +++ b/htdocs/admin/menus.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * 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; // Initialize menu handlers + $errmsgs=array(); foreach ($listofmenuhandler as $key => $val) { // Load sql init_menu_handler.sql file @@ -83,10 +84,22 @@ if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["can if (file_exists($fullpath)) { + $db->begin(); $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. header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -238,6 +251,9 @@ else print ''; +dol_htmloutput_errors($errmsgs); + + if (! isset($_GET["action"]) || $_GET["action"] != 'edit') { print '
'; @@ -245,7 +261,8 @@ if (! isset($_GET["action"]) || $_GET["action"] != 'edit') print '
'; } -$db->close(); llxFooter(); + +$db->close(); ?> diff --git a/htdocs/core/db/mssql.class.php b/htdocs/core/db/mssql.class.php index 04952615a0a..6975b8539ff 100644 --- a/htdocs/core/db/mssql.class.php +++ b/htdocs/core/db/mssql.class.php @@ -53,7 +53,7 @@ class DoliDBMssql var $database_name; //! Nom user base var $database_user; - //! 1 si une transaction est en cours, 0 sinon + //! >=1 if a transaction is opened, 0 otherwise var $transaction_opened; //! Derniere requete executee var $lastquery; @@ -242,7 +242,7 @@ class DoliDBMssql { 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; return mssql_close($this->db); } diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index 73850cc70a5..b848531342a 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -53,7 +53,7 @@ class DoliDBMysql var $database_name; //! Nom user base var $database_user; - //! 1 si une transaction est en cours, 0 sinon + //! >=1 if a transaction is opened, 0 otherwise var $transaction_opened; //! Last executed request var $lastquery; @@ -269,7 +269,7 @@ class DoliDBMysql { 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; return mysql_close($this->db); } diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 5384dfb0517..4e715c2c756 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -53,7 +53,7 @@ class DoliDBMysqli var $database_name; //! Nom user base var $database_user; - //! 1 si une transaction est en cours, 0 sinon + //! >=1 if a transaction is opened, 0 otherwise var $transaction_opened; //! Last executed request var $lastquery; @@ -273,7 +273,7 @@ class DoliDBMysqli { 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; return mysqli_close($this->db); } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index e340af866cc..50645c8701a 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -51,7 +51,8 @@ class DoliDBPgsql var $database_selected; // 1 si base selectionne, 0 sinon var $database_name; //! Nom base selectionnee 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 $lastqueryerror; // Ajout d'une variable en cas d'erreur @@ -439,7 +440,7 @@ class DoliDBPgsql { 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; return pg_close($this->db); } diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index 52d6a05d4ce..32068b9c76c 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -53,7 +53,7 @@ class DoliDBSqlite var $database_name; //! Nom user base var $database_user; - //! 1 si une transaction est en cours, 0 sinon + //! >=1 if a transaction is opened, 0 otherwise var $transaction_opened; //! Last executed request var $lastquery; @@ -393,7 +393,7 @@ class DoliDBSqlite { 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->db=null; // Clean this->db return true; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b6dc024b0e3..4d9ff9b2f81 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Christophe Combelles @@ -229,9 +229,10 @@ function getEntity($element=false, $shared=false) function dol_shutdown() { global $conf,$user,$langs,$db; - $disconnectdone=false; - if (is_object($db) && ! empty($db->connected)) $disconnectdone=$db->close(); - dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced)':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG)); + $disconnectdone=false; $depth=0; + print 'xx'.$db->connected; + 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)); }