Skip to content

Commit 725b24f

Browse files
committed
Fix fallback to super users, use filter group_id instead of groups. Simplify field description
1 parent bc99f0b commit 725b24f

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

administrator/components/com_joomlaupdate/src/Model/NotificationModel.php

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,27 @@ final class NotificationModel extends BaseDatabaseModel
4848
public function sendNotification($type, $oldVersion, $newVersion): void
4949
{
5050
$params = ComponentHelper::getParams('com_joomlaupdate');
51-
51+
52+
// Superusergroups as fallback
53+
$superUserGroups = $this->getSuperUserGroups();
54+
55+
if (!\is_array($superUserGroups)) {
56+
$emailGroups = ArrayHelper::toInteger(explode(',', $superUserGroups));
57+
}
58+
5259
// User groups from input field
53-
$emailGroups = $params->get('automated_updates_email_groups', $this->getSuperUserGroups(), 'array');
60+
$emailGroups = $params->get('automated_updates_email_groups', $superUserGroups, 'array');
5461

5562
if (!\is_array($emailGroups)) {
5663
$emailGroups = ArrayHelper::toInteger(explode(',', $emailGroups));
5764
}
5865

5966
// Get all users in these groups who can receive emails
6067
$emailReceivers = $this->getEmailReceivers($emailGroups);
61-
62-
// If no email receivers are found, we do not send any notification
68+
69+
// If no email receivers are found, we use superusergroups as fallback
6370
if (empty($emailReceivers)) {
64-
// Should not happen, as at least one super user must exist in the system
65-
return;
71+
$emailReceivers = $this->getEmailReceivers($superUserGroups);
6672
}
6773

6874
$app = Factory::getApplication();
@@ -109,39 +115,28 @@ private function getEmailReceivers($emailGroups): array
109115
// Get the users of all groups in the emailGroups
110116
$usersModel = Factory::getApplication()->bootComponent('com_users')
111117
->getMVCFactory()->createModel('Users', 'Administrator');
118+
$usersModel->setState('filter.state', (int) 0); // Only enabled users
119+
120+
foreach ($emailGroups as $group) {
121+
$usersModel->setState('filter.group_id', $group);
122+
123+
$usersInGroup = $usersModel->getItems();
124+
if (empty($usersInGroup)) {
125+
continue;
126+
}
112127

113-
$usersModel->setState('filter.groups', $emailGroups);
114-
$usersModel->setState('filter.state', (int) 0); // Only enabled users
115-
116-
$usersInGroup = $usersModel->getItems();
117-
118-
if (empty($usersInGroup)) {
119-
// Cannot happen, as at least one super user must exist in the system
120-
return [];
121-
}
122-
123-
// Only users with valid email address who are not blocked can receive the email
124-
foreach ($usersInGroup as $user) {
125-
if (MailHelper::isEmailAddress($user->email) && $user->sendEmail === 1) {
126-
$user->email = strtolower(trim($user->email));
127-
128-
// Check if the email already exists in the emailReceivers array
129-
$exist = false;
130-
foreach ($emailReceivers as $rec) {
131-
if ($rec->email === $user->email) {
132-
$exist = true;
133-
break;
134-
}
135-
}
136-
137-
// Add to the list if it is not already in the list
138-
if (!$exist) {
128+
// Users can be in more than one group. Accept only one entry
129+
foreach ($usersInGroup as $user) {
130+
131+
if (MailHelper::isEmailAddress($user->email) && $user->sendEmail === 1) {
132+
$user->email = strtolower(trim($user->email));
133+
139134
$emailReceivers[] = $user;
140135
}
141136
}
142137
}
143138

144-
return $emailReceivers;
139+
return \array_unique($emailReceivers);
145140
}
146141

147142
/**

administrator/language/en-GB/com_joomlaupdate.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_DISABLED_LABEL="<span class=\"fa-fw me
1616
COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_LABEL="Automated Updates"
1717
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_DESC="Automatically update Joomla to the latest version when it is available."
1818
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_LABEL="Automated Update"
19-
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_UPDATE_EMAIL_DESCRIPTION="All users in the selected groups will receive the emails if they have the receive system emails option enabled and are active. If no users are found, all super users will receive the emails."
19+
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_UPDATE_EMAIL_DESCRIPTION="All users in the selected groups will receive the emails. If no users are found, the emails are sent to all Super Users. Recipients MUST have the Receive System Emails option enabled."
2020
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_UPDATE_EMAIL_LABEL="Send Email to User Groups"
2121
COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_DESC="Shows the checkbox to confirm you have taken a backup and you're ready to update in the final step before the update is actually applied."
2222
COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_LABEL="Confirm Backup Checkbox"

0 commit comments

Comments
 (0)