]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19470 detection of unfinished transactions and transactions interrupted by exceptions
authorskodak <skodak>
Fri, 12 Jun 2009 10:59:28 +0000 (10:59 +0000)
committerskodak <skodak>
Fri, 12 Jun 2009 10:59:28 +0000 (10:59 +0000)
lib/dml/moodle_database.php
lib/setuplib.php

index 668ec4bf3d5933dda7d220f9767f396f5a5d73ac..3f4f2c3514deae6fd074e2c8f820743152f41d84 100644 (file)
@@ -278,7 +278,8 @@ abstract class moodle_database {
      */
     public function dispose() {
         if ($this->intransaction) {
-            error_log('Active database transaction detected when disposing database!'); // probably can not write to console anymore, log problem instead  
+            // unfortunately we can not access global $CFG any more and can not print debug 
+            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 275aa8f08d06a123f973451d276de2a99c5d6051..eb8e893529a70b8b9c1b3a485a4b710ab2752795 100644 (file)
@@ -119,7 +119,17 @@ class invalid_state_exception extends moodle_exception {
  * Default exception handler, uncought exceptions are equivalent to using print_error()
  */
 function default_exception_handler($ex) {
-    global $CFG;
+    global $CFG, $DB, $SCRIPT;
+
+    // detect active db transactions, rollback and log as error
+    if ($DB->is_transaction_started()) {
+        error_log('Database transaction aborted by exception in '.$CFG->dirroot.$SCRIPT);
+        try {
+            // note: transaction blocks should never change current $_SESSION
+            $DB->rollback_sql();
+        } catch (Exception $ignored) {
+        }
+    }
 
     $backtrace = $ex->getTrace();
     $place = array('file'=>$ex->getFile(), 'line'=>$ex->getLine(), 'exception'=>get_class($ex));