MDL-20625 coding help - better detection of missing commit or rollback

This commit is contained in:
Petr Skoda 2009-11-08 21:19:11 +00:00
parent c0829930c8
commit 07b81ebd2d
2 changed files with 15 additions and 1 deletions

View File

@ -285,10 +285,15 @@ abstract class moodle_database {
*/
public function dispose() {
if ($this->transactions) {
// this should not happen, it isually indicates wrong catching of exceptions,
// because all transactions should be finished manually or in default exception hadnler.
// unfortunately we can not access global $CFG any more and can not print debug,
// the diagnostic info should be printed in footer instead
$lowesttransaction = end($this->transactions);
$backtrace = $lowesttransaction->get_backtrace();
error_log('Potential coding error - active database transaction detected when disposing database:'."\n".format_backtrace($backtrace, true));
$this->force_transaction_rollback();
error_log('Active database transaction detected when disposing database!');
}
if ($this->used_for_db_sessions) {
// this is needed because we need to save session to db before closing it

View File

@ -41,6 +41,15 @@ class moodle_transaction {
public function __construct($database) {
$this->database = $database;
$this->start_backtrace = debug_backtrace();
array_shift($this->start_backtrace);
}
/**
* Returns backtrace of the code starting exception.
* @return array
*/
public function get_backtrace() {
return $this->start_backtrace;
}
/**