OCA\\Notifications\\MailNotifications::sendEmailToUser() BUG + Fix
wehowski opened this issue · comments
Hello,
I got the following errors in the log from cronjobs:
OCA\Notifications\MailNotifications::sendEmailToUser(): Argument #3 ($language) must be of type string, bool given, called in /apps/notifications/lib/MailNotifications.php on line 169
I am about to try to fix it now in line 138:
if ($fallbackLang === null || is_bool($fallbackLang)) {
I am on nc 27.1.4 with all apps updated to latest versions.
Edit: The fix works, notifications queued where send now.
But neither default_language
nor force_language
is a bool?
/me looks up the code
https://github.com/nextcloud/server/blob/8191295f66cdea5da7854bfad01ad9540c4a55f4/config/config.sample.php#L171-L196
Why would we do a string+bool config?
/me looks up the author
What in the world :D
TLDR: Yeah you are right
I post the complete code snippet below.
$fallbackLang is copied to $languageCode
if $userLanguages[$settings->getUserId()]
is empty/undefined.
The line WITHOUT the change was
if ($fallbackLang === null) {
WITH the change:
$fallbackLang = $this->config->getSystemValue('force_language', null);
if ($fallbackLang === null || is_bool($fallbackLang)) {
$fallbackLang = $this->config->getSystemValue('default_language', 'en');
$userLanguages = $this->config->getUserValueForUsers('core', 'lang', $userIds);
} else {
$userLanguages = [];
}
foreach ($userSettings as $settings) {
if (isset($userEnabled[$settings->getUserId()]) && $userEnabled[$settings->getUserId()] === 'false') {
// User is disabled, skip sending the email for them
if ($settings->getNextSendTime() <= $sendTime) {
$settings->setNextSendTime(
$sendTime + $settings->getBatchTime()
);
$this->settingsMapper->update($settings);
}
continue;
}
// Get the settings for this particular user, then check if we have notifications to email them
$languageCode = $userLanguages[$settings->getUserId()] ?? $fallbackLang;
$timezone = $userTimezones[$settings->getUserId()] ?? $fallbackTimeZone;
/** @var INotification[] $notifications */
$notifications = $this->handler->getAfterId($settings->getLastSendId(), $settings->getUserId());
if (!empty($notifications)) {
$oldestNotification = end($notifications);
$shouldSendAfter = $oldestNotification->getDateTime()->getTimestamp() + $settings->getBatchTime();
if ($shouldSendAfter <= $sendTime) {
// User has notifications that should send
// !!! THIS IS WHERE IT THROWS:
$this->sendEmailToUser($settings, $notifications, $languageCode, $timezone);
} else {
//...
All good, patch looks fine. Do you want to turn it into an actual pull request? Or shall I do that for you
Oh it would great if you could do that for me as you might be more involved in the nextcloud code/dev-team than me!?!
Thank you!