mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
MDL-20625 coding help - better detection of missing commit or rollback
This commit is contained in:
parent
c0829930c8
commit
07b81ebd2d
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user