From 178739cd862c28c146b03b9de99869cb0095078a Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 08:46:17 +0200 Subject: [PATCH 01/10] use correct default admin language for update notification mails --- .../com_joomlaupdate/src/Model/NotificationModel.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 8e422b5b2c708..d0859a78beca0 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -82,13 +82,18 @@ public function sendNotification($type, $oldVersion, $newVersion): void 'url' => Uri::root(), ]; + // Determine the default admin language + $defaultLanguage = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB'); + // Send emails to all receivers foreach ($emailReceivers as $receiver) { - $params = new Registry($receiver->params); + $receiverParams = new Registry($receiver->params); + $receiverLanguage = $receiverParams->get('admin_language', $defaultLanguage); + $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); - $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $params->get('admin_language', null), true, true); + $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $receiverLanguage); - $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $jLanguage->getTag()); + $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $receiverLanguage); $mailer->addRecipient($receiver->email); $mailer->addTemplateData($substitutions); $mailer->send(); From 8d164140db55b8810d4e716e9504cc116b496ca6 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 09:11:01 +0200 Subject: [PATCH 02/10] cs fix --- .../components/com_joomlaupdate/src/Model/NotificationModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index d0859a78beca0..3e71aed6630f2 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -87,7 +87,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void // Send emails to all receivers foreach ($emailReceivers as $receiver) { - $receiverParams = new Registry($receiver->params); + $receiverParams = new Registry($receiver->params); $receiverLanguage = $receiverParams->get('admin_language', $defaultLanguage); $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); From 69feeff25bec5801a4ef6a390f5653ae751ee751 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 12:51:39 +0200 Subject: [PATCH 03/10] fix language handling for multiple users --- .../src/Model/NotificationModel.php | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 3e71aed6630f2..fa151f37f9425 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -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; @@ -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'); $substitutions = [ 'oldversion' => $oldVersion, @@ -82,21 +82,46 @@ public function sendNotification($type, $oldVersion, $newVersion): void 'url' => Uri::root(), ]; - // Determine the default admin language - $defaultLanguage = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB'); + // 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(); + $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); + $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $defaultLocale); // Send emails to all receivers foreach ($emailReceivers as $receiver) { $receiverParams = new Registry($receiver->params); - $receiverLanguage = $receiverParams->get('admin_language', $defaultLanguage); + $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); - $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); - $jLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $receiverLanguage); + // Temporarily set application language to user's language. + if ($receiverLocale !== $defaultLocale) { + $receiverLanguage = Factory::getContainer() + ->get(LanguageFactoryInterface::class) + ->createLanguage($receiverLocale, $app->get('debug_lang', false)); - $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $receiverLanguage); + Factory::$language = $receiverLanguage; + + 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); $mailer->addTemplateData($substitutions); $mailer->send(); + + // Set application language back to default if we changed it + if ($receiverLocale !== $defaultLocale) { + Factory::$language = $defaultLanguage; + + if (method_exists($app, 'loadLanguage')) + { + $app->loadLanguage($defaultLanguage); + } + } } } From d7fd54e08e7506af88cda67fd21329a3d410c5df Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Tue, 9 Sep 2025 13:08:59 +0200 Subject: [PATCH 04/10] Fix PHPCS --- .../com_joomlaupdate/src/Model/NotificationModel.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index fa151f37f9425..a3b7b5e564c21 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -83,7 +83,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void ]; // 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'); + $defaultLocale = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB'); $defaultLanguage = $app->getLanguage(); $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $defaultLocale); @@ -91,7 +91,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void // Send emails to all receivers foreach ($emailReceivers as $receiver) { $receiverParams = new Registry($receiver->params); - $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); + $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); // Temporarily set application language to user's language. if ($receiverLocale !== $defaultLocale) { @@ -117,8 +117,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void if ($receiverLocale !== $defaultLocale) { Factory::$language = $defaultLanguage; - if (method_exists($app, 'loadLanguage')) - { + if (method_exists($app, 'loadLanguage')) { $app->loadLanguage($defaultLanguage); } } From 21c3ba4faa40515f4c3503ded093e9302f6aa81b Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 14:16:06 +0200 Subject: [PATCH 05/10] fix baseline --- phpstan-baseline.neon | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a59d8ffa9530b..bef4ff4ded87d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2091,7 +2091,7 @@ parameters: - message: ''' #^Access to deprecated property \$app of class Joomla\\Component\\Fields\\Administrator\\Plugin\\FieldsPlugin\: - 5.4.0 will be removed in 7\.0 use \$this\-\>getApplication\(\) instead$# + 5\.4\.0 will be removed in 7\.0 use \$this\-\>getApplication\(\) instead$# ''' identifier: property.deprecated count: 1 @@ -3770,6 +3770,18 @@ parameters: count: 1 path: administrator/components/com_joomlaupdate/src/Controller/UpdateController.php + - + message: ''' + #^Access to deprecated static property \$language of class Joomla\\CMS\\Factory\: + 4\.3 will be removed in 6\.0 + Use the language service in the DI container or get from the application object + Example\: + Factory\:\:getApplication\(\)\-\>getLanguage\(\);$# + ''' + identifier: staticProperty.deprecated + count: 2 + path: administrator/components/com_joomlaupdate/src/Model/NotificationModel.php + - message: ''' #^Call to deprecated method get\(\) of class Joomla\\CMS\\Updater\\Update\: @@ -3836,16 +3848,6 @@ parameters: count: 1 path: administrator/components/com_joomlaupdate/src/Model/UpdateModel.php - - - message: ''' - #^Call to method getDispatcher\(\) of deprecated interface Joomla\\CMS\\Application\\EventAwareInterface\: - 4\.3 will be removed in 7\.0 - This interface will be removed without replacement as the Joomla 3\.x compatibility layer will be removed$# - ''' - identifier: method.deprecatedInterface - count: 2 - path: administrator/components/com_joomlaupdate/src/Model/UpdateModel.php - - message: ''' #^Call to method set\(\) of deprecated class Joomla\\CMS\\Adapter\\Adapter\: From 88328b20d652ecd58d96494a20d0c8f89377aeae Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Tue, 9 Sep 2025 14:22:21 +0200 Subject: [PATCH 06/10] Another PHPCS fix. --- .../com_joomlaupdate/src/Model/NotificationModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index a3b7b5e564c21..41d3a9306b00d 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -90,8 +90,8 @@ public function sendNotification($type, $oldVersion, $newVersion): void // Send emails to all receivers foreach ($emailReceivers as $receiver) { - $receiverParams = new Registry($receiver->params); - $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); + $receiverParams = new Registry($receiver->params); + $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); // Temporarily set application language to user's language. if ($receiverLocale !== $defaultLocale) { From 8f26732736eaa271323176d55e3049d7c30e1991 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 18:55:45 +0200 Subject: [PATCH 07/10] added receiver name --- .../components/com_joomlaupdate/src/Model/NotificationModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 41d3a9306b00d..15064999130f8 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -109,7 +109,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void } $mailer = new MailTemplate('com_joomlaupdate.update.' . $type, $receiverLocale); - $mailer->addRecipient($receiver->email); + $mailer->addRecipient($receiver->email, $receiver->name); $mailer->addTemplateData($substitutions); $mailer->send(); From 12e183759fd0a1fde561830443dbcec91cad2935 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 9 Sep 2025 18:59:38 +0200 Subject: [PATCH 08/10] limit language changes to necesary cases --- .../src/Model/NotificationModel.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 15064999130f8..872964b78242d 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -94,7 +94,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void $receiverLocale = $receiverParams->get('admin_language', $defaultLocale); // Temporarily set application language to user's language. - if ($receiverLocale !== $defaultLocale) { + if ($app->getLanguage()->getTag() !== $receiverLocale) { $receiverLanguage = Factory::getContainer() ->get(LanguageFactoryInterface::class) ->createLanguage($receiverLocale, $app->get('debug_lang', false)); @@ -112,15 +112,13 @@ public function sendNotification($type, $oldVersion, $newVersion): void $mailer->addRecipient($receiver->email, $receiver->name); $mailer->addTemplateData($substitutions); $mailer->send(); + } - // Set application language back to default if we changed it - if ($receiverLocale !== $defaultLocale) { - Factory::$language = $defaultLanguage; + // Set application language back to default + Factory::$language = $defaultLanguage; - if (method_exists($app, 'loadLanguage')) { - $app->loadLanguage($defaultLanguage); - } - } + if (method_exists($app, 'loadLanguage')) { + $app->loadLanguage($defaultLanguage); } } From 9c653092a38ddc17a7eb6e592a887b0989172209 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Wed, 10 Sep 2025 12:17:43 +0200 Subject: [PATCH 09/10] Update administrator/components/com_joomlaupdate/src/Model/NotificationModel.php Co-authored-by: Richard Fath --- .../com_joomlaupdate/src/Model/NotificationModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 872964b78242d..0c7204d71be80 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -72,8 +72,8 @@ public function sendNotification($type, $oldVersion, $newVersion): void $emailReceivers = $this->getEmailReceivers($superUserGroups); } - $app = Factory::getApplication(); - $sitename = $app->get('sitename'); + $app = Factory::getApplication(); + $sitename = $app->get('sitename'); $substitutions = [ 'oldversion' => $oldVersion, From b3393a42b85d5945e807cedf7bca48d58e93322e Mon Sep 17 00:00:00 2001 From: David Jardin Date: Wed, 10 Sep 2025 14:53:26 +0200 Subject: [PATCH 10/10] Update administrator/components/com_joomlaupdate/src/Model/NotificationModel.php Co-authored-by: Tuan Pham Ngoc --- .../components/com_joomlaupdate/src/Model/NotificationModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php index 0c7204d71be80..2114efd2d3803 100644 --- a/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/NotificationModel.php @@ -86,7 +86,7 @@ public function sendNotification($type, $oldVersion, $newVersion): void $defaultLocale = ComponentHelper::getParams('com_languages')->get('administrator', 'en-GB'); $defaultLanguage = $app->getLanguage(); $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, 'en-GB', true, true); - $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR, $defaultLocale); + $defaultLanguage->load('com_joomlaupdate', JPATH_ADMINISTRATOR); // Send emails to all receivers foreach ($emailReceivers as $receiver) {