@@ -337,10 +337,14 @@ public function rejectSubmission()
337337
338338 public function sendReviewerNotificationEmail ($ submission )
339339 {
340+ Workflow::log ('Preparing reviewer notification. ' );
341+
340342 $ reviewerUserGroup = $ this ->getNextReviewerUserGroup ($ submission );
341343
342344 // If there is no next reviewer user group then send publisher notification email
343345 if ($ reviewerUserGroup === null ) {
346+ Workflow::log ('No reviewer user groups. Send publisher email. ' );
347+
344348 $ this ->sendPublisherNotificationEmail ($ submission );
345349
346350 return ;
@@ -350,6 +354,10 @@ public function sendReviewerNotificationEmail($submission)
350354 ->groupId ($ reviewerUserGroup ->id )
351355 ->all ();
352356
357+ if (!$ reviewers ) {
358+ Workflow::log ('No reviewers found to send notifications to. ' );
359+ }
360+
353361 foreach ($ reviewers as $ key => $ user ) {
354362 try {
355363 $ mail = Craft::$ app ->getMailer ()
@@ -368,19 +376,25 @@ public function sendReviewerNotificationEmail($submission)
368376
369377 Workflow::log ('Sent reviewer notification to ' . $ user ->email );
370378 } catch (\Throwable $ e ) {
371- Workflow::log ('Failed to send reviewer notification to ' . $ user ->email . ' - ' . $ e ->getMessage ());
379+ Workflow::error (Craft::t ('workflow ' , 'Failed to send reviewer notification to {value} - “{message}” {file}:{line} ' , [
380+ 'value ' => $ user ->email ,
381+ 'message ' => $ e ->getMessage (),
382+ 'file ' => $ e ->getFile (),
383+ 'line ' => $ e ->getLine (),
384+ ]));
372385 }
373386 }
374387 }
375388
376389 public function sendPublisherNotificationEmail ($ submission )
377390 {
391+ Workflow::log ('Preparing publisher notification. ' );
392+
378393 $ settings = Workflow::$ plugin ->getSettings ();
379394
380395 $ groupId = Db::idByUid (Table::USERGROUPS , $ settings ->publisherUserGroup );
381396
382- $ query = User::find ()
383- ->groupId ($ groupId );
397+ $ query = User::find ()->groupId ($ groupId );
384398
385399 // Check settings to see if we should email all publishers or not
386400 if (isset ($ settings ->selectedPublishers )) {
@@ -391,6 +405,10 @@ public function sendPublisherNotificationEmail($submission)
391405
392406 $ publishers = $ query ->all ();
393407
408+ if (!$ publishers ) {
409+ Workflow::log ('No publishers found to send notifications to. ' );
410+ }
411+
394412 foreach ($ publishers as $ key => $ user ) {
395413 try {
396414 $ mail = Craft::$ app ->getMailer ()
@@ -409,7 +427,12 @@ public function sendPublisherNotificationEmail($submission)
409427
410428 Workflow::log ('Sent publisher notification to ' . $ user ->email );
411429 } catch (\Throwable $ e ) {
412- Workflow::log ('Failed to send publisher notification to ' . $ user ->email . ' - ' . $ e ->getMessage ());
430+ Workflow::error (Craft::t ('workflow ' , 'Failed to send publisher notification to {value} - “{message}” {file}:{line} ' , [
431+ 'value ' => $ user ->email ,
432+ 'message ' => $ e ->getMessage (),
433+ 'file ' => $ e ->getFile (),
434+ 'line ' => $ e ->getLine (),
435+ ]));
413436 }
414437 }
415438 }
@@ -422,69 +445,79 @@ public function sendPublisherNotificationEmail($submission)
422445 */
423446 public function sendEditorNotificationEmail ($ submission , Review $ review = null )
424447 {
448+ Workflow::log ('Preparing editor notification. ' );
449+
425450 $ settings = Workflow::$ plugin ->getSettings ();
426451
427452 $ editor = User::find ()
428453 ->id ($ submission ->editorId )
429454 ->one ();
430455
431456 // Only send to the single user editor - not the whole group
432- if ($ editor ) {
433- try {
434- $ mail = Craft::$ app ->getMailer ()->setTo ($ editor );
435-
436- if ($ review === null ) {
437- $ mail ->composeFromKey ('workflow_editor_notification ' , ['submission ' => $ submission ]);
438- } else {
439- $ mail ->composeFromKey ('workflow_editor_review_notification ' , [
440- 'submission ' => $ submission ,
441- 'review ' => $ review ,
442- ]);
443- }
457+ if (!$ editor ) {
458+ Workflow::error ('Unable to find editor # ' . $ submission ->editorId );
444459
445- if (!is_array ($ settings ->editorNotificationsOptions )) {
446- $ settings ->editorNotificationsOptions = [];
447- }
460+ return ;
461+ }
448462
449- if ($ review === null ) {
450- if ($ submission ->publisher ) {
451- if (in_array ('replyTo ' , $ settings ->editorNotificationsOptions )) {
452- $ mail ->setReplyTo ($ submission ->publisher ->email );
453- }
463+ try {
464+ $ mail = Craft::$ app ->getMailer ()->setTo ($ editor );
454465
455- if (in_array ('cc ' , $ settings ->editorNotificationsOptions )) {
456- $ mail ->setCc ($ submission ->publisher ->email );
457- }
466+ if ($ review === null ) {
467+ $ mail ->composeFromKey ('workflow_editor_notification ' , ['submission ' => $ submission ]);
468+ } else {
469+ $ mail ->composeFromKey ('workflow_editor_review_notification ' , [
470+ 'submission ' => $ submission ,
471+ 'review ' => $ review ,
472+ ]);
473+ }
474+
475+ if (!is_array ($ settings ->editorNotificationsOptions )) {
476+ $ settings ->editorNotificationsOptions = [];
477+ }
478+
479+ if ($ review === null ) {
480+ if ($ submission ->publisher ) {
481+ if (in_array ('replyTo ' , $ settings ->editorNotificationsOptions )) {
482+ $ mail ->setReplyTo ($ submission ->publisher ->email );
483+ }
484+
485+ if (in_array ('cc ' , $ settings ->editorNotificationsOptions )) {
486+ $ mail ->setCc ($ submission ->publisher ->email );
458487 }
459488 }
460- else {
461- $ reviewer = $ submission ->getLastReviewer ();
489+ } else {
490+ $ reviewer = $ submission ->getLastReviewer ();
462491
463- if ($ reviewer !== null ) {
464- if (in_array ('replyToReviewer ' , $ settings ->editorNotificationsOptions )) {
465- $ mail ->setReplyTo ($ reviewer ->email );
466- }
492+ if ($ reviewer !== null ) {
493+ if (in_array ('replyToReviewer ' , $ settings ->editorNotificationsOptions )) {
494+ $ mail ->setReplyTo ($ reviewer ->email );
495+ }
467496
468- if (in_array ('ccReviewer ' , $ settings ->editorNotificationsOptions )) {
469- $ mail ->setCc ($ reviewer ->email );
470- }
497+ if (in_array ('ccReviewer ' , $ settings ->editorNotificationsOptions )) {
498+ $ mail ->setCc ($ reviewer ->email );
471499 }
472500 }
501+ }
473502
474- // Fire a 'beforeSendEditorEmail' event
475- if ($ this ->hasEventHandlers (self ::EVENT_BEFORE_SEND_EDITOR_EMAIL )) {
476- $ this ->trigger (self ::EVENT_BEFORE_SEND_EDITOR_EMAIL , new EmailEvent ([
477- 'mail ' => $ mail ,
478- 'user ' => $ editor ,
479- ]));
480- }
503+ // Fire a 'beforeSendEditorEmail' event
504+ if ($ this ->hasEventHandlers (self ::EVENT_BEFORE_SEND_EDITOR_EMAIL )) {
505+ $ this ->trigger (self ::EVENT_BEFORE_SEND_EDITOR_EMAIL , new EmailEvent ([
506+ 'mail ' => $ mail ,
507+ 'user ' => $ editor ,
508+ ]));
509+ }
481510
482- $ mail ->send ();
511+ $ mail ->send ();
483512
484- Workflow::log ('Sent editor notification to ' . $ editor ->email );
485- } catch (\Throwable $ e ) {
486- Workflow::log ('Failed to send editor notification to ' . $ editor ->email . ' - ' . $ e ->getMessage ());
487- }
513+ Workflow::log ('Sent editor notification to ' . $ editor ->email );
514+ } catch (\Throwable $ e ) {
515+ Workflow::error (Craft::t ('workflow ' , 'Failed to send editor notification to {value} - “{message}” {file}:{line} ' , [
516+ 'value ' => $ editor ->email ,
517+ 'message ' => $ e ->getMessage (),
518+ 'file ' => $ e ->getFile (),
519+ 'line ' => $ e ->getLine (),
520+ ]));
488521 }
489522 }
490523
0 commit comments