Skip to content
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\UserGroupsHelper;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Mail\MailHelper;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
Expand Down Expand Up @@ -71,9 +72,8 @@ public function sendNotification($type, $oldVersion, $newVersion): void
$emailReceivers = $this->getEmailReceivers($superUserGroups);
}

$app = Factory::getApplication();
$jLanguage = $app->getLanguage();
$sitename = $app->get('sitename');
$app = Factory::getApplication();
$sitename = $app->get('sitename');
Comment thread
SniperSister marked this conversation as resolved.
Outdated

$substitutions = [
'oldversion' => $oldVersion,
Expand All @@ -82,16 +82,46 @@ public function sendNotification($type, $oldVersion, $newVersion): void
'url' => Uri::root(),
];

// Determine the default admin language and load the language file for the fallback and default language
$defaultLocale = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB');
$defaultLanguage = $app->getLanguage();
Comment thread
richard67 marked this conversation as resolved.
Outdated
$defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true);
Comment thread
SniperSister marked this conversation as resolved.
$defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $defaultLocale);
Comment thread
SniperSister marked this conversation as resolved.
Outdated

// Send emails to all receivers
foreach ($emailReceivers as $receiver) {
$params = new Registry($receiver->params);
$jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true);
$jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $params->get('admin_language', null), true, true);
$receiverParams = new Registry($receiver->params);
$receiverLocale = $receiverParams->get('admin_language', $defaultLocale);
Comment thread
richard67 marked this conversation as resolved.
Outdated

// Temporarily set application language to user's language.
if ($receiverLocale !== $defaultLocale) {
$receiverLanguage = Factory::getContainer()
->get(LanguageFactoryInterface::class)
->createLanguage($receiverLocale, $app->get('debug_lang', false));

Factory::$language = $receiverLanguage;

$mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $jLanguage->getTag());
if (method_exists($app, 'loadLanguage')) {
$app->loadLanguage($receiverLanguage);
}

$receiverLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $receiverLocale);
}

$mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $receiverLocale);
$mailer->addRecipient($receiver->email);
Comment thread
SniperSister marked this conversation as resolved.
Outdated
$mailer->addTemplateData($substitutions);
$mailer->send();

// Set application language back to default if we changed it
Comment thread
SniperSister marked this conversation as resolved.
Outdated
if ($receiverLocale !== $defaultLocale) {
Factory::$language = $defaultLanguage;

if (method_exists($app, 'loadLanguage'))
{
Comment thread
richard67 marked this conversation as resolved.
Outdated
$app->loadLanguage($defaultLanguage);
}
}
}
}

Expand Down
Loading