]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20625 coding help - better detection of missing commit or rollback
authorPetr Skoda <skodak@moodle.org>
Sun, 8 Nov 2009 21:19:11 +0000 (21:19 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 8 Nov 2009 21:19:11 +0000 (21:19 +0000)
lib/dml/moodle_database.php
lib/dml/moodle_transaction.php

index 0e178d080e002f045af2c1f124f9528b277a9a36..0da533897f6972c66ee8bad9cb271ea9619457c0 100644 (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
index 37d252e290fbcd73703f9f80b32bd0d49ccaec92..75fc132b9e4e55024aedc48a7cce2d4b94225587 100644 (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;
     }
 
     /**