@@ -1153,28 +1153,6 @@ function rlip_get_notification_emails($plugin) {
1153
1153
return array_values ($ result );
1154
1154
}
1155
1155
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
-
1178
1156
/**
1179
1157
* Send a log email to a specific recipient
1180
1158
*
@@ -1204,7 +1182,7 @@ function rlip_send_log_email($plugin, $recipient, $archive_name) {
1204
1182
* @param boolean $manual True if manual, false if scheduled
1205
1183
*/
1206
1184
function rlip_send_log_emails ($ plugin , $ logids , $ manual = false ) {
1207
- global $ CFG ;
1185
+ global $ CFG , $ USER ;
1208
1186
1209
1187
//obtain the sanitized list of emails
1210
1188
$ emails = rlip_get_notification_emails ($ plugin );
@@ -1216,14 +1194,21 @@ function rlip_send_log_emails($plugin, $logids, $manual = false) {
1216
1194
return false ;
1217
1195
}
1218
1196
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 ;
1220
1206
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 );
1223
1209
}
1224
1210
1225
1211
@unlink ($ CFG ->dataroot .'/ ' .$ archive_name );
1226
-
1227
1212
return true ;
1228
1213
}
1229
1214
0 commit comments