From 8d7d4c7936dcfa1e3ed002f569a2ec4c149f4cae Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Mon, 23 Sep 2024 10:28:50 -0500 Subject: [PATCH] #9991 additional logs for reviewer emails --- .../users/reviewer/PKPReviewerGridHandler.php | 29 ++++++++++++++++--- .../decision/types/traits/NotifyReviewers.php | 11 +++++-- classes/log/SubmissionEmailLogEntry.php | 5 ++++ .../form/PKPReviewerReviewStep3Form.php | 6 +++- classes/task/ReviewReminder.php | 5 ++++ .../users/reviewer/form/EditReviewForm.php | 6 ++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php b/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php index 579dfd1f612..6f329dd1374 100644 --- a/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php +++ b/classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php @@ -20,7 +20,6 @@ use APP\core\PageRouter; use APP\core\Request; use APP\facades\Repo; -use APP\log\event\SubmissionEventLogEntry; use APP\notification\NotificationManager; use APP\submission\Submission; use APP\template\TemplateManager; @@ -47,6 +46,8 @@ use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxModal; use PKP\log\event\PKPSubmissionEventLogEntry; +use PKP\log\SubmissionEmailLogDAO; +use PKP\log\SubmissionEmailLogEntry; use PKP\log\SubmissionLog; use PKP\mail\Mailable; use PKP\mail\mailables\ReviewerReinstate; @@ -560,7 +561,12 @@ public function updateReinstateReviewer($args, $request) $context = PKPServices::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)){ + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_REINSTATED, $mailable, $submission, $user); + } } $json = DAO::getDataChangedEvent($reviewAssignment->getId()); @@ -616,7 +622,12 @@ 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)){ + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_RESEND, $mailable, $submission, $user); + } } $json = DAO::getDataChangedEvent($reviewAssignment->getId()); @@ -653,6 +664,12 @@ public function updateUnassignReviewer($args, $request) $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)){ + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_CANCEL, $mailable, $submission, $user); + } } $json = DAO::getDataChangedEvent($reviewAssignment->getId()); @@ -1206,7 +1223,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); @@ -1219,6 +1236,8 @@ protected function createMail(Mailable $mailable, string $emailBody, EmailTempla try { Mail::send($mailable); + + return true; } catch (TransportException $e) { $notificationMgr = new PKPNotificationManager(); $notificationMgr->createTrivialNotification( @@ -1228,6 +1247,8 @@ protected function createMail(Mailable $mailable, string $emailBody, EmailTempla ); trigger_error($e->getMessage(), E_USER_WARNING); } + + return false; } } diff --git a/classes/decision/types/traits/NotifyReviewers.php b/classes/decision/types/traits/NotifyReviewers.php index 124e11a2fa6..642df333573 100644 --- a/classes/decision/types/traits/NotifyReviewers.php +++ b/classes/decision/types/traits/NotifyReviewers.php @@ -15,7 +15,6 @@ use APP\core\Application; use APP\facades\Repo; -use APP\log\event\SubmissionEventLogEntry; use APP\submission\Submission; use Illuminate\Support\Facades\Mail; use Illuminate\Validation\Validator; @@ -23,12 +22,13 @@ use PKP\core\PKPApplication; use PKP\db\DAORegistry; use PKP\log\event\PKPSubmissionEventLogEntry; +use PKP\log\SubmissionEmailLogDAO; +use PKP\log\SubmissionEmailLogEntry; use PKP\log\SubmissionLog; use PKP\mail\EmailData; use PKP\mail\mailables\DecisionNotifyReviewer; use PKP\mail\mailables\ReviewerUnassign; use PKP\security\Validation; -use PKP\submission\reviewAssignment\ReviewAssignment; use PKP\submission\reviewAssignment\ReviewAssignmentDAO; use PKP\user\User; @@ -63,6 +63,13 @@ protected function sendReviewersEmail(DecisionNotifyReviewer|ReviewerUnassign $m $reviewAssignmentDao->updateObject($reviewAssignment); } } + + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable( + is_a($mailable, DecisionNotifyReviewer::class) ? SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_NOTIFY_REVIEWER : SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_EDIT_NOTIFY_REVIEWER, + $mailable, $submission, $editor); + } $eventLog = Repo::eventLog()->newDataObject([ diff --git a/classes/log/SubmissionEmailLogEntry.php b/classes/log/SubmissionEmailLogEntry.php index 3d9cebaa2e4..ec2d39f303f 100644 --- a/classes/log/SubmissionEmailLogEntry.php +++ b/classes/log/SubmissionEmailLogEntry.php @@ -41,6 +41,11 @@ class SubmissionEmailLogEntry extends EmailLogEntry public const SUBMISSION_EMAIL_REVIEW_CONFIRM_ACK = 0x40000008; public const SUBMISSION_EMAIL_REVIEW_REQUEST = 0x40000009; public const SUBMISSION_EMAIL_REVIEW_REQUEST_SUBSEQUENT = 0x4000000A; + public const SUBMISSION_EMAIL_REVIEW_REMIND_AUTO = 0x4000000B; + public const SUBMISSION_EMAIL_REVIEW_COMPLETE = 0x4000000C; + public const SUBMISSION_EMAIL_REVIEW_REINSTATED = 0x4000000D; + public const SUBMISSION_EMAIL_REVIEW_RESEND = 0x4000000E; + public const SUBMISSION_EMAIL_REVIEW_EDIT_NOTIFY_REVIEWER = 0x4000000F; // Copyeditor events 0x50000000 public const SUBMISSION_EMAIL_COPYEDIT_NOTIFY_COPYEDITOR = 0x50000001; diff --git a/classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php b/classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php index 493011e7a7b..5f403fe96ea 100644 --- a/classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php +++ b/classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php @@ -28,6 +28,7 @@ use PKP\core\PKPRequest; use PKP\db\DAORegistry; use PKP\log\event\PKPSubmissionEventLogEntry; +use PKP\log\SubmissionEmailLogDAO; use PKP\mail\mailables\ReviewCompleteNotifyEditors; use PKP\notification\NotificationDAO; use PKP\notification\NotificationSubscriptionSettingsDAO; @@ -44,6 +45,7 @@ use PKP\submission\reviewAssignment\ReviewAssignmentDAO; use PKP\submission\SubmissionComment; use PKP\submission\SubmissionCommentDAO; +use PKP\log\SubmissionEmailLogEntry; class PKPReviewerReviewStep3Form extends ReviewerReviewForm { @@ -236,7 +238,9 @@ public function execute(...$functionParams) ->allowUnsubscribe($notification); Mail::send($mailable); - + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_COMPLETE, $mailable, $submission, $user); $receivedList[] = $userId; } diff --git a/classes/task/ReviewReminder.php b/classes/task/ReviewReminder.php index ed21cda13f6..43257386596 100644 --- a/classes/task/ReviewReminder.php +++ b/classes/task/ReviewReminder.php @@ -24,6 +24,8 @@ use PKP\core\PKPApplication; use PKP\db\DAORegistry; use PKP\log\event\PKPSubmissionEventLogEntry; +use PKP\log\SubmissionEmailLogDAO; +use PKP\log\SubmissionEmailLogEntry; use PKP\mail\mailables\ReviewRemindAuto; use PKP\mail\mailables\ReviewResponseRemindAuto; use PKP\scheduledTask\ScheduledTask; @@ -108,6 +110,9 @@ public function sendReminder( 'recipientName' => $reviewer->getFullName(), ]); Repo::eventLog()->add($eventLog); + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_REMIND_AUTO, $mailable, $submission); } /** diff --git a/controllers/grid/users/reviewer/form/EditReviewForm.php b/controllers/grid/users/reviewer/form/EditReviewForm.php index 6c04f304f76..ac90d516816 100644 --- a/controllers/grid/users/reviewer/form/EditReviewForm.php +++ b/controllers/grid/users/reviewer/form/EditReviewForm.php @@ -27,6 +27,8 @@ use PKP\core\PKPApplication; use PKP\db\DAORegistry; use PKP\form\Form; +use PKP\log\SubmissionEmailLogDAO; +use PKP\log\SubmissionEmailLogEntry; use PKP\mail\mailables\EditReviewNotify; use PKP\notification\NotificationSubscriptionSettingsDAO; use PKP\notification\PKPNotification; @@ -214,6 +216,10 @@ public function execute(...$functionArgs) ->allowUnsubscribe($notification); Mail::send($mailable); + + /** @var SubmissionEmailLogDAO $submissionEmailLogDao */ + $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); + $submissionEmailLogDao->logMailable(SubmissionEmailLogEntry::SUBMISSION_EMAIL_REVIEW_EDIT_NOTIFY_REVIEWER, $mailable, $this->submission, $request->getUser()); } }