From 80788980aa7dd4b3a849a43a94569a8b415d96db Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 8 Aug 2014 16:43:31 +0200 Subject: [PATCH 1/6] [ticket/12742] Add method for getting authenticated recipients PHPBB3-12742 --- phpBB/phpbb/notification/type/base.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index a11ad76db9..8243a2e6a2 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -533,4 +533,27 @@ abstract class base implements \phpbb\notification\type\type_interface WHERE ' . $where; $this->db->sql_query($sql); } + + /** + * Get a list of users that are authenticated to receive notifications + * + * @param array $users Array of users that have subscribed to a notification + * @param int $forum_id Forum ID of the forum + * @param array $options Array of notification options + * @return array Array of users that are authenticated recipients + */ + protected function get_authenticated_recipients($users, $forum_id, $options) + { + $users = array_unique($users); + sort($users); + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $forum_id); + + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$forum_id]['f_read'], $options); + } } From cccd54dde8d2f7733fb44ae6e47f4ec81fa96056 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 8 Aug 2014 16:54:23 +0200 Subject: [PATCH 2/6] [ticket/12742] Add check for empty $users and add method to fitting methods The method might now return an empty array in case of an empty users array, too. The notification types then check if the returned array is empty and return this if it is empty and if the notification types would otherwise carry out other operations afterwards. PHPBB3-12742 --- phpBB/phpbb/notification/type/approve_post.php | 9 +-------- phpBB/phpbb/notification/type/approve_topic.php | 9 +-------- phpBB/phpbb/notification/type/base.php | 5 +++++ phpBB/phpbb/notification/type/bookmark.php | 14 +++----------- phpBB/phpbb/notification/type/post.php | 16 +++------------- phpBB/phpbb/notification/type/quote.php | 17 +---------------- phpBB/phpbb/notification/type/topic.php | 14 +------------- 7 files changed, 15 insertions(+), 69 deletions(-) diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 0aad19d6bf..0e258f34f0 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -81,14 +81,7 @@ class approve_post extends \phpbb\notification\type\post $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + return $this->get_authenticated_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index e649f3920e..55f7b95b15 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -81,14 +81,7 @@ class approve_topic extends \phpbb\notification\type\topic $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + return $this->get_authenticated_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 8243a2e6a2..18204aaa03 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -544,6 +544,11 @@ abstract class base implements \phpbb\notification\type\type_interface */ protected function get_authenticated_recipients($users, $forum_id, $options) { + if (empty($users)) + { + return array(); + } + $users = array_unique($users); sort($users); diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index c83288cfb8..bafdd6bb0c 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -83,20 +83,12 @@ class bookmark extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - if (empty($users)) + $notify_users = $this->get_authenticated_recipients($users, $post['forum_id'], $options); + + if (empty($notify_users)) { return array(); } - sort($users); - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 357176ec35..e772b9aa7c 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -123,23 +123,13 @@ class post extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - if (empty($users)) + $notify_users = $this->get_authenticated_recipients($users, $post['forum_id'], $options); + + if (empty($notify_users)) { return array(); } - $users = array_unique($users); - sort($users); - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); - // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT n.* diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 6e672e6fbd..89f185deda 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -102,22 +102,7 @@ class quote extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } - sort($users); - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); - - return $notify_users; + return $this->get_authenticated_recipients($users, $post['forum_id'], $options); } /** diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index 289e45bedb..c74dd4aa4e 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -111,19 +111,7 @@ class topic extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - if (empty($users)) - { - return array(); - } - - $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], $options); + return $this->get_authenticated_recipients($users, $topic['forum_id'], $options); } /** From 6a13f983a4a65483f361a2e3e799199bdd9b3ae3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 9 Aug 2014 12:42:14 +0200 Subject: [PATCH 3/6] [ticket/12742] Replace authenticated with authorised PHPBB3-12742 --- phpBB/phpbb/notification/type/approve_post.php | 2 +- phpBB/phpbb/notification/type/approve_topic.php | 2 +- phpBB/phpbb/notification/type/base.php | 6 +++--- phpBB/phpbb/notification/type/bookmark.php | 2 +- phpBB/phpbb/notification/type/post.php | 2 +- phpBB/phpbb/notification/type/quote.php | 2 +- phpBB/phpbb/notification/type/topic.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 0e258f34f0..22c9076adc 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -81,7 +81,7 @@ class approve_post extends \phpbb\notification\type\post $users = array(); $users[$post['poster_id']] = array(''); - return $this->get_authenticated_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( + return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index 55f7b95b15..77e53a0064 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -81,7 +81,7 @@ class approve_topic extends \phpbb\notification\type\topic $users = array(); $users[$post['poster_id']] = array(''); - return $this->get_authenticated_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( + return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 18204aaa03..48b368f7f9 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -535,14 +535,14 @@ abstract class base implements \phpbb\notification\type\type_interface } /** - * Get a list of users that are authenticated to receive notifications + * Get a list of users that are authorised to receive notifications * * @param array $users Array of users that have subscribed to a notification * @param int $forum_id Forum ID of the forum * @param array $options Array of notification options - * @return array Array of users that are authenticated recipients + * @return array Array of users that are authorised recipients */ - protected function get_authenticated_recipients($users, $forum_id, $options) + protected function get_authorised_recipients($users, $forum_id, $options) { if (empty($users)) { diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index bafdd6bb0c..d2e2700d2d 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -83,7 +83,7 @@ class bookmark extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - $notify_users = $this->get_authenticated_recipients($users, $post['forum_id'], $options); + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options); if (empty($notify_users)) { diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index e772b9aa7c..1bd95bfbf6 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -123,7 +123,7 @@ class post extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - $notify_users = $this->get_authenticated_recipients($users, $post['forum_id'], $options); + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options); if (empty($notify_users)) { diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 89f185deda..42ec663bfc 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -102,7 +102,7 @@ class quote extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - return $this->get_authenticated_recipients($users, $post['forum_id'], $options); + return $this->get_authorised_recipients($users, $post['forum_id'], $options); } /** diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index c74dd4aa4e..af199fb765 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -111,7 +111,7 @@ class topic extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - return $this->get_authenticated_recipients($users, $topic['forum_id'], $options); + return $this->get_authorised_recipients($users, $topic['forum_id'], $options); } /** From 0de1d65804ef8b68a189703b78381ed2787f6484 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 9 Aug 2014 12:49:32 +0200 Subject: [PATCH 4/6] [ticket/12742] Remove unneeded sort of users It doesn't matter which user will get the notification first so we shouldn't sort the users array. PHPBB3-12742 --- phpBB/phpbb/notification/type/base.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 48b368f7f9..895127f831 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -550,7 +550,6 @@ abstract class base implements \phpbb\notification\type\type_interface } $users = array_unique($users); - sort($users); $auth_read = $this->auth->acl_get_list($users, 'f_read', $forum_id); From 57d94b7bb42f5dd963156e28ecbb24d32967aa3f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 9 Aug 2014 17:43:28 +0200 Subject: [PATCH 5/6] [ticket/12742] Add sort options for notification types requiring sorting PHPBB3-12742 --- phpBB/phpbb/notification/type/base.php | 8 +++++++- phpBB/phpbb/notification/type/post.php | 2 +- phpBB/phpbb/notification/type/quote.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 895127f831..4ead06071e 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -540,9 +540,10 @@ abstract class base implements \phpbb\notification\type\type_interface * @param array $users Array of users that have subscribed to a notification * @param int $forum_id Forum ID of the forum * @param array $options Array of notification options + * @param bool $sort Whether the users array should be sorted. Default: false * @return array Array of users that are authorised recipients */ - protected function get_authorised_recipients($users, $forum_id, $options) + protected function get_authorised_recipients($users, $forum_id, $options, $sort = false) { if (empty($users)) { @@ -551,6 +552,11 @@ abstract class base implements \phpbb\notification\type\type_interface $users = array_unique($users); + if ($sort) + { + sort($users); + } + $auth_read = $this->auth->acl_get_list($users, 'f_read', $forum_id); if (empty($auth_read)) diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 1bd95bfbf6..1eba4a6a88 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -123,7 +123,7 @@ class post extends \phpbb\notification\type\base } $this->db->sql_freeresult($result); - $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options); + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); if (empty($notify_users)) { diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 42ec663bfc..5c3c822ec2 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -102,7 +102,7 @@ class quote extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - return $this->get_authorised_recipients($users, $post['forum_id'], $options); + return $this->get_authorised_recipients($users, $post['forum_id'], $options, true); } /** From 496b804a0f43b04f693f34d53304ff23d1d30d0c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 9 Aug 2014 17:48:59 +0200 Subject: [PATCH 6/6] [ticket/12742] Add sorting back to bookmark notification list of users PHPBB3-12742 --- phpBB/phpbb/notification/type/bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index d2e2700d2d..21180b3b53 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -83,7 +83,7 @@ class bookmark extends \phpbb\notification\type\post } $this->db->sql_freeresult($result); - $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options); + $notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true); if (empty($notify_users)) {