Skip to content

pkp/pkp-lib#11303 job worker mode locale set issue #11304

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

Open
wants to merge 2 commits into
base: stable-3_4_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion classes/mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Mailable extends IlluminateMailable
public const ATTACHMENT_SUBMISSION_FILE = 'submissionFileId';
public const ATTACHMENT_LIBRARY_FILE = 'libraryFileId';

/** @var string|null The specific locale to send the mail of this Mailable */
protected ?string $mailableLocale = null;

/** @var string|null Locale key for the name of this Mailable */
protected static ?string $name = null;

Expand Down Expand Up @@ -226,7 +229,7 @@ public function getData(?string $locale = null): array
public function setData(?string $locale = null): void
{
if (is_null($locale)) {
$locale = Locale::getLocale();
$locale = $this->getLocale() ?? Locale::getLocale();
}
foreach ($this->variables as $variable) {
$this->viewData = array_merge(
Expand All @@ -238,6 +241,24 @@ public function setData(?string $locale = null): void
$this->addFooter($locale); // set the locale for the email footer
}

/**
* Set the mailable locale
*/
public function setLocale(string $locale): static
{
$this->mailableLocale = $locale;

return $this;
}

/**
* Get the mailable locale
*/
public function getLocale(): ?string
{
return $this->mailableLocale;
}

/**
* @param string $localeKey
*
Expand Down Expand Up @@ -492,6 +513,7 @@ protected static function getTypeNames(ReflectionType $type): array
}
$isUnion = $type instanceof ReflectionUnionType;
if ($isUnion || $type instanceof ReflectionIntersectionType) {
/** @var ReflectionIntersectionType $type */
$flattenTypes = collect($type->getTypes())
->map(fn ($type) => static::getTypeNames($type))
->flatten();
Expand Down
2 changes: 1 addition & 1 deletion classes/mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function send($view, array $data = [], $callback = null)
{
if (is_a($view, Mailable::class)) {
/** @var Mailable $view */
$view->setData();
$view->setData($view->getLocale());
}

// Application is set to sandbox mode and will sent any emails to log
Expand Down
2 changes: 1 addition & 1 deletion classes/mail/mailables/AnnouncementNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setData(?string $locale = null): void
{
parent::setData($locale);
if (is_null($locale)) {
$locale = Locale::getLocale();
$locale = $this->getLocale() ?? Locale::getLocale();
}

$request = Application::get()->getRequest();
Expand Down
2 changes: 1 addition & 1 deletion classes/mail/mailables/DecisionNotifyOtherAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setData(?string $locale = null): void
parent::setData($locale);

if (is_null($locale)) {
$locale = Locale::getLocale();
$locale = $this->getLocale() ?? Locale::getLocale();
}

$this->viewData[self::SUBMITTING_AUTHOR_NAME] = $this->getSubmittingAuthorName($locale);
Expand Down
2 changes: 1 addition & 1 deletion classes/task/ReviewReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function sendReminder(
->from($context->getData('contactEmail'), $context->getData('contactName'))
->recipients([$reviewer]);

$mailable->setData($primaryLocale);
$mailable->setLocale($primaryLocale);

$application = Application::get();
$request = $application->getRequest();
Expand Down
3 changes: 2 additions & 1 deletion controllers/grid/users/reviewer/form/ReviewerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ protected function getMailable(): ReviewRequest
]);

// Remove template variables that haven't been set yet during form initialization
$mailable->setData(Locale::getLocale());
$locale = Locale::getLocale();
$mailable->setLocale($locale)->setData($locale);
unset($mailable->viewData[ReviewAssignmentEmailVariable::REVIEW_DUE_DATE]);
unset($mailable->viewData[ReviewAssignmentEmailVariable::RESPONSE_DUE_DATE]);
unset($mailable->viewData[ReviewAssignmentEmailVariable::REVIEW_ASSIGNMENT_URL]);
Expand Down
2 changes: 1 addition & 1 deletion controllers/grid/users/reviewer/form/ThankReviewerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function execute(...$functionArgs)

Hook::call('ThankReviewerForm::thankReviewer', [$submission, $reviewAssignment, $mailable]);
if (!$this->getData('skipEmail')) {
$mailable->setData(Locale::getLocale());
$mailable->setLocale(Locale::getLocale());
try {
Mail::send($mailable);
$submissionEmailLogDao = DAORegistry::getDAO('SubmissionEmailLogDAO'); /** @var SubmissionEmailLogDAO $submissionEmailLogDao */
Expand Down
2 changes: 1 addition & 1 deletion jobs/notifications/NewAnnouncementNotifyUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function handle()
$mailable = $this->createMailable($context, $recipient, $announcement, $template)
->allowUnsubscribe($notification);

$mailable->setData($this->locale);
$mailable->setLocale($this->locale);
Mail::send($mailable);
}
}
Expand Down
2 changes: 1 addition & 1 deletion jobs/notifications/StatisticsReportMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function handle()
$mailable->from($context->getContactEmail(), $context->getContactName());
$mailable->subject($template->getLocalizedData('subject', $locale));
$mailable->body($template->getLocalizedData('body', $locale));
$mailable->setData($locale);
$mailable->setLocale($locale);
$mailable->attach($filePath, ['as' => 'editorial-report.csv']);
$mailable->allowUnsubscribe($notification);

Expand Down