@@ -1153,28 +1153,6 @@ function rlip_get_notification_emails($plugin) {
11531153 return array_values ($ result );
11541154}
11551155
1156- /**
1157- * Obtain an object that we can use as the target user in email_to_user
1158- *
1159- * @param string $email Email of the target recipient
1160- * @return object A user object, either from the db, or a simulated user record
1161- * for non-moodle emails
1162- */
1163- function rlip_get_email_recipient ($ email ) {
1164- global $ DB ;
1165-
1166- if ($ result = $ DB ->get_record ('user ' , array ('email ' => $ email ))) {
1167- //user exists, so use their user record
1168- return $ result ;
1169- }
1170-
1171- //fake user record for non-moodle recipient
1172- $ result = new stdClass ;
1173- $ result ->email = $ email ;
1174-
1175- return $ result ;
1176- }
1177-
11781156/**
11791157 * Send a log email to a specific recipient
11801158 *
@@ -1204,7 +1182,7 @@ function rlip_send_log_email($plugin, $recipient, $archive_name) {
12041182 * @param boolean $manual True if manual, false if scheduled
12051183 */
12061184function rlip_send_log_emails ($ plugin , $ logids , $ manual = false ) {
1207- global $ CFG ;
1185+ global $ CFG , $ USER ;
12081186
12091187 //obtain the sanitized list of emails
12101188 $ emails = rlip_get_notification_emails ($ plugin );
@@ -1216,14 +1194,21 @@ function rlip_send_log_emails($plugin, $logids, $manual = false) {
12161194 return false ;
12171195 }
12181196
1219- //send to all appropriate users
1197+ // send to all appropriate users
1198+ // A valid $user->id & all other fields now required by Moodle 2.6+ email_to_user() API which also calls fullname($user).
1199+ $ duser = new stdClass ;
1200+ $ allfields = get_all_user_name_fields ();
1201+ foreach ($ allfields as $ field ) {
1202+ $ duser ->$ field = null ;
1203+ }
1204+ $ duser ->id = $ USER ->id ; // let's just use this user as default (TBD)
1205+ $ duser ->mailformat = 1 ;
12201206 foreach ($ emails as $ email ) {
1221- $ recipient = rlip_get_email_recipient ($ email );
1222- rlip_send_log_email ($ plugin , $ recipient , $ archive_name );
1207+ $ duser -> email = trim ($ email );
1208+ rlip_send_log_email ($ plugin , $ duser , $ archive_name );
12231209 }
12241210
12251211 @unlink ($ CFG ->dataroot .'/ ' .$ archive_name );
1226-
12271212 return true ;
12281213}
12291214
0 commit comments