From 7c7d3afab5767fa0e9a3bded9ff9294ea92b0c13 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 7 Nov 2009 10:27:57 +0000 Subject: [PATCH] MDL-20766 message_send() used intead of events, it will enable us to improve performance and solve db transactions issues independedntly from events, hopefully this will give us more options in future too because the events are designed specifically for communication "moodle-->external systems" --- admin/handlevirus.php | 6 +-- backup/backup_scheduled.php | 2 +- course/lib.php | 2 +- enrol/authorize/enrol.php | 16 ++++---- enrol/authorize/localfuncs.php | 4 +- enrol/authorize/uploadcsv.php | 2 +- enrol/flatfile/enrol.php | 8 ++-- enrol/imsenterprise/enrol.php | 2 +- enrol/manual/enrol.php | 4 +- enrol/paypal/ipn.php | 10 ++--- error/index.php | 2 +- lib/adminlib.php | 1 - lib/db/events.php | 17 --------- lib/messagelib.php | 67 +++++++++++++++++++--------------- lib/portfoliolib.php | 2 +- lib/setup.php | 1 + lib/uploadlib.php | 2 +- message/edit.php | 1 - message/lib.php | 2 +- mod/assignment/lib.php | 7 +--- mod/feedback/lib.php | 9 ++--- mod/forum/lib.php | 4 +- mod/lesson/essay.php | 15 +++----- mod/quiz/locallib.php | 4 +- user/editadvanced.php | 1 - 25 files changed, 85 insertions(+), 106 deletions(-) diff --git a/admin/handlevirus.php b/admin/handlevirus.php index c84428077e40a..5a131fa849f7f 100644 --- a/admin/handlevirus.php +++ b/admin/handlevirus.php @@ -68,7 +68,7 @@ function notify_user($user,$subject,$a) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } @@ -87,7 +87,7 @@ function notify_admins($user,$subject,$a) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } @@ -108,7 +108,7 @@ function notify_admins_unknown($file,$a) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } diff --git a/backup/backup_scheduled.php b/backup/backup_scheduled.php index fdf5168d99b83..87ab3a1ef7bfd 100644 --- a/backup/backup_scheduled.php +++ b/backup/backup_scheduled.php @@ -210,7 +210,7 @@ function schedule_backup_cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } //Everything is finished stop backup_sche_running diff --git a/course/lib.php b/course/lib.php index f599fcf50b5c0..dbf7f90e49904 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3996,6 +3996,6 @@ protected function notify($touser, $fromuser, $name='courserequested', $subject, $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } \ No newline at end of file diff --git a/enrol/authorize/enrol.php b/enrol/authorize/enrol.php index c2afaea55f1fd..7040492622c4f 100755 --- a/enrol/authorize/enrol.php +++ b/enrol/authorize/enrol.php @@ -252,7 +252,7 @@ private function cc_submit($form, $course) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } redirect($CFG->wwwroot, get_string("reviewnotify", "enrol_authorize"), '30'); @@ -285,7 +285,7 @@ private function cc_submit($form, $course) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } if (!empty($CFG->enrol_mailadmins)) { $a = new stdClass; @@ -302,7 +302,7 @@ private function cc_submit($form, $course) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } } @@ -723,7 +723,7 @@ public function cron() $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } if (!empty($CFG->enrol_mailadmins)) { $eventdata = new object(); @@ -735,7 +735,7 @@ public function cron() $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } // Send emails to students about which courses have enrolled. @@ -803,7 +803,7 @@ private function cron_daily() $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } mtrace(" users who have 'enrol/authorize:uploadcsv' were mailed"); } @@ -847,7 +847,7 @@ private function cron_daily() $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); // Email to payment managers if (empty($CFG->an_emailexpiredteacher)) { @@ -895,7 +895,7 @@ private function cron_daily() $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } } diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php index 29870c508cdae..d577736b2a9e0 100644 --- a/enrol/authorize/localfuncs.php +++ b/enrol/authorize/localfuncs.php @@ -131,7 +131,7 @@ function message_to_admin($subject, $data) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } function send_welcome_messages($orderdata) @@ -198,7 +198,7 @@ function send_welcome_messages($orderdata) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } while ($ei); diff --git a/enrol/authorize/uploadcsv.php b/enrol/authorize/uploadcsv.php index dfa0617613449..b2a50942e19ee 100644 --- a/enrol/authorize/uploadcsv.php +++ b/enrol/authorize/uploadcsv.php @@ -241,7 +241,7 @@ function authorize_process_csv($filename) $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } /// Send welcome messages to users diff --git a/enrol/flatfile/enrol.php b/enrol/flatfile/enrol.php index a34d219b9e4d8..e074621c513a0 100644 --- a/enrol/flatfile/enrol.php +++ b/enrol/flatfile/enrol.php @@ -227,7 +227,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } if (!empty($CFG->enrol_mailteachers) && $teachers) { @@ -247,7 +247,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } } @@ -274,7 +274,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); $this->log .= "Error unlinking file $filename\n"; } @@ -288,7 +288,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } // end of if(file_exists) diff --git a/enrol/imsenterprise/enrol.php b/enrol/imsenterprise/enrol.php index 4c15a88dd11b7..db1e9134aca7f 100644 --- a/enrol/imsenterprise/enrol.php +++ b/enrol/imsenterprise/enrol.php @@ -389,7 +389,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); $this->log_line('Notification email sent to administrator.'); diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 98300e277dd74..67b5a02dce2aa 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -330,7 +330,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } } @@ -355,7 +355,7 @@ function cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } } diff --git a/enrol/paypal/ipn.php b/enrol/paypal/ipn.php index 5cc24f3fa6cfa..b0c22dd227235 100644 --- a/enrol/paypal/ipn.php +++ b/enrol/paypal/ipn.php @@ -118,7 +118,7 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); message_paypal_error_to_admin("Payment pending", $data); die; @@ -203,7 +203,7 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } @@ -220,7 +220,7 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } if (!empty($CFG->enrol_mailadmins)) { @@ -237,7 +237,7 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } @@ -277,7 +277,7 @@ function message_paypal_error_to_admin($subject, $data) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } diff --git a/error/index.php b/error/index.php index bf7f1c93c86af..3642da0a88c3e 100644 --- a/error/index.php +++ b/error/index.php @@ -31,7 +31,7 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); redirect($CFG->wwwroot .'/course/', 'Message sent, thanks', 3); exit; diff --git a/lib/adminlib.php b/lib/adminlib.php index df3848cdd16dc..5e0562987f3df 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -114,7 +114,6 @@ /// Add libraries require_once($CFG->libdir.'/ddllib.php'); require_once($CFG->libdir.'/xmlize.php'); -require_once($CFG->libdir.'/messagelib.php'); // Messagelib functions define('INSECURE_DATAROOT_WARNING', 1); define('INSECURE_DATAROOT_ERROR', 2); diff --git a/lib/db/events.php b/lib/db/events.php index b7751cb173aa6..f90e4065d4bc6 100644 --- a/lib/db/events.php +++ b/lib/db/events.php @@ -31,23 +31,6 @@ $handlers = array ( -/* Messaging required parameters (object): - * modulename - - * userfrom - * userto - * subject - * fullmessage - the full message in a given format - * fullmessageformat - the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..) - * fullmessagehtml - the full version (the message processor will choose with one to use) - * smallmessage - the small version of the message - */ - - 'message_send' => array ( - 'handlerfile' => '/lib/messagelib.php', - 'handlerfunction' => 'message_send_handler', - 'schedule' => 'instant' - ), - /* * portfolio queued event - for non interactive file transfers */ diff --git a/lib/messagelib.php b/lib/messagelib.php index 58a5d23c111c1..ec2d3f28abd42 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -18,28 +18,40 @@ /** * messagelib.php - Contains generic messaging functions for the message system * - * @package moodlecore + * @package moodlecore * @copyright Luis Rodrigues and Martin Dougiamas * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** TIMETOSHOWUSERS = 300 */ -define('TIMETOSHOWUSERS', 300); - /** - * Triggered when a message provider wants to send a message. + * Called when a message provider wants to send a message. * This functions checks the user's processor configuration to send the given type of message, * then tries to send it. - * @param object $eventdata information about the message (origin, destination, type, content) + * + * Required parameter $eventdata structure: + * modulename - + * userfrom + * userto + * subject + * fullmessage - the full message in a given format + * fullmessageformat - the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..) + * fullmessagehtml - the full version (the message processor will choose with one to use) + * smallmessage - the small version of the message + * + * @param object $eventdata information about the message (modulename, userfrom, userto, ...) * @return boolean success */ -function message_send_handler($eventdata){ +function message_send($eventdata) { global $CFG, $DB; + //TODO: this function is very slow and inefficient, it would be a major bottleneck in cron processing, this has to be improved in 2.0 + // probably we could add two parameters with user messaging preferences and we could somehow preload/cache them in cron + //TODO: we need to solve problems with database transactions here somehow + if (isset($CFG->block_online_users_timetosee)) { $timetoshowusers = $CFG->block_online_users_timetosee * 60; } else { - $timetoshowusers = TIMETOSHOWUSERS; + $timetoshowusers = 300; } /// Work out if the user is logged in or not @@ -64,19 +76,19 @@ function message_send_handler($eventdata){ /// When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned $processor = get_user_preferences('message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate, NULL, $eventdata->userto->id); - if ($processor == NULL){ //this user never had a preference, save default - if (!message_set_default_message_preferences( $eventdata->userto )){ + if ($processor == NULL) { //this user never had a preference, save default + if (!message_set_default_message_preferences($eventdata->userto)) { print_error('cannotsavemessageprefs', 'message'); } - if ( $userstate == 'loggedin'){ - $processor='popup'; + if ($userstate == 'loggedin') { + $processor = 'popup'; } - if ( $userstate == 'loggedoff'){ - $processor='email'; + if ($userstate == 'loggedoff') { + $processor = 'email'; } } - //if we are suposed to do something with this message + // if we are suposed to do something with this message // No processor for this message, mark it as read if ($processor == "") { //this user cleared all the preferences $savemessage->timeread = time(); @@ -94,13 +106,13 @@ function message_send_handler($eventdata){ $processorfile = $CFG->dirroot. '/message/output/'.$procname.'/message_output_'.$procname.'.php'; if (is_readable($processorfile)) { - include_once( $processorfile ); // defines $module with version etc + include_once($processorfile); // defines $module with version etc $processclass = 'message_output_' . $procname; if (class_exists($processclass)) { $pclass = new $processclass(); - if (! $pclass->send_message($savemessage)) { + if (!$pclass->send_message($savemessage)) { debugging('Error calling message processor '.$procname); return false; } @@ -141,8 +153,8 @@ function message_update_providers($component='moodle') { } else { // Update existing one $provider = new object(); - $provider->id = $dbproviders[$messagename]->id; - $provider->capability = $fileprovider['capability']; + $provider->id = $dbproviders[$messagename]->id; + $provider->capability = $fileprovider['capability']; $DB->update_record('message_providers', $provider); unset($dbproviders[$messagename]); continue; @@ -199,12 +211,7 @@ function message_get_my_providers() { function message_get_providers_from_db($component) { global $DB; - if ($dbproviders = $DB->get_records('message_providers', array('component'=>$component), '', - 'name, id, component, capability')) { // Name is unique per component - return $dbproviders; - } - - return array(); + return $DB->get_records('message_providers', array('component'=>$component), '', 'name, id, component, capability'); // Name is unique per component } /** @@ -245,14 +252,14 @@ function message_uninstall($component) { * Set default message preferences. * @param $user - User to set message preferences */ -function message_set_default_message_preferences( $user ) { +function message_set_default_message_preferences($user) { global $DB; $providers = $DB->get_records('message_providers'); $preferences = array(); - foreach ( $providers as $providerid => $provider){ - $preferences[ 'message_provider_'.$provider->component.'_'.$provider->name.'_loggedin' ] = 'popup'; - $preferences[ 'message_provider_'.$provider->component.'_'.$provider->name.'_loggedoff' ] = 'email'; + foreach ($providers as $providerid => $provider) { + $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedin'] = 'popup'; + $preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedoff'] = 'email'; } - return set_user_preferences( $preferences, $user->id ); + return set_user_preferences($preferences, $user->id); } diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index dcd0db2b27e10..61db888f5f9b7 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -994,6 +994,6 @@ function portfolio_insane_notify_admins($insane, $instances=false) { $eventdata->fullmessagehtml = $htmlbody; $eventdata->smallmessage = $smallbody; error_log(print_r($eventdata, true)); - events_trigger('message_send', $eventdata); + message_send($eventdata); } } diff --git a/lib/setup.php b/lib/setup.php index 45e2f5cd07314..1478abbba4478 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -261,6 +261,7 @@ require_once($CFG->libdir .'/grouplib.php'); // Groups functions require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes +require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else //the problem is that we need specific version of quickforms and hacked excel files :-( diff --git a/lib/uploadlib.php b/lib/uploadlib.php index 91f36ca8547c4..9adb5561855c2 100644 --- a/lib/uploadlib.php +++ b/lib/uploadlib.php @@ -746,7 +746,7 @@ function clam_message_admins($notice) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - events_trigger('message_send', $eventdata); + message_send($eventdata); } } diff --git a/message/edit.php b/message/edit.php index d3cc1ac9338c7..104689b355e14 100644 --- a/message/edit.php +++ b/message/edit.php @@ -24,7 +24,6 @@ */ require_once('../config.php'); -require_once($CFG->libdir.'/messagelib.php'); $userid = optional_param('id', $USER->id, PARAM_INT); // user id $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) diff --git a/message/lib.php b/message/lib.php index 29a04c362b247..a62fec30c9089 100644 --- a/message/lib.php +++ b/message/lib.php @@ -1023,7 +1023,7 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; $eventdata->timecreated = time(); - return events_trigger('message_send', $eventdata); + return message_send($eventdata); } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 0584d17bd41dd..82d041eb23198 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1681,8 +1681,7 @@ function email_teachers($submission) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0 ){ - } + message_send($eventdata); } } } @@ -2351,9 +2350,7 @@ function assignment_cron () { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0 ){ - echo "Error: assignment cron: Could not send out mail for id $submission->id to user $user->id ($user->email)\n"; - } + message_send($eventdata); } cron_setup_user(); diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 60b74b6382bb5..862df6eb5d45b 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -2180,8 +2180,7 @@ function feedback_send_email($cm, $feedback, $course, $userid) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0 ){ - } + message_send($eventdata); }else { $eventdata = new object(); $eventdata->modulename = 'feedback'; @@ -2192,8 +2191,7 @@ function feedback_send_email($cm, $feedback, $course, $userid) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0 ){ - } + message_send($eventdata); } } } @@ -2244,8 +2242,7 @@ function feedback_send_email_anonym($cm, $feedback, $course) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0 ){ - } + message_send($eventdata); } } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f7af02e7d0e1c..e9d49704d1394 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -613,7 +613,7 @@ function forum_cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0){ + if (!message_send($eventdata)){ mtrace("Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id". " ($userto->email) .. not trying again."); @@ -907,7 +907,7 @@ function forum_cron() { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) > 0){ + if (!message_send($eventdata)){ mtrace("ERROR!"); echo "Error: mod/forum/cron.php: Could not send out digest mail to user $userto->id ($userto->email)... not trying again.\n"; add_to_log($course->id, 'forum', 'mail digest error', '', '', $cm->id, $userto->id); diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index 45629aeccd33f..9bff13759adbc 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -228,15 +228,12 @@ $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $message; $eventdata->smallmessage = ''; - if ( events_trigger('message_send', $eventdata) == 0){ - $essayinfo->sent = 1; - $attempt->useranswer = serialize($essayinfo); - $DB->update_record('lesson_attempts', $attempt); - // Log it - add_to_log($course->id, 'lesson', 'update email essay grade', "essay.php?id=$cm->id", format_string($pages[$attempt->pageid]->title,true).': '.fullname($users[$attempt->userid]), $cm->id); - } else { - print_error('emailfail'); - } + message_send($eventdata); + $essayinfo->sent = 1; + $attempt->useranswer = serialize($essayinfo); + $DB->update_record('lesson_attempts', $attempt); + // Log it + add_to_log($course->id, 'lesson', 'update email essay grade', "essay.php?id=$cm->id", format_string($pages[$attempt->pageid]->title,true).': '.fullname($users[$attempt->userid]), $cm->id); } } lesson_set_message(get_string('emailsuccess', 'lesson'), 'notifysuccess'); diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 209d69fbe1a7b..0dfc81820abf8 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1026,7 +1026,7 @@ function quiz_send_confirmation($a) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - return (events_trigger('message_send', $eventdata) == 0); + return message_send($eventdata); } /** @@ -1060,7 +1060,7 @@ function quiz_send_notification($recipient, $a) { $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = ''; $eventdata->smallmessage = ''; - return (events_trigger('message_send', $eventdata) == 0); + return message_send($eventdata); } /** diff --git a/user/editadvanced.php b/user/editadvanced.php index 9b34f02dea638..7f5dfac72143f 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -29,7 +29,6 @@ require_once($CFG->dirroot.'/user/editadvanced_form.php'); require_once($CFG->dirroot.'/user/editlib.php'); require_once($CFG->dirroot.'/user/profile/lib.php'); -require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions httpsrequired();