From: Petr Skoda Date: Sat, 7 Nov 2009 09:13:45 +0000 (+0000) Subject: MDL-20625 when in transaction do not trigger instant events becase we can not roll... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2055b631f0c65eef52834733401164f269071071;p=moodle.git MDL-20625 when in transaction do not trigger instant events becase we can not roll them back --- diff --git a/lib/eventslib.php b/lib/eventslib.php index c36c42b899..15886b57cd 100755 --- a/lib/eventslib.php +++ b/lib/eventslib.php @@ -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))) {