1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-20 07:42:09 +02:00

[ticket/14754] Only one email notification per topic

PHPBB3-14754
This commit is contained in:
Jakub Senko 2018-09-04 14:23:55 +02:00 committed by Marc Alexander
parent b732b4d8c8
commit a3e0117ff0
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
6 changed files with 101 additions and 2 deletions

View File

@ -206,8 +206,14 @@ services:
- '@user_loader'
- '@user'
- '@config'
- '@dbal.conn'
- '%core.root_path%'
- '%core.php_ext%'
- '%tables.topics_watch%'
- '%tables.topics_track%'
- '%tables.posts%'
- '%tables.forums_watch%'
- '%tables.forums_track%'
tags:
- { name: notification.method }

View File

@ -28,21 +28,51 @@ class email extends \phpbb\notification\method\messenger_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var string */
protected $topics_watch_table;
/** @var string */
protected $topics_track_table;
/** @var string */
protected $posts_table;
/** @var string */
protected $forums_watch_table;
/** @var string */
protected $forums_track_table;
/**
* Notification Method email Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $topics_watch_table
* @param string $topics_track_table
* @param string $posts_table
* @param string $forums_watch_table
* @param string $forums_track_table
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $topics_watch_table, $topics_track_table, $posts_table, $forums_watch_table, $forums_track_table)
{
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
$this->user = $user;
$this->config = $config;
$this->db = $db;
$this->topics_watch_table = $topics_watch_table;
$this->topics_track_table = $topics_track_table;
$this->posts_table = $posts_table;
$this->forums_watch_table = $forums_watch_table;
$this->forums_track_table = $forums_track_table;
}
/**
@ -68,6 +98,53 @@ class email extends \phpbb\notification\method\messenger_base
return parent::is_available($notification_type) && $this->config['email_enable'] && !empty($this->user->data['user_email']);
}
/**
* {@inheritdoc}
*/
public function get_notified_users($notification_type_id, array $options)
{
$notified_users = array();
if ($notification_type_id == 'notification.type.post' && !empty($options['item_parent_id']))
{
// Topics watch
$sql = 'SELECT tw.user_id
FROM ' . $this->topics_watch_table . ' tw
LEFT JOIN ' . $this->topics_track_table . ' tt
ON (tt.user_id = tw.user_id AND tt.topic_id = tw.topic_id)
LEFT JOIN ' . $this->posts_table . ' p
ON (p.topic_id = tw.topic_id)
WHERE tw.topic_id = ' . (int) $options['item_parent_id'] . '
AND p.post_time > tt.mark_time
HAVING COUNT(p.post_id) > 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$notified_users[$row['user_id']] = $row;
}
$this->db->sql_freeresult($result);
// Forums watch
$sql = 'SELECT fw.user_id
FROM ' . $this->forums_watch_table . ' fw
LEFT JOIN ' . $this->forums_track_table . ' ft
ON (ft.user_id = fw.user_id AND ft.forum_id = fw.forum_id)
LEFT JOIN ' . $this->posts_table . ' p
ON (p.forum_id = fw.forum_id)
WHERE p.topic_id = ' . (int) $options['item_parent_id'] . '
AND p.post_time > ft.mark_time
HAVING COUNT(p.post_id) > 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$notified_users[$row['user_id']] = $row;
}
$this->db->sql_freeresult($result);
}
return $notified_users;
}
/**
* Parse the queue and notify the users
*/

View File

@ -41,7 +41,7 @@ interface method_interface
/**
* Return the list of the users already notified
*
* @param int $notification_type_id Type of the notification
* @param int $notification_type_id ID of the notification type
* @param array $options
* @return array User
*/

View File

@ -457,6 +457,12 @@ class post extends \phpbb\notification\type\base
}
$data_array = array_merge(array(
'poster_id' => $post['poster_id'],
'topic_title' => $post['topic_title'],
'post_subject' => $post['post_subject'],
'post_username' => $post['post_username'],
'forum_id' => $post['forum_id'],
'forum_name' => $post['forum_name'],
'post_time' => $post['post_time'],
'post_id' => $post['post_id'],
'topic_id' => $post['topic_id']

View File

@ -103,6 +103,11 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
$phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications');
$phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types');
$phpbb_container->setParameter('tables.topics_watch', 'phpbb_topics_watch');
$phpbb_container->setParameter('tables.topics_track', 'phpbb_topics_track');
$phpbb_container->setParameter('tables.posts', 'phpbb_posts');
$phpbb_container->setParameter('tables.forums_watch', 'phpbb_forums_watch');
$phpbb_container->setParameter('tables.forums_track', 'phpbb_forums_track');
$this->notifications = new phpbb_notification_manager_helper(
array(),

View File

@ -130,6 +130,11 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
$phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications');
$phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types');
$phpbb_container->setParameter('tables.topics_watch', 'phpbb_topics_watch');
$phpbb_container->setParameter('tables.topics_track', 'phpbb_topics_track');
$phpbb_container->setParameter('tables.posts', 'phpbb_posts');
$phpbb_container->setParameter('tables.forums_watch', 'phpbb_forums_watch');
$phpbb_container->setParameter('tables.forums_track', 'phpbb_forums_track');
$phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE));
$phpbb_container->compile();