@@ -137,7 +137,7 @@ public static function moodleoverflow_send_mails(): bool {
137
137
$ discussions , $ posts , $ authors , $ recipients );
138
138
139
139
// Set up the user that receives the mail.
140
- $ CFG ->branch >= 402 ? cron::setup_user ($ recipients [$ record ->usertoid ]): cron_setup_user ($ recipients [$ record ->usertoid ]);
140
+ $ CFG ->branch >= 402 ? cron::setup_user ($ recipients [$ record ->usertoid ]) : cron_setup_user ($ recipients [$ record ->usertoid ]);
141
141
142
142
// Check if the user can see the post.
143
143
if (!moodleoverflow_user_can_see_post ($ moodleoverflows [$ record ->moodleoverflowid ], $ discussions [$ record ->discussionid ],
@@ -147,14 +147,14 @@ public static function moodleoverflow_send_mails(): bool {
147
147
}
148
148
149
149
// Determine if the author should be anonymous.
150
- $ authoranonymous = match ($ record ->moodleoverflowanonymous ) {
150
+ $ authoranonymous = match (( int ) $ record ->moodleoverflowanonymous ) {
151
151
anonymous::NOT_ANONYMOUS => false ,
152
152
anonymous::EVERYTHING_ANONYMOUS => true ,
153
153
anonymous::QUESTION_ANONYMOUS => ($ record ->discussionuserid == $ record ->authorid )
154
154
};
155
155
156
156
// Set the userfrom variable, that is anonymous or the post author.
157
- $ authoranonymous ? $ userfrom = core_user::get_noreply_user (): $ userfrom = clone ($ authors [$ record ->authorid ]);
157
+ $ authoranonymous ? $ userfrom = core_user::get_noreply_user () : $ userfrom = clone ($ authors [$ record ->authorid ]);
158
158
$ userfrom ->anonymous = $ authoranonymous ;
159
159
160
160
// Cache the recipients capabilities to view full names for the moodleoverflow instance.
@@ -200,7 +200,7 @@ public static function moodleoverflow_send_mails(): bool {
200
200
// Build the mail object.
201
201
$ email = new moodleoverflow_email (
202
202
$ courses [$ record ->courseid ],
203
- $ coursemodules [$ record ->moodleoverflowid ],
203
+ $ coursemodules [$ record ->cmid ],
204
204
$ moodleoverflows [$ record ->moodleoverflowid ],
205
205
$ discussions [$ record ->discussionid ],
206
206
$ posts [$ record ->postid ],
@@ -262,13 +262,11 @@ public static function moodleoverflow_send_mails(): bool {
262
262
$ smallmessage , $ record ->usertolang );
263
263
264
264
// Finally: send the notification mail.
265
- var_dump ("Finally " );
266
265
$ mailsent = message_send ($ emailmessage );
267
-
268
266
// Check if an error occurred and mark the post as mailed_error.
269
267
if (!$ mailsent ) {
270
268
mtrace ('Error: mod/moodleoverflow/classes/manager/mail_manager.php moodleoverflow_send_mails(): ' .
271
- 'Could not send out mail for id $record->postid to user $record->usertoid ($record->usertoemail). ' .
269
+ 'Could not send out mail for id $record->postid to user $record->usertoid ($record->usertoemail). ' .
272
270
' ... not trying again. ' );
273
271
$ DB ->set_field ('moodleoverflow_posts ' , 'mailed ' , MOODLEOVERFLOW_MAILED_ERROR , ['id ' => $ record ->postid ]);
274
272
} else {
@@ -299,7 +297,7 @@ public static function moodleoverflow_send_mails(): bool {
299
297
public static function moodleoverflow_get_unmailed_posts ($ starttime , $ endtime ): array {
300
298
global $ DB ;
301
299
302
- // Define fields that will be get from the database.
300
+ // Define fields that will be retrieved from the database.
303
301
$ postfields = "p.id AS postid, p.message AS postmessage, p.messageformat as postmessageformat, p.modified as postmodified,
304
302
p.parent AS postparent, p.userid AS postuserid, p.reviewed AS postreviewed " ;
305
303
$ discussionfields = "d.id AS discussionid, d.name AS discussionname, d.userid AS discussionuserid,
@@ -315,7 +313,8 @@ public static function moodleoverflow_get_unmailed_posts($starttime, $endtime):
315
313
author.picture AS authorpicture, author.imagealt AS authorimagealt, author.email AS authoremail " ;
316
314
$ usertofields = "userto.id AS usertoid, userto.maildigest AS usertomaildigest, userto.description AS usertodescription,
317
315
userto.password AS usertopassword, userto.lang AS usertolang, userto.auth AS usertoauth,
318
- userto.suspended AS usertosuspended, userto.deleted AS usertodeleted, userto.emailstop AS usertoemailstop " ;
316
+ userto.suspended AS usertosuspended, userto.deleted AS usertodeleted, userto.emailstop AS usertoemailstop,
317
+ userto.email AS usertoemail, userto.username AS usertousername " ;
319
318
320
319
$ fields = "(ROW_NUMBER() OVER (ORDER BY p.modified)) AS row_num, " . $ postfields . ", " . $ discussionfields . ", "
321
320
. $ moodleoverflowfields . ", " . $ coursefields . ", " . $ cmfields . ", " . $ authorfields . ", " . $ usertofields ;
@@ -402,15 +401,24 @@ public static function moodleoverflow_update_mail_caches(object $record, array &
402
401
'picture ' => 'authorpicture ' , 'imagealt ' => 'authorimagealt ' , 'email ' => 'authoremail ' ],
403
402
'recipients ' => ['id ' => 'usertoid ' , 'description ' => 'usertodescription ' , 'password ' => 'usertopassword ' ,
404
403
'lang ' => 'usertolang ' , 'auth ' => 'usertoauth ' , 'suspended ' => 'usertosuspended ' ,
405
- 'deleted ' => 'usertodeleted ' , 'emailstop ' => 'usertoemailstop ' , 'viewfullnames ' => [] ,
406
- 'canpost ' => [] ],
404
+ 'deleted ' => 'usertodeleted ' , 'emailstop ' => 'usertoemailstop ' , 'email ' => ' usertoemail ' ,
405
+ 'username ' => ' usertousername ' ],
407
406
];
408
407
409
408
// Iterate over cache types and update caches if not already set.
410
409
foreach ($ cachetypes as $ cachename => $ properties ) {
411
410
$ cachekey = $ record ->{$ properties ['id ' ]};
412
411
if (!isset ($ {$ cachename }[$ cachekey ])) {
413
- $ {$ cachename }[$ cachekey ] = (object ) array_map (fn ($ prop ) => $ record ->{$ prop }, $ properties );
412
+ $ obj = new stdClass ();
413
+ foreach ($ properties as $ propname => $ recordkey ) {
414
+ $ obj ->$ propname = $ record ->$ recordkey ;
415
+ }
416
+ // Only for recipients, add empty arrays for viewfullnames and canpost.
417
+ if ($ cachename === 'recipients ' ) {
418
+ $ obj ->viewfullnames = [];
419
+ $ obj ->canpost = [];
420
+ }
421
+ $ {$ cachename }[$ cachekey ] = $ obj ;
414
422
}
415
423
}
416
424
}
0 commit comments