[OJS 3.5.0-3] ORCID email to authors is sent in the wrong language

Hi,

we have observed on several OJS 3.5 instances that the ORCID request email to co-authors (ORCID_COLLECT_AUTHOR_ID) is sometimes sent in a wrong language, or does not arrive at all – for example, in our case in Arabic, even though our journal uses German.

The error occurred after we started sending emails via the scheduler/cronjob (using lib/pkp/tools/scheduler.php), meaning the process was no longer triggered directly via a browser request.

When executed via cronjob, OJS no longer correctly identifies the current journal, because there is no web address from which the journal can be derived. OJS should then fall back to the journal’s default language, but in this specific case this does not happen. Instead, it simply takes some randomly available language version of the email text (or the alphabetically first one from email_template_settings).

When debugging lib/pkp/classes/mail/Mailer.php

[…]
public function send($view, array $data = , $callback = null)
{
if (is_a($view, Mailable::class)) {
/** @var Mailable $view */
error_log(‘DEBUG ORCID: Mailable class=’ . get_class($view) . ’ resolved locale=’ . $view->getLocale());
$view->setData($view->getLocale());
}
[…]

you can see that the locale is empty.

Workaround we implemented locally:

In lib/pkp/jobs/orcid/SendAuthorMail.php, the language is not explicitly set when sending the email. We changed this so that the journal’s language is explicitly passed instead of relying on the (non-functional in cronjobs) automatic detection. Since then, the email reliably arrives in the correct primary language.

Has anyone else observed this, or is there an official fix for it? For us, it is currently a small custom patch that has to be reapplied with every upgrade.

Additional issue we noticed:

If the journal’s contact email address does not correspond to a registered user account (e.g. a pure functional address like redaktion@...), this ORCID email sending fails completely with the error:

Error: Call to a member function getLocalizedSignature() on null in /srv/www/ojs03/htdocs/lib/pkp/classes/mail/traits/OrcidVariables.php:60

Our workaround: Create a user account with exactly this email address.

Hi @ohilbig01, thank you for sharing this.

Could you confirm that this is still a problem with the latest release? I have been unable to recreate the issue locally with using the dedicated job runner. Could you share a bit more about how you have your job runner and scheduler set up and how exactly you have your emails configured to be sent given that? Thanks!

Regards,

Erik
PKP Team

Hi @ewhanson ,

thanks for your reply.

Yes, I can confirm the issue is still present in OJS 3.5.0-5. I forgot to add my fix in the new version. So I just reproduced it by adding myself as a contributor to a submission and triggering an ORCID verification email. The email arrived in Arabic instead of German (the journal’s primary locale).

Setup:
job_runner = Off
process_jobs_at_task_scheduler = On
Scheduler via cron: * * * * * php /lib/pkp/tools/scheduler.php run >> /srv/www/logs/ojs-scheduled.log 2>&1
(No dedicated job runner)

I think this behaviour only occurs when the job is processed by the scheduler in a CLI context, where there is no HTTP request.
When the job runs via the scheduler in a CLI context, there is no HTTP request available.
SendAuthorMail::handle() in lib/pkp/jobs/orcid/SendAuthorMail.php calls getLocalizedData(‘body’) and getLocalizedData(‘subject’) without passing an explicit locale.

I guess the locale resolution then tries to read the locale from the session, cookie or HTTP request, which, I assume, don’t exist.
As a fallback, it simply picks the first available locale from the email template data in the database, which in our case is ar (Arabic), because it comes before de (German) alphabetically.

My fix was passing $this->context->getPrimaryLocale() explicitly:

in lib/pkp/jobs/orcid/SendAuthorMail.php in function handle():

-    $mailable->body($emailTemplate->getLocalizedData('body'))
-    	->subject($emailTemplate->getLocalizedData('subject'));
+    $mailable->body($emailTemplate->getLocalizedData('body', $this->context->getPrimaryLocale()))
+            ->subject($emailTemplate->getLocalizedData('subject', $this->context->getPrimaryLocale()));

Hope this info helps!