]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20625 when in transaction do not trigger instant events becase we can not roll...
authorPetr Skoda <skodak@moodle.org>
Sat, 7 Nov 2009 09:13:45 +0000 (09:13 +0000)
committerPetr Skoda <skodak@moodle.org>
Sat, 7 Nov 2009 09:13:45 +0000 (09:13 +0000)
lib/eventslib.php

index c36c42b899ccf82a520abf57bc6e94f969081755..15886b57cd0af795aee9c9cf1f7e173b88a7fafb 100755 (executable)
@@ -424,7 +424,16 @@ function events_trigger($eventname, $eventdata) {
 
            $errormessage = '';
 
-           if ($handler->schedule == 'instant') {
+           if ($handler->schedule == 'instant' and $DB->is_transaction_started()) {
+                // Instant events can not be rolled back in DB transactions,
+                // we need to send them to queue instead - this is slow but necessary.
+                // It could be improved in future by adding internal/external flag to each handler.
+
+                $DB->set_field('events_handlers', 'status', ($hadnler->status+1), array('id'=>$handler->id));
+                // reset static handler cache
+                events_get_handlers('reset');
+
+           } else if ($handler->schedule == 'instant') {
                 if ($handler->status) {
                     //check if previous pending events processed
                     if (!$DB->record_exists('events_queue_handlers', array('handlerid'=>$handler->id))) {