pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
298 stars 443 forks source link

Re-add sent review request email data into the email log #9991

Open Vitaliy-1 opened 1 month ago

Vitaliy-1 commented 1 month ago

Describe the bug Described on the forum https://forum.pkp.sfu.ca/t/review-request-emails-no-longer-logged-in-ojs-3-4-intentionally/88499

In 3.3, when sending a review request email, the email information was recorded in the email_log table. It didn't have a specific event_type for that action.

To Reproduce Steps to reproduce the behavior:

  1. Go to the submission on the review stage
  2. Click on Add Reviewer
  3. Fill the form and send email
  4. See the email data wasn't logged in the email_log table

What application are you using? OJS 3.4, OJS main

Additional information

  1. Create a submission event type constant, i.e., SUBMISSION_EMAIL_REVIEW_REQUEST and SUBMISSION_EMAIL_REVIEW_REQUEST_SUBSEQUENT
  2. The actual email sending is performed in PKP\submission\action\EditorAction::addReviewer(), use PKP\log\SubmissionEmailLogDAO::logMailable() to record the data.
jim13731 commented 2 weeks ago

@Vitaliy-1 Thank you for the sharing the files path.

I have added functionality to log email data for the "Add Reviewer" action in OJS 3.4. Below are the changes made:

Files Modified lib/pkp/classes/log/event/PKPSubmissionEventLogEntry.php lib/pkp/classes/submission/action/EditorAction.php

Changes

  1. lib/pkp/classes/log/event/PKPSubmissionEventLogEntry.php

Added new constants for email events:

`class PKPSubmissionEventLogEntry extends EventLogEntry { // ... existing constants ...

public const SUBMISSION_EMAIL_REVIEW_REQUEST = 0x50000001;
public const SUBMISSION_EMAIL_REVIEW_REQUEST_SUBSEQUENT = 0x50000002;

// ... existing methods ...

} `

  1. lib/pkp/classes/submission/action/EditorAction.php

Modified the addReviewer method to include email logging:

`public function addReviewer($request, $submission, $reviewerId, &$reviewRound, $reviewDueDate, $responseDueDate, $reviewMethod = null) { // ... existing code ...

if (!$assigned && isset($reviewer) && !Hook::call('EditorAction::addReviewer', [&$submission, $reviewerId])) {
    // ... existing code ...

    // Send mail
    if (!$request->getUserVar('skipEmail')) {
        $context = PKPServices::get('context')->get($submission->getData('contextId'));
        $emailTemplate = Repo::emailTemplate()->getByKey($submission->getData('contextId'), $request->getUserVar('template'));
        $emailBody = $request->getUserVar('personalMessage');
        $emailSubject = $emailTemplate->getLocalizedData('subject');
        $mailable = $this->createMail($submission, $reviewAssignment, $reviewer, $user, $emailBody, $emailSubject, $context);

        try {
            Mail::send($mailable);

            // Log email
            $eventType = ($reviewRound->getRound() == 1) ? PKPSubmissionEventLogEntry::SUBMISSION_EMAIL_REVIEW_REQUEST : PKPSubmissionEventLogEntry::SUBMISSION_EMAIL_REVIEW_REQUEST_SUBSEQUENT;
            $submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO');
            $submissionEmailLogDao->logMailable($eventType, $mailable, $submission, $user);

        } catch (TransportException $e) {
            $notificationMgr = new PKPNotificationManager();
            $notificationMgr->createTrivialNotification(
                $user->getId(),
                PKPNotification::NOTIFICATION_TYPE_ERROR,
                ['contents' => __('email.compose.error')]
            );
            trigger_error('Failed to send email: ' . $e->getMessage(), E_USER_WARNING);
        }
    }
}

}

Summary

These changes ensure that email data is logged whenever a reviewer is added.`

image

image

taslangraham commented 18 hours ago

@Vitaliy-1 I've created PRs for this. Please take a look.

PRs: pkp-lib (main) - https://github.com/pkp/pkp-lib/pull/10229 pkp lib (stable 3.4) - https://github.com/pkp/pkp-lib/pull/10230

ojs (main) - https://github.com/pkp/ojs/pull/4373 ojs (stable 3.4) - https://github.com/pkp/ojs/pull/4374

omp (main) - https://github.com/pkp/omp/pull/1651 omp (stable 3.4) - https://github.com/pkp/omp/pull/1652