MDL-50009 cron: Prevent tasks from leaving uncommitted transactions
authorMichael Aherne <michael.aherne@strath.ac.uk>
Tue, 28 Apr 2015 08:14:31 +0000 (09:14 +0100)
committerMichael Aherne <michael.aherne@strath.ac.uk>
Wed, 29 Apr 2015 08:39:07 +0000 (09:39 +0100)
lib/cronlib.php

index cb8bb98..5db8ba8 100644 (file)
@@ -72,6 +72,9 @@ function cron_run() {
         try {
             get_mailer('buffer');
             $task->execute();
+            if ($DB->is_transaction_started()) {
+                throw new coding_exception("Task left transaction open");
+            }
             if (isset($predbqueries)) {
                 mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
                 mtrace("... used " . (microtime(1) - $pretime) . " seconds");
@@ -105,6 +108,9 @@ function cron_run() {
         try {
             get_mailer('buffer');
             $task->execute();
+            if ($DB->is_transaction_started()) {
+                throw new coding_exception("Task left transaction open");
+            }
             if (isset($predbqueries)) {
                 mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
                 mtrace("... used " . (microtime(1) - $pretime) . " seconds");