Skip to content

Commit

Permalink
pkp#9991 additional logs for reviewer emails
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Sep 23, 2024
1 parent 191f9ed commit 8989b08
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
22 changes: 18 additions & 4 deletions classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\log\event\PKPSubmissionEventLogEntry;
use PKP\log\SubmissionEmailLogEventType;
use PKP\mail\Mailable;
use PKP\mail\mailables\ReviewerReinstate;
use PKP\mail\mailables\ReviewerResendRequest;
Expand Down Expand Up @@ -560,7 +561,10 @@ public function updateReinstateReviewer($args, $request)
$context = app()->get('context')->get($submission->getData('contextId'));
$template = Repo::emailTemplate()->getByKey($context->getId(), ReviewerReinstate::getEmailTemplateKey());
$mailable = new ReviewerReinstate($context, $submission, $reviewAssignment);
$this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer);

if($this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer)) {
Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_REINSTATED, $mailable, $submission, $user);
}
}

$json = DAO::getDataChangedEvent($reviewAssignment->getId());
Expand Down Expand Up @@ -616,7 +620,10 @@ public function updateResendRequestReviewer($args, $request)
$context = $request->getContext();
$template = Repo::emailTemplate()->getByKey($context->getId(), ReviewerResendRequest::getEmailTemplateKey());
$mailable = new ReviewerResendRequest($context, $submission, $reviewAssignment);
$this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer);

if($this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer)) {
Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_RESEND, $mailable, $submission, $user);
}
}

$json = DAO::getDataChangedEvent($reviewAssignment->getId());
Expand Down Expand Up @@ -652,7 +659,10 @@ public function updateUnassignReviewer($args, $request)
$context = app()->get('context')->get($submission->getData('contextId'));
$template = Repo::emailTemplate()->getByKey($context->getId(), ReviewerUnassign::getEmailTemplateKey());
$mailable = new ReviewerUnassign($context, $submission, $reviewAssignment);
$this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer);

if($this->createMail($mailable, $request->getUserVar('personalMessage'), $template, $user, $reviewer)) {
Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_CANCEL, $mailable, $submission, $user);
}
}

$json = DAO::getDataChangedEvent($reviewAssignment->getId());
Expand Down Expand Up @@ -1194,7 +1204,7 @@ protected function _getAuthorDeniedAnonymousOps()
/**
* Creates and sends email to the reviewer
*/
protected function createMail(Mailable $mailable, string $emailBody, EmailTemplate $template, User $sender, User $reviewer): void
protected function createMail(Mailable $mailable, string $emailBody, EmailTemplate $template, User $sender, User $reviewer): bool
{
if ($subject = $template->getLocalizedData('subject')) {
$mailable->subject($subject);
Expand All @@ -1207,6 +1217,8 @@ protected function createMail(Mailable $mailable, string $emailBody, EmailTempla

try {
Mail::send($mailable);

return true;
} catch (TransportException $e) {
$notificationMgr = new PKPNotificationManager();
$notificationMgr->createTrivialNotification(
Expand All @@ -1216,6 +1228,8 @@ protected function createMail(Mailable $mailable, string $emailBody, EmailTempla
);
trigger_error($e->getMessage(), E_USER_WARNING);
}

return false;
}
}

Expand Down
3 changes: 3 additions & 0 deletions classes/decision/types/traits/NotifyReviewers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PKP\core\Core;
use PKP\core\PKPApplication;
use PKP\log\event\PKPSubmissionEventLogEntry;
use PKP\log\SubmissionEmailLogEventType;
use PKP\mail\EmailData;
use PKP\mail\mailables\DecisionNotifyReviewer;
use PKP\mail\mailables\ReviewerUnassign;
Expand Down Expand Up @@ -60,6 +61,8 @@ protected function sendReviewersEmail(DecisionNotifyReviewer|ReviewerUnassign $m
]);
}
}

Repo::emailLogEntry()->logMailable(is_a($mailable, DecisionNotifyReviewer::class) ? SubmissionEmailLogEventType::REVIEW_NOTIFY_REVIEWER : SubmissionEmailLogEventType::REVIEW_EDIT_NOTIFY_REVIEWER, $mailable, $submission, $editor);
}

$eventLog = Repo::eventLog()->newDataObject([
Expand Down
5 changes: 5 additions & 0 deletions classes/log/SubmissionEmailLogEventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ enum SubmissionEmailLogEventType: int implements EmailLogEventType
case REVIEW_CONFIRM_ACK = 0x40000008;
case REVIEW_REQUEST = 0x40000009;
case REVIEW_REQUEST_SUBSEQUENT = 0x4000000A;
case REVIEW_REMIND_AUTO = 0x4000000B;
case REVIEW_COMPLETE = 0x4000000C;
case REVIEW_REINSTATED = 0x4000000D;
case REVIEW_RESEND = 0x4000000E;
case REVIEW_EDIT_NOTIFY_REVIEWER = 0x4000000F;

// Copyeditor events 0x50000000
case COPYEDIT_NOTIFY_COPYEDITOR = 0x50000001;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\log\event\PKPSubmissionEventLogEntry;
use PKP\log\SubmissionEmailLogEventType;
use PKP\mail\mailables\ReviewCompleteNotifyEditors;
use PKP\notification\Notification;
use PKP\notification\NotificationSubscriptionSettingsDAO;
Expand Down Expand Up @@ -231,6 +232,7 @@ public function execute(...$functionParams)
->allowUnsubscribe($notification);

Mail::send($mailable);
Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_COMPLETE, $mailable, $submission, $user);

$receivedList[] = $userId;
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/grid/users/reviewer/form/EditReviewForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\form\Form;
use PKP\log\SubmissionEmailLogEventType;
use PKP\mail\mailables\EditReviewNotify;
use PKP\notification\Notification;
use PKP\notification\NotificationSubscriptionSettingsDAO;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __construct(ReviewAssignment $reviewAssignment, Submission $subm
// Validation checks for this form
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'responseDueDate', 'required', 'editor.review.errorAddingReviewer'));
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'reviewDueDate', 'required', 'editor.review.errorAddingReviewer'));

$this->addCheck(
new \PKP\form\validation\FormValidatorDateCompare(
$this,
Expand Down Expand Up @@ -226,6 +227,7 @@ public function execute(...$functionArgs)
->allowUnsubscribe($notification);

Mail::send($mailable);
Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_EDIT_NOTIFY_REVIEWER, $mailable, $this->submission, $request->getUser());
}
}

Expand Down
7 changes: 5 additions & 2 deletions jobs/email/ReviewReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PKP\core\PKPApplication;
use PKP\core\Core;
use PKP\invitation\invitations\ReviewerAccessInvite;
use PKP\log\SubmissionEmailLogEventType;
use PKP\mail\mailables\ReviewResponseRemindAuto;
use PKP\mail\mailables\ReviewRemindAuto;
use PKP\jobs\BaseJob;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function handle(): void
}

$submission = Repo::submission()->get($reviewAssignment->getData('submissionId'));

$contextService = app()->get('context');
$context = $contextService->get($this->contextId);

Expand All @@ -59,7 +60,7 @@ public function handle(): void

$primaryLocale = $context->getPrimaryLocale();
$emailTemplate = Repo::emailTemplate()->getByKey(
$context->getId(),
$context->getId(),
$mailable::getEmailTemplateKey()
);

Expand Down Expand Up @@ -96,6 +97,8 @@ public function handle(): void
'reminderWasAutomatic' => 1
]);

Repo::emailLogEntry()->logMailable(SubmissionEmailLogEventType::REVIEW_REMIND_AUTO, $mailable, $submission);

$eventLog = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $submission->getId(),
Expand Down

0 comments on commit 8989b08

Please sign in to comment.