aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
authorNicofuma <github@nicofuma.fr>2014-04-28 14:00:27 +0200
committerTristan Darricau <tristan.darricau@sensiolabs.com>2015-07-13 22:41:13 +0200
commitbe0d4e20d4be8bc3217e5d025058e065b8f2071a (patch)
tree557a9732223835282b86ba8986120d978bca5260 /phpBB/phpbb
parent58d1d37c167c978257c9a4680d56835c63202738 (diff)
downloadforums-be0d4e20d4be8bc3217e5d025058e065b8f2071a.tar
forums-be0d4e20d4be8bc3217e5d025058e065b8f2071a.tar.gz
forums-be0d4e20d4be8bc3217e5d025058e065b8f2071a.tar.bz2
forums-be0d4e20d4be8bc3217e5d025058e065b8f2071a.tar.xz
forums-be0d4e20d4be8bc3217e5d025058e065b8f2071a.zip
[ticket/11444] Moving the in-board notifications to a method class
Currently the in-board method for the notifications is hardcoded and cannot be disabled. This method should be in his own class extending `phpbb\notification\method\method_interface`. It also add the possibility, for each method, to be enabled by default (ie: no entry in the DB => notification enabled). https://tracker.phpbb.com/browse/PHPBB3-11444 https://tracker.phpbb.com/browse/PHPBB3-11967 PHPBB3-11444
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/db/migration/data/v310/notifications_board.php73
-rw-r--r--phpBB/phpbb/notification/manager.php467
-rw-r--r--phpBB/phpbb/notification/method/base.php79
-rw-r--r--phpBB/phpbb/notification/method/board.php390
-rw-r--r--phpBB/phpbb/notification/method/method_interface.php104
-rw-r--r--phpBB/phpbb/notification/type/admin_activate_user.php2
-rw-r--r--phpBB/phpbb/notification/type/approve_post.php23
-rw-r--r--phpBB/phpbb/notification/type/approve_topic.php24
-rw-r--r--phpBB/phpbb/notification/type/base.php50
-rw-r--r--phpBB/phpbb/notification/type/bookmark.php31
-rw-r--r--phpBB/phpbb/notification/type/disapprove_post.php21
-rw-r--r--phpBB/phpbb/notification/type/disapprove_topic.php21
-rw-r--r--phpBB/phpbb/notification/type/group_request.php2
-rw-r--r--phpBB/phpbb/notification/type/group_request_approved.php4
-rw-r--r--phpBB/phpbb/notification/type/pm.php10
-rw-r--r--phpBB/phpbb/notification/type/post.php41
-rw-r--r--phpBB/phpbb/notification/type/post_in_queue.php21
-rw-r--r--phpBB/phpbb/notification/type/quote.php24
-rw-r--r--phpBB/phpbb/notification/type/report_pm.php10
-rw-r--r--phpBB/phpbb/notification/type/report_pm_closed.php23
-rw-r--r--phpBB/phpbb/notification/type/report_post.php10
-rw-r--r--phpBB/phpbb/notification/type/report_post_closed.php23
-rw-r--r--phpBB/phpbb/notification/type/topic.php10
-rw-r--r--phpBB/phpbb/notification/type/topic_in_queue.php21
-rw-r--r--phpBB/phpbb/notification/type/type_interface.php8
25 files changed, 1030 insertions, 462 deletions
diff --git a/phpBB/phpbb/db/migration/data/v310/notifications_board.php b/phpBB/phpbb/db/migration/data/v310/notifications_board.php
new file mode 100644
index 0000000000..525d94e984
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v310/notifications_board.php
@@ -0,0 +1,73 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\db\migration\data\v310;
+
+class notifications_board extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('\phpbb\db\migration\data\v310\notifications');
+ }
+
+ public function update_data()
+ {
+ return array(
+ array('config.add', array('allow_board_notifications', 1)),
+ array('custom', array(array($this, 'update_user_subscriptions'))),
+ array('custom', array(array($this, 'update_module'))),
+ );
+ }
+
+ public function update_module()
+ {
+ $sql = 'UPDATE ' . MODULES_TABLE . "
+ SET auth = 'cfg_allow_board_notifications'
+ WHERE module_basename = 'ucp_notifications'
+ AND module_mode = 'notification_list'";
+ $this->sql_query($sql);
+ }
+
+ public function update_user_subscriptions()
+ {
+ $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . "
+ SET method = 'notification.method.board'
+ WHERE method = ''";
+ $this->sql_query($sql);
+ }
+
+ public function revert_data()
+ {
+ return array(
+ array('custom', array(array($this, 'revert_user_subscriptions'))),
+ array('custom', array(array($this, 'revert_module'))),
+ );
+ }
+
+ public function revert_user_subscriptions()
+ {
+ $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . "
+ SET method = ''
+ WHERE method = 'notification.method.board'";
+ $this->sql_query($sql);
+ }
+
+ public function revert_module()
+ {
+ $sql = 'UPDATE ' . MODULES_TABLE . "
+ SET auth = ''
+ WHERE module_basename = 'ucp_notifications'
+ AND module_mode = 'notification_list'";
+ $this->sql_query($sql);
+ }
+}
diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php
index 38d7a13165..6b69dca817 100644
--- a/phpBB/phpbb/notification/manager.php
+++ b/phpBB/phpbb/notification/manager.php
@@ -13,7 +13,7 @@
namespace phpbb\notification;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use \Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Notifications service class
@@ -60,9 +60,6 @@ class manager
protected $notification_types_table;
/** @var string */
- protected $notifications_table;
-
- /** @var string */
protected $user_notifications_table;
/**
@@ -80,12 +77,11 @@ class manager
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_types_table
- * @param string $notifications_table
* @param string $user_notifications_table
*
* @return \phpbb\notification\manager
*/
- public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
+ public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\config\config $config, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $user_notifications_table)
{
$this->notification_types = $notification_types;
$this->notification_methods = $notification_methods;
@@ -102,13 +98,13 @@ class manager
$this->php_ext = $php_ext;
$this->notification_types_table = $notification_types_table;
- $this->notifications_table = $notifications_table;
$this->user_notifications_table = $user_notifications_table;
}
/**
- * Load the user's notifications
+ * Load the user's notifications for a given method
*
+ * @param string $method_name
* @param array $options Optional options to control what notifications are loaded
* notification_id Notification id to load (or array of notification ids)
* user_id User id to load notifications for (Default: $user->data['user_id'])
@@ -123,27 +119,21 @@ class manager
* 'notifications' array of notification type objects
* 'unread_count' number of unread notifications the user has if count_unread is true in the options
* 'total_count' number of notifications the user has if count_total is true in the options
+ * @throws \phpbb\notification\exception when the method doesn't refer to a class extending \phpbb\notification\method\method_interface
*/
- public function load_notifications(array $options = array())
+ public function load_notifications($method_name, array $options = array())
{
- // Merge default options
- $options = array_merge(array(
- 'notification_id' => false,
- 'user_id' => $this->user->data['user_id'],
- 'order_by' => 'notification_time',
- 'order_dir' => 'DESC',
- 'limit' => 0,
- 'start' => 0,
- 'all_unread' => false,
- 'count_unread' => false,
- 'count_total' => false,
- ), $options);
-
- // If all_unread, count_unread must be true
- $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread'];
+ $method = $this->get_method_class($method_name);
- // Anonymous users and bots never receive notifications
- if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE))
+ if (! $method instanceof \phpbb\notification\method\method_interface)
+ {
+ throw new \phpbb\notification\exception($this->user->lang('NOTIFICATION_METHOD_INVALID', $method_name));
+ }
+ else if ($method->is_available())
+ {
+ return $method->load_notifications($options);
+ }
+ else
{
return array(
'notifications' => array(),
@@ -151,172 +141,80 @@ class manager
'total_count' => 0,
);
}
-
- $notifications = $user_ids = array();
- $load_special = array();
- $total_count = $unread_count = 0;
-
- if ($options['count_unread'])
- {
- // Get the total number of unread notifications
- $sql = 'SELECT COUNT(n.notification_id) AS unread_count
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.user_id = ' . (int) $options['user_id'] . '
- AND n.notification_read = 0
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- $unread_count = (int) $this->db->sql_fetchfield('unread_count');
- $this->db->sql_freeresult($result);
- }
-
- if ($options['count_total'])
- {
- // Get the total number of notifications
- $sql = 'SELECT COUNT(n.notification_id) AS total_count
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.user_id = ' . (int) $options['user_id'] . '
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- $total_count = (int) $this->db->sql_fetchfield('total_count');
- $this->db->sql_freeresult($result);
- }
-
- if (!$options['count_total'] || $total_count)
- {
- $rowset = array();
-
- // Get the main notifications
- $sql = 'SELECT n.*, nt.notification_type_name
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.user_id = ' . (int) $options['user_id'] .
- (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id']) : '') . '
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1
- ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
- $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
-
- while ($row = $this->db->sql_fetchrow($result))
- {
- $rowset[$row['notification_id']] = $row;
- }
- $this->db->sql_freeresult($result);
-
- // Get all unread notifications
- if ($unread_count && $options['all_unread'] && !empty($rowset))
- {
- $sql = 'SELECT n.*, nt.notification_type_name
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.user_id = ' . (int) $options['user_id'] . '
- AND n.notification_read = 0
- AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1
- ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
- $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
-
- while ($row = $this->db->sql_fetchrow($result))
- {
- $rowset[$row['notification_id']] = $row;
- }
- $this->db->sql_freeresult($result);
- }
-
- foreach ($rowset as $row)
- {
- $notification = $this->get_item_type_class($row['notification_type_name'], $row);
-
- // Array of user_ids to query all at once
- $user_ids = array_merge($user_ids, $notification->users_to_query());
-
- // Some notification types also require querying additional tables themselves
- if (!isset($load_special[$row['notification_type_name']]))
- {
- $load_special[$row['notification_type_name']] = array();
- }
- $load_special[$row['notification_type_name']] = array_merge($load_special[$row['notification_type_name']], $notification->get_load_special());
-
- $notifications[$row['notification_id']] = $notification;
- }
-
- $this->user_loader->load_users($user_ids);
-
- // Allow each type to load its own special items
- foreach ($load_special as $item_type => $data)
- {
- $item_class = $this->get_item_type_class($item_type);
-
- $item_class->load_special($data, $notifications);
- }
- }
-
- return array(
- 'notifications' => $notifications,
- 'unread_count' => $unread_count,
- 'total_count' => $total_count,
- );
}
/**
- * Mark notifications read
+ * Mark notifications read or unread for all available methods
*
* @param bool|string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item types
* @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids
* @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
* @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
- public function mark_notifications_read($notification_type_name, $item_id, $user_id, $time = false)
+ public function mark_notifications($notification_type_name, $item_id, $user_id, $time = false, $mark_read = true)
{
- $time = ($time !== false) ? $time : time();
-
- $sql = 'UPDATE ' . $this->notifications_table . "
- SET notification_read = 1
- WHERE notification_time <= " . (int) $time .
- (($notification_type_name !== false) ? ' AND ' .
- (is_array($notification_type_name) ? $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : 'notification_type_id = ' . $this->get_notification_type_id($notification_type_name)) : '') .
- (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '') .
- (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '');
- $this->db->sql_query($sql);
+ if (is_array($notification_type_name))
+ {
+ $notification_type_id = $this->get_notification_type_ids($notification_type_name);
+ }
+ else if ($notification_type_name !== false)
+ {
+ $notification_type_id = $this->get_notification_type_id($notification_type_name);
+ }
+ else
+ {
+ $notification_type_id = false;
+ }
+
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->mark_notifications($notification_type_id, $item_id, $user_id, $time, $mark_read);
+ }
}
/**
- * Mark notifications read from a parent identifier
+ * Mark notifications read or unread from a parent identifier for all available methods
*
* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
* @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids
* @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
* @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
- public function mark_notifications_read_by_parent($notification_type_name, $item_parent_id, $user_id, $time = false)
+ public function mark_notifications_by_parent($notification_type_name, $item_parent_id, $user_id, $time = false, $mark_read = true)
{
- $time = ($time !== false) ? $time : time();
-
- $sql = 'UPDATE ' . $this->notifications_table . "
- SET notification_read = 1
- WHERE notification_time <= " . (int) $time .
- (($notification_type_name !== false) ? ' AND ' .
- (is_array($notification_type_name) ? $this->db->sql_in_set('notification_type_id', $this->get_notification_type_ids($notification_type_name)) : 'notification_type_id = ' . $this->get_notification_type_id($notification_type_name)) : '') .
- (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
- (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');
- $this->db->sql_query($sql);
+ if (is_array($notification_type_name))
+ {
+ $notification_type_id = $this->get_notification_type_ids($notification_type_name);
+ }
+ else
+ {
+ $notification_type_id = $this->get_notification_type_id($notification_type_name);
+ }
+
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time, $mark_read);
+ }
}
/**
- * Mark notifications read
+ * Mark notifications read or unread for a given method
*
+ * @param string $method_name
* @param int|array $notification_id Notification id or array of notification ids.
* @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
- public function mark_notifications_read_by_id($notification_id, $time = false)
+ public function mark_notifications_by_id($method_name, $notification_id, $time = false, $mark_read = true)
{
- $time = ($time !== false) ? $time : time();
+ $method = $this->get_method_class($method_name);
- $sql = 'UPDATE ' . $this->notifications_table . "
- SET notification_read = 1
- WHERE notification_time <= " . (int) $time . '
- AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id);
- $this->db->sql_query($sql);
+ if ($method instanceof \phpbb\notification\method\method_interface && $method->is_available())
+ {
+ $method->mark_notifications_by_id($notification_id, $time, $mark_read);
+ }
}
/**
@@ -411,18 +309,15 @@ class manager
// Make sure not to send new notifications to users who've already been notified about this item
// This may happen when an item was added, but now new users are able to see the item
- $sql = 'SELECT n.user_id
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.notification_type_id = ' . (int) $notification_type_id . '
- AND n.item_id = ' . (int) $item_id . '
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
+ // We remove each user which was already notified by at least one method.
+ foreach ($this->get_subscription_methods_instances() as $method)
{
- unset($notify_users[$row['user_id']]);
+ $notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id));
+ foreach ($notified_users as $user => $notifications)
+ {
+ unset($notify_users[$user]);
+ }
}
- $this->db->sql_freeresult($result);
if (!sizeof($notify_users))
{
@@ -434,8 +329,6 @@ class manager
$pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
unset($notification);
- $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);
-
// Go through each user so we can insert a row in the DB and then notify them by their desired means
foreach ($notify_users as $user => $methods)
{
@@ -443,8 +336,8 @@ class manager
$notification->user_id = (int) $user;
- // Insert notification row using buffer.
- $insert_buffer->insert($notification->create_insert_array($data, $pre_create_data));
+ // Generate the insert_array
+ $notification->create_insert_array($data, $pre_create_data);
// Users are needed to send notifications
$user_ids = array_merge($user_ids, $notification->users_to_query());
@@ -452,20 +345,15 @@ class manager
foreach ($methods as $method)
{
// setup the notification methods and add the notification to the queue
- if ($method) // blank means we just insert it as a notification, but do not notify them by any other means
+ if (!isset($notification_methods[$method]))
{
- if (!isset($notification_methods[$method]))
- {
- $notification_methods[$method] = $this->get_method_class($method);
- }
-
- $notification_methods[$method]->add_to_queue($notification);
+ $notification_methods[$method] = $this->get_method_class($method);
}
+
+ $notification_methods[$method]->add_to_queue($notification);
}
}
- $insert_buffer->flush();
-
// We need to load all of the users to send notifications
$this->user_loader->load_users($user_ids);
@@ -477,12 +365,13 @@ class manager
}
/**
- * Update a notification
+ * Update notification
*
* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
* @param array $data Data specific for this type that will be updated
+ * @param array $options
*/
- public function update_notifications($notification_type_name, $data)
+ public function update_notifications($notification_type_name, array $data, array $options = array())
{
if (is_array($notification_type_name))
{
@@ -494,27 +383,27 @@ class manager
return;
}
- $notification = $this->get_item_type_class($notification_type_name);
+ $this->update_notification($this->get_item_type_class($notification_type_name), $data, $options);
+ }
- // Allow the notifications class to over-ride the update_notifications functionality
- if (method_exists($notification, 'update_notifications'))
+ /**
+ * Update a notification
+ *
+ * @param \phpbb\notification\type\type_interface $notification The notification
+ * @param array $data Data specific for this type that will be updated
+ * @param array $options
+ */
+ public function update_notification(\phpbb\notification\type\type_interface $notification, array $data, array $options = array())
+ {
+ if (empty($options))
{
- // Return False to over-ride the rest of the update
- if ($notification->update_notifications($data) === false)
- {
- return;
- }
+ $options['item_id'] = $notification->get_item_id($data);
}
- $notification_type_id = $this->get_notification_type_id($notification_type_name);
- $item_id = $notification->get_item_id($data);
- $update_array = $notification->create_update_array($data);
-
- $sql = 'UPDATE ' . $this->notifications_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $update_array) . '
- WHERE notification_type_id = ' . (int) $notification_type_id . '
- AND item_id = ' . (int) $item_id;
- $this->db->sql_query($sql);
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->update_notification($notification, $data, $options);
+ }
}
/**
@@ -523,14 +412,15 @@ class manager
* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)
* @param int|array $item_id Identifier within the type (or array of ids)
* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
+ * @param mixed $user_id User id (Default: false; not checked)
*/
- public function delete_notifications($notification_type_name, $item_id, $parent_id = false)
+ public function delete_notifications($notification_type_name, $item_id, $parent_id = false, $user_id = false)
{
if (is_array($notification_type_name))
{
foreach ($notification_type_name as $type)
{
- $this->delete_notifications($type, $item_id, $parent_id);
+ $this->delete_notifications($type, $item_id, $parent_id, $user_id);
}
return;
@@ -538,11 +428,10 @@ class manager
$notification_type_id = $this->get_notification_type_id($notification_type_name);
- $sql = 'DELETE FROM ' . $this->notifications_table . '
- WHERE notification_type_id = ' . (int) $notification_type_id . '
- AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) .
- (($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $parent_id)) : '');
- $this->db->sql_query($sql);
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->delete_notifications($notification_type_id, $item_id, $parent_id, $user_id);
+ }
}
/**
@@ -593,16 +482,53 @@ class manager
{
$subscription_methods = array();
+ foreach ($this->get_available_subscription_methods() as $method_name => $method)
+ {
+ $subscription_methods[$method_name] = array(
+ 'id' => $method->get_type(),
+ 'lang' => str_replace('.', '_', strtoupper($method->get_type())),
+ );
+ }
+
+ return $subscription_methods;
+ }
+
+ /**
+ * Get all of the subscription methods
+ *
+ * @return array Array of method's instances
+ */
+ private function get_subscription_methods_instances()
+ {
+ $subscription_methods = array();
+
foreach ($this->notification_methods as $method_name => $data)
{
$method = $this->get_method_class($method_name);
- if ($method instanceof \phpbb\notification\method\method_interface && $method->is_available())
+ if ($method instanceof \phpbb\notification\method\method_interface)
+ {
+ $subscription_methods[$method_name] = $method;
+ }
+ }
+
+ return $subscription_methods;
+ }
+
+ /**
+ * Get all of the available subscription methods
+ *
+ * @return array Array of method's instances
+ */
+ private function get_available_subscription_methods()
+ {
+ $subscription_methods = array();
+
+ foreach ($this->get_subscription_methods_instances() as $method_name => $method)
+ {
+ if ($method->is_available())
{
- $subscription_methods[$method_name] = array(
- 'id' => $method->get_type(),
- 'lang' => str_replace('.', '_', strtoupper($method->get_type())),
- );
+ $subscription_methods[$method_name] = $method;
}
}
@@ -646,7 +572,7 @@ class manager
*/
public function get_global_subscriptions($user_id = false)
{
- $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
+ $user_id = $user_id ?: $this->user->data['user_id'];
$subscriptions = array();
@@ -656,11 +582,9 @@ class manager
{
foreach ($types as $id => $type)
{
-
if (empty($user_notifications[$id]))
{
- // No rows at all, default to ''
- $subscriptions[$id] = array('');
+ $subscriptions[$id] = $this->get_default_methods();
}
else
{
@@ -690,15 +614,20 @@ class manager
*
* @param string $item_type Type identifier of the subscription
* @param int $item_id The id of the item
- * @param string $method The method of the notification e.g. '', 'email', or 'jabber'
+ * @param string $method The method of the notification e.g. 'board', 'email', or 'jabber'
+ * (if null a subscription will be added for all the defaults methods)
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
- public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
+ public function add_subscription($item_type, $item_id = 0, $method = null, $user_id = false)
{
- if ($method !== '')
+ if ($method === null)
{
- // Make sure to subscribe them to the base subscription
- $this->add_subscription($item_type, $item_id, '', $user_id);
+ foreach ($this->get_default_methods() as $method_name)
+ {
+ $this->add_subscription($item_type, $item_id, $method_name, $user_id);
+ }
+
+ return;
}
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
@@ -742,33 +671,23 @@ class manager
*
* @param string $item_type Type identifier of the subscription
* @param int $item_id The id of the item
- * @param string $method The method of the notification e.g. '', 'email', or 'jabber'
+ * @param string $method The method of the notification e.g. 'board', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
- public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
+ public function delete_subscription($item_type, $item_id = 0, $method = null, $user_id = false)
{
- $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
-
- // If no method, make sure that no other notification methods for this item are selected before deleting
- if ($method === '')
+ if ($method === null)
{
- $sql = 'SELECT COUNT(*) as num_notifications
- FROM ' . $this->user_notifications_table . "
- WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
- AND item_id = " . (int) $item_id . '
- AND user_id = ' .(int) $user_id . "
- AND method <> ''
- AND notify = 1";
- $this->db->sql_query($sql);
- $num_notifications = $this->db->sql_fetchfield('num_notifications');
- $this->db->sql_freeresult();
-
- if ($num_notifications)
+ foreach ($this->get_default_methods() as $method_name)
{
- return;
+ $this->delete_subscription($item_type, $item_id, $method_name, $user_id);
}
+
+ return;
}
+ $user_id = $user_id ?: $this->user->data['user_id'];
+
$sql = 'UPDATE ' . $this->user_notifications_table . "
SET notify = 0
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
@@ -828,15 +747,11 @@ class manager
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
- $sql = 'DELETE FROM ' . $this->notifications_table . '
- WHERE notification_type_id = ' . (int) $notification_type_id;
- $this->db->sql_query($sql);
-
- $sql = 'DELETE FROM ' . $this->notification_types_table . '
- WHERE notification_type_id = ' . (int) $notification_type_id;
- $this->db->sql_query($sql);
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->purge_notifications($notification_type_id);
+ }
- $this->cache->destroy('notification_type_ids');
}
catch (\phpbb\notification\exception $e)
{
@@ -869,12 +784,28 @@ class manager
*/
public function prune_notifications($timestamp, $only_read = true)
{
- $sql = 'DELETE FROM ' . $this->notifications_table . '
- WHERE notification_time < ' . (int) $timestamp .
- (($only_read) ? ' AND notification_read = 1' : '');
- $this->db->sql_query($sql);
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $method->prune_notifications($timestamp, $only_read);
+ }
+ }
+
+ /**
+ * Helper to get the list of methods enabled by default
+ */
+ public function get_default_methods()
+ {
+ $default_methods = array();
+
+ foreach ($this->notification_methods as $method)
+ {
+ if ($method->is_enabled_by_default() && $method->is_available())
+ {
+ $default_methods[] = $method->get_type();
+ }
+ }
- $this->config->set('read_notification_last_gc', time(), false);
+ return $default_methods;
}
/**
@@ -977,4 +908,24 @@ class manager
return $notification_type_ids;
}
+
+ /**
+ * Find the users which are already notified
+ *
+ * @param bool|string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to retrieve all item types
+ * @param array $options
+ * @return array The list of the notified users
+ */
+ public function get_notified_users($notification_type_name, array $options)
+ {
+ $notification_type_id = $this->get_notification_type_id($notification_type_name);
+
+ $notified_users = array();
+ foreach ($this->get_available_subscription_methods() as $method)
+ {
+ $notified_users = $notified_users + $method->get_notified_users($notification_type_id, $options);
+ }
+
+ return $notified_users;
+ }
}
diff --git a/phpBB/phpbb/notification/method/base.php b/phpBB/phpbb/notification/method/base.php
index 6ee1d2984a..240b2ddbac 100644
--- a/phpBB/phpbb/notification/method/base.php
+++ b/phpBB/phpbb/notification/method/base.php
@@ -94,6 +94,36 @@ abstract class base implements \phpbb\notification\method\method_interface
}
/**
+ * Is the method enable by default?
+ *
+ * @return bool
+ */
+ public function is_enabled_by_default()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_notified_users($notification_type_id, array $options)
+ {
+ return array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function load_notifications(array $options = array())
+ {
+ return array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ 'total_count' => 0,
+ );
+ }
+
+ /**
* Add a notification to the queue
*
* @param \phpbb\notification\type\type_interface $notification
@@ -104,6 +134,55 @@ abstract class base implements \phpbb\notification\method\method_interface
}
/**
+ * {@inheritdoc}
+ */
+ public function update_notification($notification, array $data, array $options)
+ {
+ }
+
+ /**
+ * {@inheritdoc
+ */
+ public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prune_notifications($timestamp, $only_read = true)
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function purge_notifications($notification_type_id)
+ {
+ }
+
+ /**
* Empty the queue
*/
protected function empty_queue()
diff --git a/phpBB/phpbb/notification/method/board.php b/phpBB/phpbb/notification/method/board.php
new file mode 100644
index 0000000000..99853e2f81
--- /dev/null
+++ b/phpBB/phpbb/notification/method/board.php
@@ -0,0 +1,390 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\notification\method;
+
+/**
+* In Board notification method class
+* This class handles in board notifications. This method is enabled by default.
+*
+* @package notifications
+*/
+class board extends \phpbb\notification\method\base
+{
+ /** @var string */
+ protected $notification_types_table;
+
+ /** @var string */
+ protected $notifications_table;
+
+ /**
+ * Notification Method Board Constructor
+ *
+ * @param \phpbb\user_loader $user_loader
+ * @param \phpbb\db\driver\driver_interface $db
+ * @param \phpbb\cache\driver\driver_interface $cache
+ * @param \phpbb\user $user
+ * @param \phpbb\auth\auth $auth
+ * @param \phpbb\config\config $config
+ * @param string $phpbb_root_path
+ * @param string $php_ext
+ * @param string $notification_types_table
+ * @param string $notifications_table
+ * @return \phpbb\notification\method\board
+ */
+ public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table)
+ {
+ $this->user_loader = $user_loader;
+ $this->db = $db;
+ $this->cache = $cache;
+ $this->user = $user;
+ $this->auth = $auth;
+ $this->config = $config;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+
+ $this->notification_types_table = $notification_types_table;
+ $this->notifications_table = $notifications_table;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function add_to_queue(\phpbb\notification\type\type_interface $notification)
+ {
+ $this->queue[] = $notification;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_type()
+ {
+ return 'notification.method.board';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function is_available()
+ {
+ return $this->config['allow_board_notifications'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function is_enabled_by_default()
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_notified_users($notification_type_id, array $options)
+ {
+ $notified_users = array();
+ $sql = 'SELECT n.*
+ FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
+ WHERE n.notification_type_id = ' . (int) $notification_type_id .
+ (isset($options['item_id']) ? ' AND n.item_id = ' . (int) $options['item_id'] : '') .
+ (isset($options['item_parent_id']) ? ' AND n.item_parent_id = ' . (int) $options['item_parent_id'] : '') .
+ (isset($options['user_id']) ? ' AND n.user_id = ' . (int) $options['user_id'] : '') .
+ (isset($options['read']) ? ' AND n.notification_read = ' . (int) $options['read'] : '') .'
+ AND nt.notification_type_id = n.notification_type_id
+ AND nt.notification_type_enabled = 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;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function load_notifications(array $options = array())
+ {
+ // Merge default options
+ $options = array_merge(array(
+ 'notification_id' => false,
+ 'user_id' => $this->user->data['user_id'],
+ 'order_by' => 'notification_time',
+ 'order_dir' => 'DESC',
+ 'limit' => 0,
+ 'start' => 0,
+ 'all_unread' => false,
+ 'count_unread' => false,
+ 'count_total' => false,
+ ), $options);
+
+ // If all_unread, count_unread must be true
+ $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread'];
+
+ // Anonymous users and bots never receive notifications
+ if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE))
+ {
+ return array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ 'total_count' => 0,
+ );
+ }
+
+ $notifications = $user_ids = array();
+ $load_special = array();
+ $total_count = $unread_count = 0;
+
+ if ($options['count_unread'])
+ {
+ // Get the total number of unread notifications
+ $sql = 'SELECT COUNT(n.notification_id) AS unread_count
+ FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
+ WHERE n.user_id = ' . (int) $options['user_id'] . '
+ AND n.notification_read = 0
+ AND nt.notification_type_id = n.notification_type_id
+ AND nt.notification_type_enabled = 1';
+ $result = $this->db->sql_query($sql);
+ $unread_count = (int) $this->db->sql_fetchfield('unread_count');
+ $this->db->sql_freeresult($result);
+ }
+
+ if ($options['count_total'])
+ {
+ // Get the total number of notifications
+ $sql = 'SELECT COUNT(n.notification_id) AS total_count
+ FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
+ WHERE n.user_id = ' . (int) $options['user_id'] . '
+ AND nt.notification_type_id = n.notification_type_id
+ AND nt.notification_type_enabled = 1';
+ $result = $this->db->sql_query($sql);
+ $total_count = (int) $this->db->sql_fetchfield('total_count');
+ $this->db->sql_freeresult($result);
+ }
+
+ if (!$options['count_total'] || $total_count)
+ {
+ $rowset = array();
+
+ // Get the main notifications
+ $sql = 'SELECT n.*, nt.notification_type_name
+ FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
+ WHERE n.user_id = ' . (int) $options['user_id'] .
+ (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id']) : '') . '
+ AND nt.notification_type_id = n.notification_type_id
+ AND nt.notification_type_enabled = 1
+ ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
+ $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $rowset[$row['notification_id']] = $row;
+ }
+ $this->db->sql_freeresult($result);
+
+ // Get all unread notifications
+ if ($unread_count && $options['all_unread'] && !empty($rowset))
+ {
+ $sql = 'SELECT n.*, nt.notification_type_name
+ FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
+ WHERE n.user_id = ' . (int) $options['user_id'] . '
+ AND n.notification_read = 0
+ AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
+ AND nt.notification_type_id = n.notification_type_id
+ AND nt.notification_type_enabled = 1
+ ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
+ $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $rowset[$row['notification_id']] = $row;
+ }
+ $this->db->sql_freeresult($result);
+ }
+
+ foreach ($rowset as $row)
+ {
+ $notification = $this->notification_manager->get_item_type_class($row['notification_type_name'], $row);
+
+ // Array of user_ids to query all at once
+ $user_ids = array_merge($user_ids, $notification->users_to_query());
+
+ // Some notification types also require querying additional tables themselves
+ if (!isset($load_special[$row['notification_type_name']]))
+ {
+ $load_special[$row['notification_type_name']] = array();
+ }
+ $load_special[$row['notification_type_name']] = array_merge($load_special[$row['notification_type_name']], $notification->get_load_special());
+
+ $notifications[$row['notification_id']] = $notification;
+ }
+
+ $this->user_loader->load_users($user_ids);
+
+ // Allow each type to load its own special items
+ foreach ($load_special as $item_type => $data)
+ {
+ $item_class = $this->notification_manager->get_item_type_class($item_type);
+
+ $item_class->load_special($data, $notifications);
+ }
+ }
+
+ return array(
+ 'notifications' => $notifications,
+ 'unread_count' => $unread_count,
+ 'total_count' => $total_count,
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function notify()
+ {
+ $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);
+
+ foreach ($this->queue as $notification)
+ {
+ $data = $notification->get_insert_array();
+ $insert_buffer->insert($data);
+ }
+
+ $insert_buffer->flush();
+
+ // We're done, empty the queue
+ $this->empty_queue();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function update_notification($notification, array $data, array $options)
+ {
+ // Allow the notifications class to over-ride the update_notifications functionality
+ if (method_exists($notification, 'update_notifications'))
+ {
+ // Return False to over-ride the rest of the update
+ if ($notification->update_notifications($data) === false)
+ {
+ return;
+ }
+ }
+
+ $notification_type_id = $this->notification_manager->get_notification_type_id($notification->get_type());
+ $update_array = $notification->create_update_array($data);
+
+ $sql = 'UPDATE ' . $this->notifications_table . '
+ SET ' . $this->db->sql_build_array('UPDATE', $update_array) . '
+ WHERE notification_type_id = ' . (int) $notification_type_id .
+ (isset($options['item_id']) ? ' AND item_id = ' . (int) $options['item_id'] : '') .
+ (isset($options['item_parent_id']) ? ' AND item_parent_id = ' . (int) $options['item_parent_id'] : '') .
+ (isset($options['user_id']) ? ' AND user_id = ' . (int) $options['user_id'] : '') .
+ (isset($options['read']) ? ' AND notification_read = ' . (int) $options['read'] : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
+ {
+ $time = ($time !== false) ? $time : time();
+
+ $sql = 'UPDATE ' . $this->notifications_table . '
+ SET notification_read = ' . ($mark_read ? 1 : 0) . '
+ WHERE notification_time <= ' . (int) $time .
+ (($notification_type_id !== false) ? ' AND ' .
+ (is_array($notification_type_id) ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : 'notification_type_id = ' . $notification_type_id) : '') .
+ (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '') .
+ (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
+ {
+ $time = ($time !== false) ? $time : time();
+
+ $sql = 'UPDATE ' . $this->notifications_table . '
+ SET notification_read = ' . ($mark_read ? 1 : 0) . '
+ WHERE notification_time <= ' . (int) $time .
+ (($notification_type_id !== false) ? ' AND ' .
+ (is_array($notification_type_id) ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : 'notification_type_id = ' . $notification_type_id) : '') .
+ (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
+ (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true)
+ {
+ $time = ($time !== false) ? $time : time();
+
+ $sql = 'UPDATE ' . $this->notifications_table . '
+ SET notification_read = ' . ($mark_read ? 1 : 0) . '
+ WHERE notification_time <= ' . (int) $time . '
+ AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id);
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false)
+ {
+ $sql = 'DELETE FROM ' . $this->notifications_table . '
+ WHERE notification_type_id = ' . (int) $notification_type_id . '
+ AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) .
+ (($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $parent_id)) : '') .
+ (($user_id !== false) ? ' AND ' . ((is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id)) : '');
+ $this->db->sql_query($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prune_notifications($timestamp, $only_read = true)
+ {
+ $sql = 'DELETE FROM ' . $this->notifications_table . '
+ WHERE notification_time < ' . (int) $timestamp .
+ (($only_read) ? ' AND notification_read = 1' : '');
+ $this->db->sql_query($sql);
+
+ $this->config->set('read_notification_last_gc', time(), false);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function purge_notifications($notification_type_id)
+ {
+ $sql = 'DELETE FROM ' . $this->notifications_table . '
+ WHERE notification_type_id = ' . (int) $notification_type_id;
+ $this->db->sql_query($sql);
+
+ $sql = 'DELETE FROM ' . $this->notification_types_table . '
+ WHERE notification_type_id = ' . (int) $notification_type_id;
+ $this->db->sql_query($sql);
+
+ $this->cache->destroy('notification_type_ids');
+ }
+}
diff --git a/phpBB/phpbb/notification/method/method_interface.php b/phpBB/phpbb/notification/method/method_interface.php
index 76b0de179c..c2e4940485 100644
--- a/phpBB/phpbb/notification/method/method_interface.php
+++ b/phpBB/phpbb/notification/method/method_interface.php
@@ -26,12 +26,48 @@ interface method_interface
public function get_type();
/**
+ * Is the method enable by default?
+ *
+ * @return bool
+ */
+ public function is_enabled_by_default();
+
+ /**
* Is this method available for the user?
* This is checked on the notifications options
*/
public function is_available();
/**
+ * Return the list of the users already notified
+ *
+ * @param int $notification_type_id Type of the notification
+ * @param array $options
+ * @return array User
+ */
+ public function get_notified_users($notification_type_id, array $options);
+
+ /**
+ * Load the user's notifications
+ *
+ * @param array $options Optional options to control what notifications are loaded
+ * notification_id Notification id to load (or array of notification ids)
+ * user_id User id to load notifications for (Default: $user->data['user_id'])
+ * order_by Order by (Default: notification_time)
+ * order_dir Order direction (Default: DESC)
+ * limit Number of notifications to load (Default: 5)
+ * start Notifications offset (Default: 0)
+ * all_unread Load all unread notifications? If set to true, count_unread is set to true (Default: false)
+ * count_unread Count all unread notifications? (Default: false)
+ * count_total Count all notifications? (Default: false)
+ * @return array Array of information based on the request with keys:
+ * 'notifications' array of notification type objects
+ * 'unread_count' number of unread notifications the user has if count_unread is true in the options
+ * 'total_count' number of notifications the user has if count_total is true in the options
+ */
+ public function load_notifications(array $options = array());
+
+ /**
* Add a notification to the queue
*
* @param \phpbb\notification\type\type_interface $notification
@@ -42,4 +78,72 @@ interface method_interface
* Parse the queue and notify the users
*/
public function notify();
+
+ /**
+ * Update a notification
+ *
+ * @param \phpbb\notification\type\type_interface $notification Notification to update
+ * @param array $data Data specific for this type that will be updated
+ * @param array $options
+ */
+ public function update_notification($notification, array $data, array $options);
+
+ /**
+ * Mark notifications read or unread
+ *
+ * @param bool|string $notification_type_id Type identifier of item types. False to mark read for all item types
+ * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids
+ * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
+ */
+ public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true);
+
+ /**
+ * Mark notifications read or unread from a parent identifier
+ *
+ * @param string $notification_type_id Type identifier of item types
+ * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids
+ * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
+ */
+ public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true);
+
+ /**
+ * Mark notifications read or unread
+ *
+ * @param int $notification_id Notification id of notification ids.
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ * @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
+ */
+ public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true);
+
+ /**
+ * Delete a notification
+ *
+ * @param string $notification_type_id Type identifier of item types
+ * @param int|array $item_id Identifier within the type (or array of ids)
+ * @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
+ * @param mixed $user_id User id (Default: false; not checked)
+ */
+ public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false);
+
+ /**
+ * Delete all notifications older than a certain time
+ *
+ * @param int $timestamp Unix timestamp to delete all notifications that were created before
+ * @param bool $only_read True (default) to only prune read notifications
+ */
+ public function prune_notifications($timestamp, $only_read = true);
+
+ /**
+ * Purge all notifications of a certain type
+ *
+ * This should be called when an extension which has notification types
+ * is purged so that all those notifications are removed
+ *
+ * @param string $notification_type_id Type identifier of the subscription
+ */
+ public function purge_notifications($notification_type_id);
}
diff --git a/phpBB/phpbb/notification/type/admin_activate_user.php b/phpBB/phpbb/notification/type/admin_activate_user.php
index 0e2924e29c..5b7e58bd92 100644
--- a/phpBB/phpbb/notification/type/admin_activate_user.php
+++ b/phpBB/phpbb/notification/type/admin_activate_user.php
@@ -164,6 +164,6 @@ class admin_activate_user extends \phpbb\notification\type\base
$this->set_data('user_actkey', $user['user_actkey']);
$this->notification_time = $user['user_regdate'];
- return parent::create_insert_array($user, $pre_create_data);
+ parent::create_insert_array($user, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php
index e6c38b2ede..9666647bd8 100644
--- a/phpBB/phpbb/notification/type/approve_post.php
+++ b/phpBB/phpbb/notification/type/approve_post.php
@@ -79,7 +79,7 @@ class approve_post extends \phpbb\notification\type\post
), $options);
$users = array();
- $users[$post['poster_id']] = array('');
+ $users[$post['poster_id']] = $this->notification_manager->get_default_methods();
return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array(
'item_type' => self::$notification_option['id'],
@@ -107,21 +107,24 @@ class approve_post extends \phpbb\notification\type\post
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('post_subject', $post['post_subject']);
- $data = parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php
index 5f5b96f335..e9f4c32852 100644
--- a/phpBB/phpbb/notification/type/approve_topic.php
+++ b/phpBB/phpbb/notification/type/approve_topic.php
@@ -79,7 +79,7 @@ class approve_topic extends \phpbb\notification\type\topic
), $options);
$users = array();
- $users[$post['poster_id']] = array('');
+ $users[$post['poster_id']] = $this->notification_manager->get_default_methods();
return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array(
'item_type' => self::$notification_option['id'],
@@ -107,19 +107,23 @@ class approve_topic extends \phpbb\notification\type\topic
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
- $data = parent::create_insert_array($post, $pre_create_data);
- $this->notification_time = $data['notification_time'] = time();
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php
index 1cf0498138..843ab98de8 100644
--- a/phpBB/phpbb/notification/type/base.php
+++ b/phpBB/phpbb/notification/type/base.php
@@ -52,9 +52,6 @@ abstract class base implements \phpbb\notification\type\type_interface
protected $notification_types_table;
/** @var string */
- protected $notifications_table;
-
- /** @var string */
protected $user_notifications_table;
/**
@@ -100,11 +97,10 @@ abstract class base implements \phpbb\notification\type\type_interface
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_types_table
- * @param string $notifications_table
* @param string $user_notifications_table
* @return \phpbb\notification\type\base
*/
- public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
+ public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $user_notifications_table)
{
$this->user_loader = $user_loader;
$this->db = $db;
@@ -117,7 +113,6 @@ abstract class base implements \phpbb\notification\type\type_interface
$this->php_ext = $php_ext;
$this->notification_types_table = $notification_types_table;
- $this->notifications_table = $notifications_table;
$this->user_notifications_table = $user_notifications_table;
}
@@ -207,12 +202,7 @@ abstract class base implements \phpbb\notification\type\type_interface
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $type_data Data unique to this notification type
- * @param array $pre_create_data Data from pre_create_insert_array()
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($type_data, $pre_create_data = array())
{
@@ -227,7 +217,13 @@ abstract class base implements \phpbb\notification\type\type_interface
'notification_data' => array(),
), $this->data);
+ }
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
$data = $this->data;
$data['notification_data'] = serialize($data['notification_data']);
@@ -244,7 +240,8 @@ abstract class base implements \phpbb\notification\type\type_interface
*/
public function create_update_array($type_data)
{
- $data = $this->create_insert_array($type_data);
+ $this->create_insert_array($type_data);
+ $data = $this->get_insert_array();
// Unset data unique to each row
unset(
@@ -497,8 +494,8 @@ abstract class base implements \phpbb\notification\type\type_interface
{
if (!in_array($user_id, $resulting_user_ids) && !isset($options['ignore_users'][$user_id]))
{
- // No rows at all for this user, default to ''
- $rowset[$user_id] = array('');
+ // No rows at all for this user, use the default methods
+ $rowset[$user_id] = $this->notification_manager->get_default_methods();
}
}
@@ -516,22 +513,21 @@ abstract class base implements \phpbb\notification\type\type_interface
{
$this->notification_read = (bool) !$unread;
- $where = array(
- 'notification_type_id = ' . (int) $this->notification_type_id,
- 'item_id = ' . (int) $this->item_id,
- 'user_id = ' . (int) $this->user_id,
- );
- $where = implode(' AND ', $where);
-
if ($return)
{
+ $where = array(
+ 'notification_type_id = ' . (int) $this->notification_type_id,
+ 'item_id = ' . (int) $this->item_id,
+ 'user_id = ' . (int) $this->user_id,
+ );
+
+ $where = implode(' AND ', $where);
return $where;
}
-
- $sql = 'UPDATE ' . $this->notifications_table . '
- SET notification_read = ' . (int) $this->notification_read . '
- WHERE ' . $where;
- $this->db->sql_query($sql);
+ else
+ {
+ $this->notification_manager->mark_notifications($this->get_type(), (int) $this->item_id, (int) $this->user_id, $this->notification_read);
+ }
}
/**
diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php
index e6a695e875..4f66a1ef5c 100644
--- a/phpBB/phpbb/notification/type/bookmark.php
+++ b/phpBB/phpbb/notification/type/bookmark.php
@@ -91,31 +91,26 @@ class bookmark extends \phpbb\notification\type\post
}
// 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.*
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
- AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
- AND n.notification_read = 0
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
+ $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
+ 'item_parent_id' => self::get_item_parent_id($post),
+ 'read' => 0,
+ ));
+
+ foreach ($notified_users as $user => $notification_data)
{
- // Do not create a new notification
- unset($notify_users[$row['user_id']]);
+ unset($notify_users[$user]);
- $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
+ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
if (!empty($update_responders))
{
- $sql = 'UPDATE ' . $this->notifications_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . '
- WHERE notification_id = ' . $row['notification_id'];
- $this->db->sql_query($sql);
+ $this->notification_manager->update_notification($notification, $update_responders, array(
+ 'item_parent_id' => self::get_item_parent_id($post),
+ 'read' => 0,
+ 'user_id' => $user,
+ ));
}
}
- $this->db->sql_freeresult($result);
return $notify_users;
}
diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php
index 7021cdc837..21338bddb7 100644
--- a/phpBB/phpbb/notification/type/disapprove_post.php
+++ b/phpBB/phpbb/notification/type/disapprove_post.php
@@ -125,21 +125,24 @@ class disapprove_post extends \phpbb\notification\type\approve_post
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
- $data = parent::create_insert_array($post);
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php
index 419cc5b2a6..30a23a83fe 100644
--- a/phpBB/phpbb/notification/type/disapprove_topic.php
+++ b/phpBB/phpbb/notification/type/disapprove_topic.php
@@ -125,21 +125,24 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
- $data = parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php
index 2d7925c1b4..9a5746bcce 100644
--- a/phpBB/phpbb/notification/type/group_request.php
+++ b/phpBB/phpbb/notification/type/group_request.php
@@ -156,6 +156,6 @@ class group_request extends \phpbb\notification\type\base
{
$this->set_data('group_name', $group['group_name']);
- return parent::create_insert_array($group, $pre_create_data);
+ parent::create_insert_array($group, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/group_request_approved.php b/phpBB/phpbb/notification/type/group_request_approved.php
index f282cdd158..dc353f3380 100644
--- a/phpBB/phpbb/notification/type/group_request_approved.php
+++ b/phpBB/phpbb/notification/type/group_request_approved.php
@@ -58,7 +58,7 @@ class group_request_approved extends \phpbb\notification\type\base
foreach ($group['user_ids'] as $user_id)
{
- $users[$user_id] = array('');
+ $users[$user_id] = $this->notification_manager->get_default_methods();
}
return $users;
@@ -87,7 +87,7 @@ class group_request_approved extends \phpbb\notification\type\base
{
$this->set_data('group_name', $group['group_name']);
- return parent::create_insert_array($group, $pre_create_data);
+ parent::create_insert_array($group, $pre_create_data);
}
/**
diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php
index 5d4f7fe0c6..6c66c9c057 100644
--- a/phpBB/phpbb/notification/type/pm.php
+++ b/phpBB/phpbb/notification/type/pm.php
@@ -176,13 +176,7 @@ class pm extends \phpbb\notification\type\base
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $pm Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($pm, $pre_create_data = array())
{
@@ -190,6 +184,6 @@ class pm extends \phpbb\notification\type\base
$this->set_data('message_subject', $pm['message_subject']);
- return parent::create_insert_array($pm, $pre_create_data);
+ parent::create_insert_array($pm, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php
index f6b3136a21..e310484187 100644
--- a/phpBB/phpbb/notification/type/post.php
+++ b/phpBB/phpbb/notification/type/post.php
@@ -131,31 +131,26 @@ class post extends \phpbb\notification\type\base
}
// 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.*
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
- AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
- AND n.notification_read = 0
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
+ $notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
+ 'item_parent_id' => self::get_item_parent_id($post),
+ 'read' => 0,
+ ));
+
+ foreach ($notified_users as $user => $notification_data)
{
- // Do not create a new notification
- unset($notify_users[$row['user_id']]);
+ unset($notify_users[$user]);
- $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
+ $notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
if (!empty($update_responders))
{
- $sql = 'UPDATE ' . $this->notifications_table . '
- SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . '
- WHERE notification_id = ' . $row['notification_id'];
- $this->db->sql_query($sql);
+ $this->notification_manager->update_notification($notification, $update_responders, array(
+ 'item_parent_id' => self::get_item_parent_id($post),
+ 'read' => 0,
+ 'user_id' => $user,
+ ));
}
}
- $this->db->sql_freeresult($result);
return $notify_users;
}
@@ -363,13 +358,7 @@ class post extends \phpbb\notification\type\base
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
@@ -394,7 +383,7 @@ class post extends \phpbb\notification\type\base
$this->notification_read = true;
}
- return parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
}
/**
diff --git a/phpBB/phpbb/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php
index e500ad33bc..8b21d77cdd 100644
--- a/phpBB/phpbb/notification/type/post_in_queue.php
+++ b/phpBB/phpbb/notification/type/post_in_queue.php
@@ -131,19 +131,22 @@ class post_in_queue extends \phpbb\notification\type\post
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
- $data = parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php
index 51edfec6f7..57f77bba83 100644
--- a/phpBB/phpbb/notification/type/quote.php
+++ b/phpBB/phpbb/notification/type/quote.php
@@ -109,22 +109,12 @@ class quote extends \phpbb\notification\type\post
*/
public function update_notifications($post)
{
- $old_notifications = array();
- $sql = 'SELECT n.user_id
- FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
- WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
- AND n.item_id = ' . self::get_item_id($post) . '
- AND nt.notification_type_id = n.notification_type_id
- AND nt.notification_type_enabled = 1';
- $result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $old_notifications[] = $row['user_id'];
- }
- $this->db->sql_freeresult($result);
+ $old_notifications = $this->notification_manager->get_notified_users($this->get_type(), array(
+ 'item_id' => self::get_item_id($post),
+ ));
// Find the new users to notify
- $notifications = $this->find_users_for_notification($post);
+ $notifications = array_keys($this->find_users_for_notification($post));
// Find the notifications we must delete
$remove_notifications = array_diff($old_notifications, array_keys($notifications));
@@ -142,11 +132,7 @@ class quote extends \phpbb\notification\type\post
// Remove the necessary notifications
if (!empty($remove_notifications))
{
- $sql = 'DELETE FROM ' . $this->notifications_table . '
- WHERE notification_type_id = ' . (int) $this->notification_type_id . '
- AND item_id = ' . self::get_item_id($post) . '
- AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
- $this->db->sql_query($sql);
+ $this->notification_manager->delete_notifications($this->get_type(), self::get_item_id($post), false, $remove_notifications);
}
// return true to continue with the update code in the notifications service (this will update the rest of the notifications)
diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php
index e7d385f59f..a68685547a 100644
--- a/phpBB/phpbb/notification/type/report_pm.php
+++ b/phpBB/phpbb/notification/type/report_pm.php
@@ -237,13 +237,7 @@ class report_pm extends \phpbb\notification\type\pm
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
@@ -252,6 +246,6 @@ class report_pm extends \phpbb\notification\type\pm
$this->set_data('reason_description', $post['reason_description']);
$this->set_data('report_text', $post['report_text']);
- return parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php
index 1c99db60c3..f793c7df9a 100644
--- a/phpBB/phpbb/notification/type/report_pm_closed.php
+++ b/phpBB/phpbb/notification/type/report_pm_closed.php
@@ -64,7 +64,7 @@ class report_pm_closed extends \phpbb\notification\type\pm
return array();
}
- return array($pm['reporter'] => array(''));
+ return array($pm['reporter'] => $this->notification_manager->get_default_methods());
}
/**
@@ -144,21 +144,24 @@ class report_pm_closed extends \phpbb\notification\type\pm
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $pm PM Data
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($pm, $pre_create_data = array())
{
$this->set_data('closer_id', $pm['closer_id']);
- $data = parent::create_insert_array($pm, $pre_create_data);
+ parent::create_insert_array($pm, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php
index 8289a04cf1..6eefd53832 100644
--- a/phpBB/phpbb/notification/type/report_post.php
+++ b/phpBB/phpbb/notification/type/report_post.php
@@ -210,13 +210,7 @@ class report_post extends \phpbb\notification\type\post_in_queue
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
@@ -225,6 +219,6 @@ class report_post extends \phpbb\notification\type\post_in_queue
$this->set_data('reason_description', $post['reason_description']);
$this->set_data('report_text', $post['report_text']);
- return parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php
index 3f4378628b..6327011f2d 100644
--- a/phpBB/phpbb/notification/type/report_post_closed.php
+++ b/phpBB/phpbb/notification/type/report_post_closed.php
@@ -71,7 +71,7 @@ class report_post_closed extends \phpbb\notification\type\post
return array();
}
- return array($post['reporter'] => array(''));
+ return array($post['reporter'] => $this->notification_manager->get_default_methods());
}
/**
@@ -151,21 +151,24 @@ class report_post_closed extends \phpbb\notification\type\post
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('closer_id', $post['closer_id']);
- $data = parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php
index f0681b9eb8..22eb4bd526 100644
--- a/phpBB/phpbb/notification/type/topic.php
+++ b/phpBB/phpbb/notification/type/topic.php
@@ -263,13 +263,7 @@ class topic extends \phpbb\notification\type\base
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $post Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
@@ -290,6 +284,6 @@ class topic extends \phpbb\notification\type\base
$this->notification_read = true;
}
- return parent::create_insert_array($post, $pre_create_data);
+ parent::create_insert_array($post, $pre_create_data);
}
}
diff --git a/phpBB/phpbb/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php
index cfdf748d38..ad2961525e 100644
--- a/phpBB/phpbb/notification/type/topic_in_queue.php
+++ b/phpBB/phpbb/notification/type/topic_in_queue.php
@@ -123,19 +123,22 @@ class topic_in_queue extends \phpbb\notification\type\topic
}
/**
- * Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
- *
- * @param array $topic Data from submit_post
- * @param array $pre_create_data Data from pre_create_insert_array()
- *
- * @return array Array of data ready to be inserted into the database
+ * {@inheritdoc}
*/
public function create_insert_array($topic, $pre_create_data = array())
{
- $data = parent::create_insert_array($topic, $pre_create_data);
+ parent::create_insert_array($topic, $pre_create_data);
+
+ $this->notification_time = time();
+ }
- $this->notification_time = $data['notification_time'] = time();
+ /**
+ * {@inheritdoc}
+ */
+ public function get_insert_array()
+ {
+ $data = parent::get_insert_array();
+ $data['notification_time'] = $this->notification_time;
return $data;
}
diff --git a/phpBB/phpbb/notification/type/type_interface.php b/phpBB/phpbb/notification/type/type_interface.php
index 8844ce1a38..9b4446ac47 100644
--- a/phpBB/phpbb/notification/type/type_interface.php
+++ b/phpBB/phpbb/notification/type/type_interface.php
@@ -177,14 +177,18 @@ interface type_interface
/**
* Function for preparing the data for insertion in an SQL query
- * (The service handles insertion)
*
* @param array $type_data The type specific data
* @param array $pre_create_data Data from pre_create_insert_array()
+ */
+ public function create_insert_array($type_data, $pre_create_data);
+
+ /**
+ * Function for getting the data for insertion in an SQL query
*
* @return array Array of data ready to be inserted into the database
*/
- public function create_insert_array($type_data, $pre_create_data);
+ public function get_insert_array();
/**
* Function for preparing the data for update in an SQL query