Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer in the Editorial Reminder if the user has blocked notifications #10496

Open
nwoodward opened this issue Oct 2, 2024 · 1 comment
Assignees
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Milestone

Comments

@nwoodward
Copy link

Describe the bug
We see several errors in the OJS logs about a null pointer in EditorialReminder.php, and it's due to the $notification being null. In the handle() method below the $notification variable returned from $notificationManager->createNotification() could potentially be null. So when it's used in the allowUnsubscribe() method of $mailable it throws a null pointer error.

$notificationManager = new NotificationManager();
$notification = $notificationManager->createNotification(
Application::get()->getRequest(),
$this->editorId,
Notification::NOTIFICATION_TYPE_EDITORIAL_REMINDER,
$this->contextId
);
$mailable = new MailablesEditorialReminder($context);
$emailTemplate = Repo::emailTemplate()->getByKey($context->getId(), $mailable::getEmailTemplateKey());
$mailable
->setOutstandingTasks($outstanding, $submissions, $submissionIds->count())
->from($context->getContactEmail(), $context->getLocalizedName(Locale::getLocale()))
->recipients([$editor])
->subject($emailTemplate->getLocalizedData('subject'))
->body($emailTemplate->getLocalizedData('body'))
->allowUnsubscribe($notification);
Mail::send($mailable);

This happens when the user has blocked notifications. In the createNotification() method of PKPNotificationOperationManager there's a check at the beginning to see if the user exists and has blocked notifications, in which case null is returned.

public function createNotification(PKPRequest $request, ?int $userId = null, ?int $notificationType = null, ?int $contextId = Application::SITE_CONTEXT_ID, ?int $assocType = null, ?int $assocId = null, int $level = Notification::NOTIFICATION_LEVEL_NORMAL, ?array $params = null): ?Notification
{
if ($userId && in_array($notificationType, $this->getUserBlockedNotifications($userId, $contextId))) {
return null;
}
$notification = Notification::create([
'userId' => $userId,
'type' => $notificationType,
'contextId' => $contextId,
'assocType' => $assocType,
'assocId' => $assocId,
'level' => $level,
'dateCreated' => Carbon::now()
]);
if ($params) {
$notificationSettingsDao = DAORegistry::getDAO('NotificationSettingsDAO'); /** @var NotificationSettingsDAO $notificationSettingsDao */
foreach ($params as $name => $value) {
$notificationSettingsDao->updateNotificationSetting($notification->id, $name, $value);
}
}
return $notification;
}

I don't understand the code well enough to say if the fix should be a null check on $notification after it gets created in EditorialReminder.php, and if so then return from handle(). Or if $mailable should still be called without the allowUnsubscribe($notification) method.

What application are you using?
OJS 3.4.0-5

@touhidurabir touhidurabir self-assigned this Oct 9, 2024
@touhidurabir touhidurabir added this to the 3.4.0-8 milestone Oct 9, 2024
@touhidurabir touhidurabir added the Bug:1:Low A bug that does not have a severe consequence or affects a small number of users. label Oct 9, 2024
@asmecher asmecher modified the milestones: 3.4.0-8, 3.4.0-9 Nov 29, 2024
@touhidurabir
Copy link
Member

Fix is applied at https://github.com/pkp/pkp-lib/pull/10332/files#diff-83d61d197c61d91e16b32cc318edb9f2c3ba21032384d2337d75ce12c7189fdfR173-R177 for issue #10214 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:1:Low A bug that does not have a severe consequence or affects a small number of users.
Projects
None yet
Development

No branches or pull requests

3 participants