mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge remote-tracking branch 'EXreaction/ticket/11413' into develop
* EXreaction/ticket/11413: (23 commits) [ticket/11413] Revert some cache service related changes from earlier [ticket/11413] Use phpbb_user in test [ticket/11413] $user should have been $this->user [ticket/11413] Fix unit tests [ticket/11413] Translate the error [ticket/11413] Rename file to something more helpful [ticket/11413] Remove remaining irrelevant code to this PR [ticket/11413] Remove mock sql_insert_buffer.php (not relevant to PR) [ticket/11413] Remove conversion of user_notifications [ticket/11413] Correct copyright year [ticket/11413] Remove changes for ticket 11420 from this branch [ticket/11413] Include mock class [ticket/11413] Don't use the database for the convert test [ticket/11413] Test get_notification_type_id and _ids functions [ticket/11413] Use sql_insert_buffer [ticket/11413] Create test for notification conversion [ticket/11413] Fix test fixtures and tests [ticket/11413] Fix some more tests [ticket/11413] Fix notification tests [ticket/11413] Prevent recursive function calls ...
This commit is contained in:
commit
fedd9d18d2
25 changed files with 516 additions and 210 deletions
|
@ -217,6 +217,7 @@ services:
|
||||||
- @service_container
|
- @service_container
|
||||||
- @user_loader
|
- @user_loader
|
||||||
- @dbal.conn
|
- @dbal.conn
|
||||||
|
- @cache
|
||||||
- @user
|
- @user
|
||||||
- %core.root_path%
|
- %core.root_path%
|
||||||
- %core.php_ext%
|
- %core.php_ext%
|
||||||
|
|
|
@ -1317,16 +1317,20 @@ function get_schema_struct()
|
||||||
|
|
||||||
$schema_data['phpbb_notification_types'] = array(
|
$schema_data['phpbb_notification_types'] = array(
|
||||||
'COLUMNS' => array(
|
'COLUMNS' => array(
|
||||||
'notification_type' => array('VCHAR:255', ''),
|
'notification_type_id' => array('USINT', NULL, 'auto_increment'),
|
||||||
|
'notification_type_name' => array('VCHAR:255', ''),
|
||||||
'notification_type_enabled' => array('BOOL', 1),
|
'notification_type_enabled' => array('BOOL', 1),
|
||||||
),
|
),
|
||||||
'PRIMARY_KEY' => array('notification_type', 'notification_type_enabled'),
|
'PRIMARY_KEY' => array('notification_type_id'),
|
||||||
|
'KEYS' => array(
|
||||||
|
'type' => array('UNIQUE', array('notification_type_name')),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema_data['phpbb_notifications'] = array(
|
$schema_data['phpbb_notifications'] = array(
|
||||||
'COLUMNS' => array(
|
'COLUMNS' => array(
|
||||||
'notification_id' => array('UINT', NULL, 'auto_increment'),
|
'notification_id' => array('UINT:10', NULL, 'auto_increment'),
|
||||||
'item_type' => array('VCHAR:255', ''),
|
'notification_type_id' => array('USINT', 0),
|
||||||
'item_id' => array('UINT', 0),
|
'item_id' => array('UINT', 0),
|
||||||
'item_parent_id' => array('UINT', 0),
|
'item_parent_id' => array('UINT', 0),
|
||||||
'user_id' => array('UINT', 0),
|
'user_id' => array('UINT', 0),
|
||||||
|
@ -1336,7 +1340,7 @@ function get_schema_struct()
|
||||||
),
|
),
|
||||||
'PRIMARY_KEY' => 'notification_id',
|
'PRIMARY_KEY' => 'notification_id',
|
||||||
'KEYS' => array(
|
'KEYS' => array(
|
||||||
'item_ident' => array('INDEX', array('item_type', 'item_id')),
|
'item_ident' => array('INDEX', array('notification_type_id', 'item_id')),
|
||||||
'user' => array('INDEX', array('user_id', 'notification_read')),
|
'user' => array('INDEX', array('user_id', 'notification_read')),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package migration
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_db_migration_data_310_notifications_schema_fix extends phpbb_db_migration
|
||||||
|
{
|
||||||
|
static public function depends_on()
|
||||||
|
{
|
||||||
|
return array('phpbb_db_migration_data_310_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'drop_tables' => array(
|
||||||
|
$this->table_prefix . 'notification_types',
|
||||||
|
$this->table_prefix . 'notifications',
|
||||||
|
),
|
||||||
|
'add_tables' => array(
|
||||||
|
$this->table_prefix . 'notification_types' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'notification_type_id' => array('USINT', NULL, 'auto_increment'),
|
||||||
|
'notification_type_name' => array('VCHAR:255', ''),
|
||||||
|
'notification_type_enabled' => array('BOOL', 1),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => array('notification_type_id'),
|
||||||
|
'KEYS' => array(
|
||||||
|
'type' => array('UNIQUE', array('notification_type_name')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
$this->table_prefix . 'notifications' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'notification_id' => array('UINT:10', NULL, 'auto_increment'),
|
||||||
|
'notification_type_id' => array('USINT', 0),
|
||||||
|
'item_id' => array('UINT', 0),
|
||||||
|
'item_parent_id' => array('UINT', 0),
|
||||||
|
'user_id' => array('UINT', 0),
|
||||||
|
'notification_read' => array('BOOL', 0),
|
||||||
|
'notification_time' => array('TIMESTAMP', 1),
|
||||||
|
'notification_data' => array('TEXT_UNI', ''),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => 'notification_id',
|
||||||
|
'KEYS' => array(
|
||||||
|
'item_ident' => array('INDEX', array('notification_type_id', 'item_id')),
|
||||||
|
'user' => array('INDEX', array('user_id', 'notification_read')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revert_schema()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'drop_tables' => array(
|
||||||
|
$this->table_prefix . 'notification_types',
|
||||||
|
$this->table_prefix . 'notifications',
|
||||||
|
),
|
||||||
|
'add_tables' => array(
|
||||||
|
$this->table_prefix . 'notification_types' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'notification_type' => array('VCHAR:255', ''),
|
||||||
|
'notification_type_enabled' => array('BOOL', 1),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => array('notification_type', 'notification_type_enabled'),
|
||||||
|
),
|
||||||
|
$this->table_prefix . 'notifications' => array(
|
||||||
|
'COLUMNS' => array(
|
||||||
|
'notification_id' => array('UINT', NULL, 'auto_increment'),
|
||||||
|
'item_type' => array('VCHAR:255', ''),
|
||||||
|
'item_id' => array('UINT', 0),
|
||||||
|
'item_parent_id' => array('UINT', 0),
|
||||||
|
'user_id' => array('UINT', 0),
|
||||||
|
'notification_read' => array('BOOL', 0),
|
||||||
|
'notification_time' => array('TIMESTAMP', 1),
|
||||||
|
'notification_data' => array('TEXT_UNI', ''),
|
||||||
|
),
|
||||||
|
'PRIMARY_KEY' => 'notification_id',
|
||||||
|
'KEYS' => array(
|
||||||
|
'item_ident' => array('INDEX', array('item_type', 'item_id')),
|
||||||
|
'user' => array('INDEX', array('user_id', 'notification_read')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
29
phpBB/includes/notification/exception.php
Normal file
29
phpBB/includes/notification/exception.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package notifications
|
||||||
|
* @copyright (c) 2013 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
if (!defined('IN_PHPBB'))
|
||||||
|
{
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifications exception
|
||||||
|
*
|
||||||
|
* @package notifications
|
||||||
|
*/
|
||||||
|
class phpbb_notification_exception extends \Exception
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->getMessage();
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,9 @@ class phpbb_notification_manager
|
||||||
/** @var phpbb_db_driver */
|
/** @var phpbb_db_driver */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
/** @var phpbb_cache_service */
|
||||||
|
protected $cache;
|
||||||
|
|
||||||
/** @var phpbb_user */
|
/** @var phpbb_user */
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
|
@ -70,7 +73,7 @@ class phpbb_notification_manager
|
||||||
* @param string $user_notifications_table
|
* @param string $user_notifications_table
|
||||||
* @return phpbb_notification_manager
|
* @return phpbb_notification_manager
|
||||||
*/
|
*/
|
||||||
public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
|
public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_service $cache, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table)
|
||||||
{
|
{
|
||||||
$this->notification_types = $notification_types;
|
$this->notification_types = $notification_types;
|
||||||
$this->notification_methods = $notification_methods;
|
$this->notification_methods = $notification_methods;
|
||||||
|
@ -78,6 +81,7 @@ class phpbb_notification_manager
|
||||||
|
|
||||||
$this->user_loader = $user_loader;
|
$this->user_loader = $user_loader;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
$this->cache = $cache;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
|
@ -145,7 +149,7 @@ class phpbb_notification_manager
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
||||||
AND n.notification_read = 0
|
AND n.notification_read = 0
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
$unread_count = (int) $this->db->sql_fetchfield('unread_count', $result);
|
$unread_count = (int) $this->db->sql_fetchfield('unread_count', $result);
|
||||||
|
@ -158,7 +162,7 @@ class phpbb_notification_manager
|
||||||
$sql = 'SELECT COUNT(n.notification_id) AS total_count
|
$sql = 'SELECT COUNT(n.notification_id) AS total_count
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
$total_count = (int) $this->db->sql_fetchfield('total_count', $result);
|
$total_count = (int) $this->db->sql_fetchfield('total_count', $result);
|
||||||
|
@ -170,11 +174,11 @@ class phpbb_notification_manager
|
||||||
$rowset = array();
|
$rowset = array();
|
||||||
|
|
||||||
// Get the main notifications
|
// Get the main notifications
|
||||||
$sql = 'SELECT n.*
|
$sql = 'SELECT n.*, nt.notification_type_name
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.user_id = ' . (int) $options['user_id'] .
|
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']) : '') . '
|
(($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 = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1
|
AND nt.notification_type_enabled = 1
|
||||||
ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
|
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']);
|
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
|
||||||
|
@ -188,12 +192,12 @@ class phpbb_notification_manager
|
||||||
// Get all unread notifications
|
// Get all unread notifications
|
||||||
if ($unread_count && $options['all_unread'] && !empty($rowset))
|
if ($unread_count && $options['all_unread'] && !empty($rowset))
|
||||||
{
|
{
|
||||||
$sql = 'SELECT n.*
|
$sql = 'SELECT n.*, nt.notification_type_name
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
WHERE n.user_id = ' . (int) $options['user_id'] . '
|
||||||
AND n.notification_read = 0
|
AND n.notification_read = 0
|
||||||
AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
|
AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1
|
AND nt.notification_type_enabled = 1
|
||||||
ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
|
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']);
|
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
|
||||||
|
@ -207,17 +211,17 @@ class phpbb_notification_manager
|
||||||
|
|
||||||
foreach ($rowset as $row)
|
foreach ($rowset as $row)
|
||||||
{
|
{
|
||||||
$notification = $this->get_item_type_class($row['item_type'], $row);
|
$notification = $this->get_item_type_class($row['notification_type_name'], $row);
|
||||||
|
|
||||||
// Array of user_ids to query all at once
|
// Array of user_ids to query all at once
|
||||||
$user_ids = array_merge($user_ids, $notification->users_to_query());
|
$user_ids = array_merge($user_ids, $notification->users_to_query());
|
||||||
|
|
||||||
// Some notification types also require querying additional tables themselves
|
// Some notification types also require querying additional tables themselves
|
||||||
if (!isset($load_special[$row['item_type']]))
|
if (!isset($load_special[$row['notification_type_name']]))
|
||||||
{
|
{
|
||||||
$load_special[$row['item_type']] = array();
|
$load_special[$row['notification_type_name']] = array();
|
||||||
}
|
}
|
||||||
$load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special());
|
$load_special[$row['notification_type_name']] = array_merge($load_special[$row['notification_type_name']], $notification->get_load_special());
|
||||||
|
|
||||||
$notifications[$row['notification_id']] = $notification;
|
$notifications[$row['notification_id']] = $notification;
|
||||||
}
|
}
|
||||||
|
@ -243,19 +247,21 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Mark notifications read
|
* Mark notifications read
|
||||||
*
|
*
|
||||||
* @param bool|string|array $item_type 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|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 $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|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|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
|
||||||
*/
|
*/
|
||||||
public function mark_notifications_read($item_type, $item_id, $user_id, $time = false)
|
public function mark_notifications_read($notification_type_name, $item_id, $user_id, $time = false)
|
||||||
{
|
{
|
||||||
$time = ($time !== false) ? $time : time();
|
$time = ($time !== false) ? $time : time();
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->notifications_table . "
|
$sql = 'UPDATE ' . $this->notifications_table . "
|
||||||
SET notification_read = 1
|
SET notification_read = 1
|
||||||
WHERE notification_time <= " . (int) $time .
|
WHERE notification_time <= " . (int) $time .
|
||||||
(($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') .
|
(($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) : '') .
|
(($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) : '');
|
(($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);
|
$this->db->sql_query($sql);
|
||||||
|
@ -264,29 +270,21 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Mark notifications read from a parent identifier
|
* Mark notifications read from a parent identifier
|
||||||
*
|
*
|
||||||
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
* @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 $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|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|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
|
||||||
*/
|
*/
|
||||||
public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false)
|
public function mark_notifications_read_by_parent($notification_type_name, $item_parent_id, $user_id, $time = false)
|
||||||
{
|
{
|
||||||
if (is_array($item_type))
|
|
||||||
{
|
|
||||||
foreach ($item_type as $type)
|
|
||||||
{
|
|
||||||
$this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$time = ($time !== false) ? $time : time();
|
$time = ($time !== false) ? $time : time();
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->notifications_table . "
|
$sql = 'UPDATE ' . $this->notifications_table . "
|
||||||
SET notification_read = 1
|
SET notification_read = 1
|
||||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
WHERE notification_time <= " . (int) $time .
|
||||||
AND 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) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
|
(($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : '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) : '');
|
(($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);
|
$this->db->sql_query($sql);
|
||||||
|
@ -312,7 +310,7 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Add a notification
|
* Add a notification
|
||||||
*
|
*
|
||||||
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
||||||
* Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive
|
* Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive
|
||||||
* a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array
|
* a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array
|
||||||
* @param array $data Data specific for this type that will be inserted
|
* @param array $data Data specific for this type that will be inserted
|
||||||
|
@ -320,18 +318,18 @@ class phpbb_notification_manager
|
||||||
* ignore_users array of data to specify which users should not receive certain types of notifications
|
* ignore_users array of data to specify which users should not receive certain types of notifications
|
||||||
* @return array Information about what users were notified and how they were notified
|
* @return array Information about what users were notified and how they were notified
|
||||||
*/
|
*/
|
||||||
public function add_notifications($item_type, $data, array $options = array())
|
public function add_notifications($notification_type_name, $data, array $options = array())
|
||||||
{
|
{
|
||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
'ignore_users' => array(),
|
'ignore_users' => array(),
|
||||||
), $options);
|
), $options);
|
||||||
|
|
||||||
if (is_array($item_type))
|
if (is_array($notification_type_name))
|
||||||
{
|
{
|
||||||
$notified_users = array();
|
$notified_users = array();
|
||||||
$temp_options = $options;
|
$temp_options = $options;
|
||||||
|
|
||||||
foreach ($item_type as $type)
|
foreach ($notification_type_name as $type)
|
||||||
{
|
{
|
||||||
$temp_options['ignore_users'] = $options['ignore_users'] + $notified_users;
|
$temp_options['ignore_users'] = $options['ignore_users'] + $notified_users;
|
||||||
$notified_users += $this->add_notifications($type, $data, $temp_options);
|
$notified_users += $this->add_notifications($type, $data, $temp_options);
|
||||||
|
@ -340,12 +338,12 @@ class phpbb_notification_manager
|
||||||
return $notified_users;
|
return $notified_users;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item_id = $this->get_item_type_class($item_type)->get_item_id($data);
|
$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
|
||||||
|
|
||||||
// find out which users want to receive this type of notification
|
// find out which users want to receive this type of notification
|
||||||
$notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options);
|
$notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options);
|
||||||
|
|
||||||
$this->add_notifications_for_users($item_type, $data, $notify_users);
|
$this->add_notifications_for_users($notification_type_name, $data, $notify_users);
|
||||||
|
|
||||||
return $notify_users;
|
return $notify_users;
|
||||||
}
|
}
|
||||||
|
@ -353,15 +351,15 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Add a notification for specific users
|
* Add a notification for specific users
|
||||||
*
|
*
|
||||||
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
* @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 inserted
|
* @param array $data Data specific for this type that will be inserted
|
||||||
* @param array $notify_users User list to notify
|
* @param array $notify_users User list to notify
|
||||||
*/
|
*/
|
||||||
public function add_notifications_for_users($item_type, $data, $notify_users)
|
public function add_notifications_for_users($notification_type_name, $data, $notify_users)
|
||||||
{
|
{
|
||||||
if (is_array($item_type))
|
if (is_array($notification_type_name))
|
||||||
{
|
{
|
||||||
foreach ($item_type as $type)
|
foreach ($notification_type_name as $type)
|
||||||
{
|
{
|
||||||
$this->add_notifications_for_users($type, $data, $notify_users);
|
$this->add_notifications_for_users($type, $data, $notify_users);
|
||||||
}
|
}
|
||||||
|
@ -369,24 +367,9 @@ class phpbb_notification_manager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'SELECT notification_type
|
$notification_type_id = $this->get_notification_type_id($notification_type_name);
|
||||||
FROM ' . $this->notification_types_table . "
|
|
||||||
WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'";
|
|
||||||
$result = $this->db->sql_query($sql);
|
|
||||||
|
|
||||||
if ($this->db->sql_fetchrow($result) === false)
|
$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
|
||||||
{
|
|
||||||
// Does not exist in the database, must add the item type
|
|
||||||
$sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array(
|
|
||||||
'notification_type' => $item_type,
|
|
||||||
'notification_type_enabled' => 1,
|
|
||||||
));
|
|
||||||
$this->db->sql_query($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->sql_freeresult($result);
|
|
||||||
|
|
||||||
$item_id = $this->get_item_type_class($item_type)->get_item_id($data);
|
|
||||||
|
|
||||||
$user_ids = array();
|
$user_ids = array();
|
||||||
$notification_objects = $notification_methods = array();
|
$notification_objects = $notification_methods = array();
|
||||||
|
@ -397,10 +380,10 @@ class phpbb_notification_manager
|
||||||
// Make sure not to send new notifications to users who've already been notified about this item
|
// 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
|
// This may happen when an item was added, but now new users are able to see the item
|
||||||
$sql = 'SELECT n.user_id
|
$sql = 'SELECT n.user_id
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.item_type = '" . $this->db->sql_escape($item_type) . "'
|
WHERE n.notification_type_id = ' . (int) $notification_type_id . '
|
||||||
AND n.item_id = " . (int) $item_id . '
|
AND n.item_id = ' . (int) $item_id . '
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
@ -415,7 +398,7 @@ class phpbb_notification_manager
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
|
// Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
|
||||||
$notification = $this->get_item_type_class($item_type);
|
$notification = $this->get_item_type_class($notification_type_name);
|
||||||
$pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
|
$pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
|
||||||
unset($notification);
|
unset($notification);
|
||||||
|
|
||||||
|
@ -424,7 +407,7 @@ class phpbb_notification_manager
|
||||||
// Go through each user so we can insert a row in the DB and then notify them by their desired means
|
// 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)
|
foreach ($notify_users as $user => $methods)
|
||||||
{
|
{
|
||||||
$notification = $this->get_item_type_class($item_type);
|
$notification = $this->get_item_type_class($notification_type_name);
|
||||||
|
|
||||||
$notification->user_id = (int) $user;
|
$notification->user_id = (int) $user;
|
||||||
|
|
||||||
|
@ -464,14 +447,14 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Update a notification
|
* Update a notification
|
||||||
*
|
*
|
||||||
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
|
* @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 $data Data specific for this type that will be updated
|
||||||
*/
|
*/
|
||||||
public function update_notifications($item_type, $data)
|
public function update_notifications($notification_type_name, $data)
|
||||||
{
|
{
|
||||||
if (is_array($item_type))
|
if (is_array($notification_type_name))
|
||||||
{
|
{
|
||||||
foreach ($item_type as $type)
|
foreach ($notification_type_name as $type)
|
||||||
{
|
{
|
||||||
$this->update_notifications($type, $data);
|
$this->update_notifications($type, $data);
|
||||||
}
|
}
|
||||||
|
@ -479,7 +462,7 @@ class phpbb_notification_manager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification = $this->get_item_type_class($item_type);
|
$notification = $this->get_item_type_class($notification_type_name);
|
||||||
|
|
||||||
// Allow the notifications class to over-ride the update_notifications functionality
|
// Allow the notifications class to over-ride the update_notifications functionality
|
||||||
if (method_exists($notification, 'update_notifications'))
|
if (method_exists($notification, 'update_notifications'))
|
||||||
|
@ -491,28 +474,29 @@ class phpbb_notification_manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notification_type_id = $this->get_notification_type_id($notification_type_name);
|
||||||
$item_id = $notification->get_item_id($data);
|
$item_id = $notification->get_item_id($data);
|
||||||
$update_array = $notification->create_update_array($data);
|
$update_array = $notification->create_update_array($data);
|
||||||
|
|
||||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||||
SET ' . $this->db->sql_build_array('UPDATE', $update_array) . "
|
SET ' . $this->db->sql_build_array('UPDATE', $update_array) . '
|
||||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
WHERE notification_type_id = ' . (int) $notification_type_id . '
|
||||||
AND item_id = " . (int) $item_id;
|
AND item_id = ' . (int) $item_id;
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a notification
|
* Delete a notification
|
||||||
*
|
*
|
||||||
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)
|
* @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 int|array $item_id Identifier within the type (or array of ids)
|
||||||
* @param array $data Data specific for this type that will be updated
|
* @param array $data Data specific for this type that will be updated
|
||||||
*/
|
*/
|
||||||
public function delete_notifications($item_type, $item_id)
|
public function delete_notifications($notification_type_name, $item_id)
|
||||||
{
|
{
|
||||||
if (is_array($item_type))
|
if (is_array($notification_type_name))
|
||||||
{
|
{
|
||||||
foreach ($item_type as $type)
|
foreach ($notification_type_name as $type)
|
||||||
{
|
{
|
||||||
$this->delete_notifications($type, $item_id);
|
$this->delete_notifications($type, $item_id);
|
||||||
}
|
}
|
||||||
|
@ -520,9 +504,11 @@ class phpbb_notification_manager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . $this->notifications_table . "
|
$notification_type_id = $this->get_notification_type_id($notification_type_name);
|
||||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
|
||||||
AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id);
|
$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);
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,7 +641,8 @@ class phpbb_notification_manager
|
||||||
{
|
{
|
||||||
if ($method !== '')
|
if ($method !== '')
|
||||||
{
|
{
|
||||||
$this->add_subscription($item_type, $item_type, '', $user_id);
|
// Make sure to subscribe them to the base subscription
|
||||||
|
$this->add_subscription($item_type, $item_id, '', $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
|
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
|
||||||
|
@ -755,13 +742,13 @@ class phpbb_notification_manager
|
||||||
* is disabled so that all those notifications are hidden and do not
|
* is disabled so that all those notifications are hidden and do not
|
||||||
* cause errors
|
* cause errors
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier of the subscription
|
* @param string $notification_type_name Type identifier of the subscription
|
||||||
*/
|
*/
|
||||||
public function disable_notifications($item_type)
|
public function disable_notifications($notification_type_name)
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . $this->notification_types_table . "
|
$sql = 'UPDATE ' . $this->notification_types_table . "
|
||||||
SET notification_type_enabled = 0
|
SET notification_type_enabled = 0
|
||||||
WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'";
|
WHERE notification_type_name = '" . $this->db->sql_escape($notification_type_name) . "'";
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,17 +758,21 @@ class phpbb_notification_manager
|
||||||
* This should be called when an extension which has notification types
|
* This should be called when an extension which has notification types
|
||||||
* is purged so that all those notifications are removed
|
* is purged so that all those notifications are removed
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier of the subscription
|
* @param string $notification_type_name Type identifier of the subscription
|
||||||
*/
|
*/
|
||||||
public function purge_notifications($item_type)
|
public function purge_notifications($notification_type_name)
|
||||||
{
|
{
|
||||||
$sql = 'DELETE FROM ' . $this->notifications_table . "
|
$notification_type_id = $this->get_notification_type_id($notification_type_name);
|
||||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'";
|
|
||||||
|
$sql = 'DELETE FROM ' . $this->notifications_table . '
|
||||||
|
WHERE notification_type_id = ' . (int) $notification_type_id;
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
$sql = 'DELETE FROM ' . $this->notification_types_table . "
|
$sql = 'DELETE FROM ' . $this->notification_types_table . '
|
||||||
WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'";
|
WHERE notification_type_id = ' . (int) $notification_type_id;
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$this->cache->destroy('notification_type_ids');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -791,13 +782,13 @@ class phpbb_notification_manager
|
||||||
* that was disabled is re-enabled so that all those notifications that
|
* that was disabled is re-enabled so that all those notifications that
|
||||||
* were hidden are shown again
|
* were hidden are shown again
|
||||||
*
|
*
|
||||||
* @param string $item_type Type identifier of the subscription
|
* @param string $notification_type_name Type identifier of the subscription
|
||||||
*/
|
*/
|
||||||
public function enable_notifications($item_type)
|
public function enable_notifications($notification_type_name)
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE ' . $this->notification_types_table . "
|
$sql = 'UPDATE ' . $this->notification_types_table . "
|
||||||
SET notification_type_enabled = 1
|
SET notification_type_enabled = 1
|
||||||
WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'";
|
WHERE notification_type_name = '" . $this->db->sql_escape($notification_type_name) . "'";
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,11 +807,11 @@ class phpbb_notification_manager
|
||||||
/**
|
/**
|
||||||
* Helper to get the notifications item type class and set it up
|
* Helper to get the notifications item type class and set it up
|
||||||
*/
|
*/
|
||||||
public function get_item_type_class($item_type, $data = array())
|
public function get_item_type_class($notification_type_name, $data = array())
|
||||||
{
|
{
|
||||||
$item_type = (strpos($item_type, 'notification.type.') === 0) ? $item_type : 'notification.type.' . $item_type;
|
$notification_type_name = (strpos($notification_type_name, 'notification.type.') === 0) ? $notification_type_name : 'notification.type.' . $notification_type_name;
|
||||||
|
|
||||||
$item = $this->load_object($item_type);
|
$item = $this->load_object($notification_type_name);
|
||||||
|
|
||||||
$item->set_initial_data($data);
|
$item->set_initial_data($data);
|
||||||
|
|
||||||
|
@ -851,4 +842,69 @@ class phpbb_notification_manager
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification type id from the name
|
||||||
|
*
|
||||||
|
* @param string $notification_type_name The name
|
||||||
|
* @return int the notification_type_id
|
||||||
|
*/
|
||||||
|
public function get_notification_type_id($notification_type_name)
|
||||||
|
{
|
||||||
|
$notification_type_ids = $this->cache->get('notification_type_ids');
|
||||||
|
|
||||||
|
if ($notification_type_ids === false)
|
||||||
|
{
|
||||||
|
$notification_type_ids = array();
|
||||||
|
|
||||||
|
$sql = 'SELECT notification_type_id, notification_type_name
|
||||||
|
FROM ' . $this->notification_types_table;
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$this->cache->put('notification_type_ids', $notification_type_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($notification_type_ids[$notification_type_name]))
|
||||||
|
{
|
||||||
|
if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name]))
|
||||||
|
{
|
||||||
|
throw new phpbb_notification_exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||||
|
'notification_type_name' => $notification_type_name,
|
||||||
|
'notification_type_enabled' => 1,
|
||||||
|
));
|
||||||
|
$this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid();
|
||||||
|
|
||||||
|
$this->cache->put('notification_type_ids', $notification_type_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $notification_type_ids[$notification_type_name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get notification type ids (as an array)
|
||||||
|
*
|
||||||
|
* @param array $notification_type_names Array of strings
|
||||||
|
* @return array Array of integers
|
||||||
|
*/
|
||||||
|
public function get_notification_type_ids(array $notification_type_names)
|
||||||
|
{
|
||||||
|
$notification_type_ids = array();
|
||||||
|
|
||||||
|
foreach ($notification_type_names as $name)
|
||||||
|
{
|
||||||
|
$notification_type_ids[$name] = $this->get_notification_type_id($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $notification_type_ids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
|
||||||
/** @var phpbb_db_driver */
|
/** @var phpbb_db_driver */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/** @var phpbb_cache_service */
|
/** @var phpbb_cache_driver_interface */
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
/** @var phpbb_template */
|
/** @var phpbb_template */
|
||||||
|
|
|
@ -30,7 +30,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
||||||
/** @var phpbb_db_driver */
|
/** @var phpbb_db_driver */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/** @var phpbb_cache_service */
|
/** @var phpbb_cache_driver_interface */
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
/** @var phpbb_template */
|
/** @var phpbb_template */
|
||||||
|
@ -68,9 +68,17 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
||||||
*/
|
*/
|
||||||
public static $notification_option = false;
|
public static $notification_option = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The notification_type_id, set upon creation of the class
|
||||||
|
* This is the notification_type_id from the notification_types table
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $notification_type_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indentification data
|
* Indentification data
|
||||||
* item_type - Type of the item (translates to the notification type)
|
* notification_type_id - ID of the item type (auto generated, from notification types table)
|
||||||
* item_id - ID of the item (e.g. post_id, msg_id)
|
* item_id - ID of the item (e.g. post_id, msg_id)
|
||||||
* item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc)
|
* item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc)
|
||||||
* user_id
|
* user_id
|
||||||
|
@ -124,6 +132,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
||||||
public function set_notification_manager(phpbb_notification_manager $notification_manager)
|
public function set_notification_manager(phpbb_notification_manager $notification_manager)
|
||||||
{
|
{
|
||||||
$this->notification_manager = $notification_manager;
|
$this->notification_manager = $notification_manager;
|
||||||
|
|
||||||
|
$this->notification_type_id = $this->notification_manager->get_notification_type_id($this->get_type());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +221,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
||||||
// Defaults
|
// Defaults
|
||||||
$this->data = array_merge(array(
|
$this->data = array_merge(array(
|
||||||
'item_id' => static::get_item_id($type_data),
|
'item_id' => static::get_item_id($type_data),
|
||||||
'item_type' => $this->get_type(),
|
'notification_type_id' => $this->notification_type_id,
|
||||||
'item_parent_id' => static::get_item_parent_id($type_data),
|
'item_parent_id' => static::get_item_parent_id($type_data),
|
||||||
|
|
||||||
'notification_time' => time(),
|
'notification_time' => time(),
|
||||||
|
@ -460,7 +470,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
|
||||||
$this->notification_read = (bool) !$unread;
|
$this->notification_read = (bool) !$unread;
|
||||||
|
|
||||||
$where = array(
|
$where = array(
|
||||||
"item_type = '" . $this->db->sql_escape($this->item_type) . "'",
|
'notification_type_id = ' . (int) $this->notification_type_id,
|
||||||
'item_id = ' . (int) $this->item_id,
|
'item_id = ' . (int) $this->item_id,
|
||||||
'user_id = ' . (int) $this->user_id,
|
'user_id = ' . (int) $this->user_id,
|
||||||
);
|
);
|
||||||
|
|
|
@ -103,11 +103,11 @@ class phpbb_notification_type_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
|
// 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();
|
$update_notifications = array();
|
||||||
$sql = 'SELECT n.*
|
$sql = 'SELECT n.*
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.item_type = '" . $this->get_type() . "'
|
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
|
||||||
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
|
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
|
||||||
AND n.notification_read = 0
|
AND n.notification_read = 0
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
|
|
@ -138,11 +138,11 @@ class phpbb_notification_type_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
|
// 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();
|
$update_notifications = array();
|
||||||
$sql = 'SELECT n.*
|
$sql = 'SELECT n.*
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.item_type = '" . $this->get_type() . "'
|
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
|
||||||
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
|
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
|
||||||
AND n.notification_read = 0
|
AND n.notification_read = 0
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
|
|
@ -122,11 +122,11 @@ class phpbb_notification_type_quote 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
|
// 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();
|
$update_notifications = array();
|
||||||
$sql = 'SELECT n.*
|
$sql = 'SELECT n.*
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.item_type = '" . $this->get_type() . "'
|
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
|
||||||
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
|
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
|
||||||
AND n.notification_read = 0
|
AND n.notification_read = 0
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
@ -154,10 +154,10 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
|
||||||
{
|
{
|
||||||
$old_notifications = array();
|
$old_notifications = array();
|
||||||
$sql = 'SELECT n.user_id
|
$sql = 'SELECT n.user_id
|
||||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
|
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||||
WHERE n.item_type = '" . $this->get_type() . "'
|
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
|
||||||
AND n.item_id = " . self::get_item_id($post) . '
|
AND n.item_id = ' . self::get_item_id($post) . '
|
||||||
AND nt.notification_type = n.item_type
|
AND nt.notification_type_id = n.notification_type_id
|
||||||
AND nt.notification_type_enabled = 1';
|
AND nt.notification_type_enabled = 1';
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
while ($row = $this->db->sql_fetchrow($result))
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
@ -185,9 +185,9 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
|
||||||
// Remove the necessary notifications
|
// Remove the necessary notifications
|
||||||
if (!empty($remove_notifications))
|
if (!empty($remove_notifications))
|
||||||
{
|
{
|
||||||
$sql = 'DELETE FROM ' . $this->notifications_table . "
|
$sql = 'DELETE FROM ' . $this->notifications_table . '
|
||||||
WHERE item_type = '" . $this->get_type() . "'
|
WHERE notification_type_id = ' . (int) $this->notification_type_id . '
|
||||||
AND item_id = " . self::get_item_id($post) . '
|
AND item_id = ' . self::get_item_id($post) . '
|
||||||
AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
|
AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
|
||||||
$this->db->sql_query($sql);
|
$this->db->sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
|
@ -642,17 +642,30 @@ END;;
|
||||||
|
|
||||||
# Table: 'phpbb_notification_types'
|
# Table: 'phpbb_notification_types'
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
notification_type_id INTEGER NOT NULL,
|
||||||
|
notification_type_name VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
||||||
notification_type_enabled INTEGER DEFAULT 1 NOT NULL
|
notification_type_enabled INTEGER DEFAULT 1 NOT NULL
|
||||||
);;
|
);;
|
||||||
|
|
||||||
ALTER TABLE phpbb_notification_types ADD PRIMARY KEY (notification_type, notification_type_enabled);;
|
ALTER TABLE phpbb_notification_types ADD PRIMARY KEY (notification_type_id);;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types(notification_type_name);;
|
||||||
|
|
||||||
|
CREATE GENERATOR phpbb_notification_types_gen;;
|
||||||
|
SET GENERATOR phpbb_notification_types_gen TO 0;;
|
||||||
|
|
||||||
|
CREATE TRIGGER t_phpbb_notification_types FOR phpbb_notification_types
|
||||||
|
BEFORE INSERT
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
NEW.notification_type_id = GEN_ID(phpbb_notification_types_gen, 1);
|
||||||
|
END;;
|
||||||
|
|
||||||
|
|
||||||
# Table: 'phpbb_notifications'
|
# Table: 'phpbb_notifications'
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id INTEGER NOT NULL,
|
notification_id INTEGER NOT NULL,
|
||||||
item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
|
notification_type_id INTEGER DEFAULT 0 NOT NULL,
|
||||||
item_id INTEGER DEFAULT 0 NOT NULL,
|
item_id INTEGER DEFAULT 0 NOT NULL,
|
||||||
item_parent_id INTEGER DEFAULT 0 NOT NULL,
|
item_parent_id INTEGER DEFAULT 0 NOT NULL,
|
||||||
user_id INTEGER DEFAULT 0 NOT NULL,
|
user_id INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
@ -663,7 +676,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
|
|
||||||
ALTER TABLE phpbb_notifications ADD PRIMARY KEY (notification_id);;
|
ALTER TABLE phpbb_notifications ADD PRIMARY KEY (notification_id);;
|
||||||
|
|
||||||
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications(item_type, item_id);;
|
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications(notification_type_id, item_id);;
|
||||||
CREATE INDEX phpbb_notifications_user ON phpbb_notifications(user_id, notification_read);;
|
CREATE INDEX phpbb_notifications_user ON phpbb_notifications(user_id, notification_read);;
|
||||||
|
|
||||||
CREATE GENERATOR phpbb_notifications_gen;;
|
CREATE GENERATOR phpbb_notifications_gen;;
|
||||||
|
|
|
@ -793,7 +793,8 @@ GO
|
||||||
Table: 'phpbb_notification_types'
|
Table: 'phpbb_notification_types'
|
||||||
*/
|
*/
|
||||||
CREATE TABLE [phpbb_notification_types] (
|
CREATE TABLE [phpbb_notification_types] (
|
||||||
[notification_type] [varchar] (255) DEFAULT ('') NOT NULL ,
|
[notification_type_id] [int] IDENTITY (1, 1) NOT NULL ,
|
||||||
|
[notification_type_name] [varchar] (255) DEFAULT ('') NOT NULL ,
|
||||||
[notification_type_enabled] [int] DEFAULT (1) NOT NULL
|
[notification_type_enabled] [int] DEFAULT (1) NOT NULL
|
||||||
) ON [PRIMARY]
|
) ON [PRIMARY]
|
||||||
GO
|
GO
|
||||||
|
@ -801,18 +802,20 @@ GO
|
||||||
ALTER TABLE [phpbb_notification_types] WITH NOCHECK ADD
|
ALTER TABLE [phpbb_notification_types] WITH NOCHECK ADD
|
||||||
CONSTRAINT [PK_phpbb_notification_types] PRIMARY KEY CLUSTERED
|
CONSTRAINT [PK_phpbb_notification_types] PRIMARY KEY CLUSTERED
|
||||||
(
|
(
|
||||||
[notification_type],
|
[notification_type_id]
|
||||||
[notification_type_enabled]
|
|
||||||
) ON [PRIMARY]
|
) ON [PRIMARY]
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX [type] ON [phpbb_notification_types]([notification_type_name]) ON [PRIMARY]
|
||||||
|
GO
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Table: 'phpbb_notifications'
|
Table: 'phpbb_notifications'
|
||||||
*/
|
*/
|
||||||
CREATE TABLE [phpbb_notifications] (
|
CREATE TABLE [phpbb_notifications] (
|
||||||
[notification_id] [int] IDENTITY (1, 1) NOT NULL ,
|
[notification_id] [int] IDENTITY (1, 1) NOT NULL ,
|
||||||
[item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
|
[notification_type_id] [int] DEFAULT (0) NOT NULL ,
|
||||||
[item_id] [int] DEFAULT (0) NOT NULL ,
|
[item_id] [int] DEFAULT (0) NOT NULL ,
|
||||||
[item_parent_id] [int] DEFAULT (0) NOT NULL ,
|
[item_parent_id] [int] DEFAULT (0) NOT NULL ,
|
||||||
[user_id] [int] DEFAULT (0) NOT NULL ,
|
[user_id] [int] DEFAULT (0) NOT NULL ,
|
||||||
|
@ -829,7 +832,7 @@ ALTER TABLE [phpbb_notifications] WITH NOCHECK ADD
|
||||||
) ON [PRIMARY]
|
) ON [PRIMARY]
|
||||||
GO
|
GO
|
||||||
|
|
||||||
CREATE INDEX [item_ident] ON [phpbb_notifications]([item_type], [item_id]) ON [PRIMARY]
|
CREATE INDEX [item_ident] ON [phpbb_notifications]([notification_type_id], [item_id]) ON [PRIMARY]
|
||||||
GO
|
GO
|
||||||
|
|
||||||
CREATE INDEX [user] ON [phpbb_notifications]([user_id], [notification_read]) ON [PRIMARY]
|
CREATE INDEX [user] ON [phpbb_notifications]([user_id], [notification_read]) ON [PRIMARY]
|
||||||
|
|
|
@ -452,16 +452,18 @@ CREATE TABLE phpbb_modules (
|
||||||
|
|
||||||
# Table: 'phpbb_notification_types'
|
# Table: 'phpbb_notification_types'
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type varbinary(255) DEFAULT '' NOT NULL,
|
notification_type_id smallint(4) UNSIGNED NOT NULL auto_increment,
|
||||||
|
notification_type_name varbinary(255) DEFAULT '' NOT NULL,
|
||||||
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
|
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
|
||||||
PRIMARY KEY (notification_type, notification_type_enabled)
|
PRIMARY KEY (notification_type_id),
|
||||||
|
UNIQUE type (notification_type_name)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
# Table: 'phpbb_notifications'
|
# Table: 'phpbb_notifications'
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
notification_id int(10) UNSIGNED NOT NULL auto_increment,
|
||||||
item_type varbinary(255) DEFAULT '' NOT NULL,
|
notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
|
@ -469,7 +471,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
|
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
|
||||||
notification_data blob NOT NULL,
|
notification_data blob NOT NULL,
|
||||||
PRIMARY KEY (notification_id),
|
PRIMARY KEY (notification_id),
|
||||||
KEY item_ident (item_type, item_id),
|
KEY item_ident (notification_type_id, item_id),
|
||||||
KEY user (user_id, notification_read)
|
KEY user (user_id, notification_read)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -452,16 +452,18 @@ CREATE TABLE phpbb_modules (
|
||||||
|
|
||||||
# Table: 'phpbb_notification_types'
|
# Table: 'phpbb_notification_types'
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type varchar(255) DEFAULT '' NOT NULL,
|
notification_type_id smallint(4) UNSIGNED NOT NULL auto_increment,
|
||||||
|
notification_type_name varchar(255) DEFAULT '' NOT NULL,
|
||||||
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
|
notification_type_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
|
||||||
PRIMARY KEY (notification_type, notification_type_enabled)
|
PRIMARY KEY (notification_type_id),
|
||||||
|
UNIQUE type (notification_type_name)
|
||||||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||||
|
|
||||||
|
|
||||||
# Table: 'phpbb_notifications'
|
# Table: 'phpbb_notifications'
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
notification_id int(10) UNSIGNED NOT NULL auto_increment,
|
||||||
item_type varchar(255) DEFAULT '' NOT NULL,
|
notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||||
|
@ -469,7 +471,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
|
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
|
||||||
notification_data text NOT NULL,
|
notification_data text NOT NULL,
|
||||||
PRIMARY KEY (notification_id),
|
PRIMARY KEY (notification_id),
|
||||||
KEY item_ident (item_type, item_id),
|
KEY item_ident (notification_type_id, item_id),
|
||||||
KEY user (user_id, notification_read)
|
KEY user (user_id, notification_read)
|
||||||
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
) CHARACTER SET `utf8` COLLATE `utf8_bin`;
|
||||||
|
|
||||||
|
|
|
@ -870,19 +870,37 @@ END;
|
||||||
Table: 'phpbb_notification_types'
|
Table: 'phpbb_notification_types'
|
||||||
*/
|
*/
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type varchar2(255) DEFAULT '' ,
|
notification_type_id number(4) NOT NULL,
|
||||||
|
notification_type_name varchar2(255) DEFAULT '' ,
|
||||||
notification_type_enabled number(1) DEFAULT '1' NOT NULL,
|
notification_type_enabled number(1) DEFAULT '1' NOT NULL,
|
||||||
CONSTRAINT pk_phpbb_notification_types PRIMARY KEY (notification_type, notification_type_enabled)
|
CONSTRAINT pk_phpbb_notification_types PRIMARY KEY (notification_type_id),
|
||||||
|
CONSTRAINT u_phpbb_type UNIQUE (notification_type_name)
|
||||||
)
|
)
|
||||||
/
|
/
|
||||||
|
|
||||||
|
|
||||||
|
CREATE SEQUENCE phpbb_notification_types_seq
|
||||||
|
/
|
||||||
|
|
||||||
|
CREATE OR REPLACE TRIGGER t_phpbb_notification_types
|
||||||
|
BEFORE INSERT ON phpbb_notification_types
|
||||||
|
FOR EACH ROW WHEN (
|
||||||
|
new.notification_type_id IS NULL OR new.notification_type_id = 0
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
SELECT phpbb_notification_types_seq.nextval
|
||||||
|
INTO :new.notification_type_id
|
||||||
|
FROM dual;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Table: 'phpbb_notifications'
|
Table: 'phpbb_notifications'
|
||||||
*/
|
*/
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id number(8) NOT NULL,
|
notification_id number(10) NOT NULL,
|
||||||
item_type varchar2(255) DEFAULT '' ,
|
notification_type_id number(4) DEFAULT '0' NOT NULL,
|
||||||
item_id number(8) DEFAULT '0' NOT NULL,
|
item_id number(8) DEFAULT '0' NOT NULL,
|
||||||
item_parent_id number(8) DEFAULT '0' NOT NULL,
|
item_parent_id number(8) DEFAULT '0' NOT NULL,
|
||||||
user_id number(8) DEFAULT '0' NOT NULL,
|
user_id number(8) DEFAULT '0' NOT NULL,
|
||||||
|
@ -893,7 +911,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
)
|
)
|
||||||
/
|
/
|
||||||
|
|
||||||
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id)
|
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id)
|
||||||
/
|
/
|
||||||
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read)
|
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read)
|
||||||
/
|
/
|
||||||
|
|
|
@ -623,12 +623,16 @@ CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id
|
||||||
/*
|
/*
|
||||||
Table: 'phpbb_notification_types'
|
Table: 'phpbb_notification_types'
|
||||||
*/
|
*/
|
||||||
|
CREATE SEQUENCE phpbb_notification_types_seq;
|
||||||
|
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type varchar(255) DEFAULT '' NOT NULL,
|
notification_type_id INT2 DEFAULT nextval('phpbb_notification_types_seq'),
|
||||||
|
notification_type_name varchar(255) DEFAULT '' NOT NULL,
|
||||||
notification_type_enabled INT2 DEFAULT '1' NOT NULL CHECK (notification_type_enabled >= 0),
|
notification_type_enabled INT2 DEFAULT '1' NOT NULL CHECK (notification_type_enabled >= 0),
|
||||||
PRIMARY KEY (notification_type, notification_type_enabled)
|
PRIMARY KEY (notification_type_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types (notification_type_name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Table: 'phpbb_notifications'
|
Table: 'phpbb_notifications'
|
||||||
|
@ -637,7 +641,7 @@ CREATE SEQUENCE phpbb_notifications_seq;
|
||||||
|
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'),
|
notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'),
|
||||||
item_type varchar(255) DEFAULT '' NOT NULL,
|
notification_type_id INT2 DEFAULT '0' NOT NULL CHECK (notification_type_id >= 0),
|
||||||
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
|
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
|
||||||
item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_id >= 0),
|
item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_id >= 0),
|
||||||
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
|
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
|
||||||
|
@ -647,7 +651,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
PRIMARY KEY (notification_id)
|
PRIMARY KEY (notification_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
|
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id);
|
||||||
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
|
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -439,16 +439,17 @@ CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id
|
||||||
|
|
||||||
# Table: 'phpbb_notification_types'
|
# Table: 'phpbb_notification_types'
|
||||||
CREATE TABLE phpbb_notification_types (
|
CREATE TABLE phpbb_notification_types (
|
||||||
notification_type varchar(255) NOT NULL DEFAULT '',
|
notification_type_id INTEGER PRIMARY KEY NOT NULL ,
|
||||||
notification_type_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1',
|
notification_type_name varchar(255) NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (notification_type, notification_type_enabled)
|
notification_type_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX phpbb_notification_types_type ON phpbb_notification_types (notification_type_name);
|
||||||
|
|
||||||
# Table: 'phpbb_notifications'
|
# Table: 'phpbb_notifications'
|
||||||
CREATE TABLE phpbb_notifications (
|
CREATE TABLE phpbb_notifications (
|
||||||
notification_id INTEGER PRIMARY KEY NOT NULL ,
|
notification_id INTEGER PRIMARY KEY NOT NULL ,
|
||||||
item_type varchar(255) NOT NULL DEFAULT '',
|
notification_type_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||||
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||||
item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||||
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
@ -457,7 +458,7 @@ CREATE TABLE phpbb_notifications (
|
||||||
notification_data text(65535) NOT NULL DEFAULT ''
|
notification_data text(65535) NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
|
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (notification_type_id, item_id);
|
||||||
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
|
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
|
||||||
|
|
||||||
# Table: 'phpbb_poll_options'
|
# Table: 'phpbb_poll_options'
|
||||||
|
|
|
@ -424,6 +424,7 @@ $lang = array_merge($lang, array(
|
||||||
'NOTIFICATION_TOPIC_APPROVED' => 'Your topic "%2$s" in the forum "%3$s" was approved.',
|
'NOTIFICATION_TOPIC_APPROVED' => 'Your topic "%2$s" in the forum "%3$s" was approved.',
|
||||||
'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved for reason: "%2$s".',
|
'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved for reason: "%2$s".',
|
||||||
'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by %1$s and needs approval.',
|
'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by %1$s and needs approval.',
|
||||||
|
'NOTIFICATION_TYPE_NOT_EXIST' => 'The notification type "%s" is missing from the file system.',
|
||||||
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
|
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
|
||||||
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>',
|
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>',
|
||||||
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',
|
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',
|
||||||
|
|
|
@ -29,14 +29,14 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notifications">
|
<table name="phpbb_notifications">
|
||||||
<column>item_type</column>
|
<column>notification_type_id</column>
|
||||||
<column>user_id</column>
|
<column>user_id</column>
|
||||||
<column>item_id</column>
|
<column>item_id</column>
|
||||||
<column>item_parent_id</column>
|
<column>item_parent_id</column>
|
||||||
<column>notification_read</column>
|
<column>notification_read</column>
|
||||||
<column>notification_data</column>
|
<column>notification_data</column>
|
||||||
<row>
|
<row>
|
||||||
<value>bookmark</value>
|
<value>1</value>
|
||||||
<value>5</value>
|
<value>5</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -45,9 +45,11 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notification_types">
|
<table name="phpbb_notification_types">
|
||||||
<column>notification_type</column>
|
<column>notification_type_id</column>
|
||||||
|
<column>notification_type_name</column>
|
||||||
<column>notification_type_enabled</column>
|
<column>notification_type_enabled</column>
|
||||||
<row>
|
<row>
|
||||||
|
<value>1</value>
|
||||||
<value>bookmark</value>
|
<value>bookmark</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
|
|
@ -21,14 +21,14 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notifications">
|
<table name="phpbb_notifications">
|
||||||
<column>item_type</column>
|
<column>notification_type_id</column>
|
||||||
<column>user_id</column>
|
<column>user_id</column>
|
||||||
<column>item_id</column>
|
<column>item_id</column>
|
||||||
<column>item_parent_id</column>
|
<column>item_parent_id</column>
|
||||||
<column>notification_read</column>
|
<column>notification_read</column>
|
||||||
<column>notification_data</column>
|
<column>notification_data</column>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>1</value>
|
||||||
<value>5</value>
|
<value>5</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
<value></value>
|
<value></value>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<value>post</value>
|
<value>1</value>
|
||||||
<value>8</value>
|
<value>8</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -45,9 +45,11 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notification_types">
|
<table name="phpbb_notification_types">
|
||||||
<column>notification_type</column>
|
<column>notification_type_id</column>
|
||||||
|
<column>notification_type_name</column>
|
||||||
<column>notification_type_enabled</column>
|
<column>notification_type_enabled</column>
|
||||||
<row>
|
<row>
|
||||||
|
<value>1</value>
|
||||||
<value>post</value>
|
<value>post</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<dataset>
|
<dataset>
|
||||||
<table name="phpbb_notifications">
|
<table name="phpbb_notifications">
|
||||||
<column>item_type</column>
|
<column>notification_type_id</column>
|
||||||
<column>user_id</column>
|
<column>user_id</column>
|
||||||
<column>item_id</column>
|
<column>item_id</column>
|
||||||
<column>item_parent_id</column>
|
<column>item_parent_id</column>
|
||||||
<column>notification_read</column>
|
<column>notification_read</column>
|
||||||
<column>notification_data</column>
|
<column>notification_data</column>
|
||||||
<row>
|
<row>
|
||||||
<value>post_in_queue</value>
|
<value>1</value>
|
||||||
<value>6</value>
|
<value>6</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -17,9 +17,11 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notification_types">
|
<table name="phpbb_notification_types">
|
||||||
<column>notification_type</column>
|
<column>notification_type_id</column>
|
||||||
|
<column>notification_type_name</column>
|
||||||
<column>notification_type_enabled</column>
|
<column>notification_type_enabled</column>
|
||||||
<row>
|
<row>
|
||||||
|
<value>1</value>
|
||||||
<value>post_in_queue</value>
|
<value>post_in_queue</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<dataset>
|
<dataset>
|
||||||
<table name="phpbb_notifications">
|
<table name="phpbb_notifications">
|
||||||
<column>item_type</column>
|
<column>notification_type_id</column>
|
||||||
<column>user_id</column>
|
<column>user_id</column>
|
||||||
<column>item_id</column>
|
<column>item_id</column>
|
||||||
<column>item_parent_id</column>
|
<column>item_parent_id</column>
|
||||||
<column>notification_read</column>
|
<column>notification_read</column>
|
||||||
<column>notification_data</column>
|
<column>notification_data</column>
|
||||||
<row>
|
<row>
|
||||||
<value>quote</value>
|
<value>1</value>
|
||||||
<value>5</value>
|
<value>5</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
|
@ -17,9 +17,11 @@
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
<table name="phpbb_notification_types">
|
<table name="phpbb_notification_types">
|
||||||
<column>notification_type</column>
|
<column>notification_type_id</column>
|
||||||
|
<column>notification_type_name</column>
|
||||||
<column>notification_type_enabled</column>
|
<column>notification_type_enabled</column>
|
||||||
<row>
|
<row>
|
||||||
|
<value>1</value>
|
||||||
<value>quote</value>
|
<value>quote</value>
|
||||||
<value>1</value>
|
<value>1</value>
|
||||||
</row>
|
</row>
|
||||||
|
|
|
@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
|
||||||
* Notifications service class
|
* Notifications service class
|
||||||
* @package notifications
|
* @package notifications
|
||||||
*/
|
*/
|
||||||
class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager
|
class phpbb_notification_manager_helper extends phpbb_notification_manager
|
||||||
{
|
{
|
||||||
public function set_var($name, $value)
|
public function set_var($name, $value)
|
||||||
{
|
{
|
||||||
|
@ -28,12 +28,10 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
|
||||||
|
|
||||||
// Extra dependencies for get_*_class functions
|
// Extra dependencies for get_*_class functions
|
||||||
protected $auth = null;
|
protected $auth = null;
|
||||||
protected $cache = null;
|
|
||||||
protected $config = null;
|
protected $config = null;
|
||||||
public function setDependencies($auth, $cache, $config)
|
public function setDependencies($auth, $config)
|
||||||
{
|
{
|
||||||
$this->auth = $auth;
|
$this->auth = $auth;
|
||||||
$this->cache = $cache;
|
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +42,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
|
||||||
{
|
{
|
||||||
$item_type = 'phpbb_notification_type_' . $item_type;
|
$item_type = 'phpbb_notification_type_' . $item_type;
|
||||||
|
|
||||||
$item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
$item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
||||||
|
|
||||||
$item->set_notification_manager($this);
|
$item->set_notification_manager($this);
|
||||||
|
|
||||||
|
@ -60,7 +58,7 @@ class phpbb_mock_notifications_notification_manager extends phpbb_notification_m
|
||||||
{
|
{
|
||||||
$method_name = 'phpbb_notification_method_' . $method_name;
|
$method_name = 'phpbb_notification_method_' . $method_name;
|
||||||
|
|
||||||
$method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
$method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
||||||
|
|
||||||
$method->set_notification_manager($this);
|
$method->set_notification_manager($this);
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/manager_helper.php';
|
||||||
|
|
||||||
class phpbb_notification_test extends phpbb_database_test_case
|
class phpbb_notification_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
||||||
|
@ -31,19 +33,26 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'allow_topic_notify' => true,
|
'allow_topic_notify' => true,
|
||||||
'allow_forum_notify' => true,
|
'allow_forum_notify' => true,
|
||||||
));
|
));
|
||||||
$this->user = new phpbb_mock_user();
|
$this->user = new phpbb_user();
|
||||||
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
|
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
|
||||||
$this->auth = new phpbb_mock_notifications_auth();
|
$this->auth = new phpbb_mock_notifications_auth();
|
||||||
$this->cache = new phpbb_mock_cache();
|
$this->cache = new phpbb_cache_service(
|
||||||
|
new phpbb_cache_driver_null(),
|
||||||
|
$this->config,
|
||||||
|
$this->db,
|
||||||
|
$phpbb_root_path,
|
||||||
|
$phpEx
|
||||||
|
);
|
||||||
|
|
||||||
$this->container = new phpbb_mock_container_builder();
|
$this->container = new phpbb_mock_container_builder();
|
||||||
|
|
||||||
$this->notifications = new phpbb_mock_notifications_notification_manager(
|
$this->notifications = new phpbb_notification_manager_helper(
|
||||||
array(),
|
array(),
|
||||||
array(),
|
array(),
|
||||||
$this->container,
|
$this->container,
|
||||||
$this->user_loader,
|
$this->user_loader,
|
||||||
$this->db,
|
$this->db,
|
||||||
|
$this->cache,
|
||||||
$this->user,
|
$this->user,
|
||||||
$phpbb_root_path,
|
$phpbb_root_path,
|
||||||
$phpEx,
|
$phpEx,
|
||||||
|
@ -52,7 +61,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'phpbb_user_notifications'
|
'phpbb_user_notifications'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->notifications->setDependencies($this->auth, $this->cache, $this->config);
|
$this->notifications->setDependencies($this->auth, $this->config);
|
||||||
|
|
||||||
$types = array();
|
$types = array();
|
||||||
foreach (array(
|
foreach (array(
|
||||||
|
@ -87,7 +96,36 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx;
|
global $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
|
return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_notification_type_id()
|
||||||
|
{
|
||||||
|
// They should be inserted the first time
|
||||||
|
$this->assertEquals(1, $this->notifications->get_notification_type_id('post'));
|
||||||
|
$this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
|
||||||
|
$this->assertEquals(3, $this->notifications->get_notification_type_id('test'));
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'test' => 3,
|
||||||
|
'quote' => 2,
|
||||||
|
'post' => 1,
|
||||||
|
),
|
||||||
|
$this->notifications->get_notification_type_ids(array(
|
||||||
|
'test',
|
||||||
|
'quote',
|
||||||
|
'post',
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$this->assertEquals(2, $this->notifications->get_notification_type_id('quote'));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->assertEquals(3, $this->notifications->get_notification_type_id('fail'));
|
||||||
|
|
||||||
|
$this->fail('Non-existent type should throw an exception');
|
||||||
|
}
|
||||||
|
catch (Exception $e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_get_subscription_types()
|
public function test_get_subscription_types()
|
||||||
|
@ -121,6 +159,20 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_notifications()
|
public function test_notifications()
|
||||||
{
|
{
|
||||||
|
$this->db->sql_query('DELETE FROM phpbb_notification_types');
|
||||||
|
|
||||||
|
$types = array('quote', 'bookmark', 'post', 'test');
|
||||||
|
foreach ($types as $id => $type)
|
||||||
|
{
|
||||||
|
$this->db->sql_query('INSERT INTO phpbb_notification_types ' .
|
||||||
|
$this->db->sql_build_array('INSERT', array(
|
||||||
|
'notification_type_id' => ($id + 1),
|
||||||
|
'notification_type_name' => $type,
|
||||||
|
'notification_type_enabled' => 1,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Used to test post notifications later
|
// Used to test post notifications later
|
||||||
$this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
$this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||||
'topic_id' => 2,
|
'topic_id' => 2,
|
||||||
|
@ -195,7 +247,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
1 => array(
|
1 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 1,
|
'item_id' => 1,
|
||||||
'item_parent_id' => 1,
|
'item_parent_id' => 1,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -204,7 +256,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
2 => array(
|
2 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 2,
|
'item_id' => 2,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -213,7 +265,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
3 => array(
|
3 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 3,
|
'item_id' => 3,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -222,7 +274,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
4 => array(
|
4 => array(
|
||||||
'item_type' => 'post',
|
'notification_type_id' => 3,
|
||||||
'item_id' => 4,
|
'item_id' => 4,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -238,7 +290,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
5 => array(
|
5 => array(
|
||||||
'item_type' => 'bookmark',
|
'notification_type_id' => 2,
|
||||||
'item_id' => 5,
|
'item_id' => 5,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -301,7 +353,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
1 => array(
|
1 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 1,
|
'item_id' => 1,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -310,7 +362,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
2 => array(
|
2 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 2,
|
'item_id' => 2,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -319,7 +371,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
3 => array(
|
3 => array(
|
||||||
'item_type' => 'test',
|
'notification_type_id' => 4,
|
||||||
'item_id' => 3,
|
'item_id' => 3,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -328,7 +380,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
'notification_data' => array(),
|
'notification_data' => array(),
|
||||||
),
|
),
|
||||||
4 => array(
|
4 => array(
|
||||||
'item_type' => 'post',
|
'notification_type_id' => 3,
|
||||||
'item_id' => 4,
|
'item_id' => 4,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
@ -344,7 +396,7 @@ class phpbb_notification_test extends phpbb_database_test_case
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
5 => array(
|
5 => array(
|
||||||
'item_type' => 'bookmark',
|
'notification_type_id' => 2,
|
||||||
'item_id' => 5,
|
'item_id' => 5,
|
||||||
'item_parent_id' => 2,
|
'item_parent_id' => 2,
|
||||||
'user_id' => 0,
|
'user_id' => 0,
|
||||||
|
|
|
@ -52,9 +52,6 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
$this->db = $this->new_dbal();
|
$this->db = $this->new_dbal();
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
|
|
||||||
// Cache
|
|
||||||
$cache = new phpbb_mock_cache();
|
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
$auth = $this->getMock('phpbb_auth');
|
$auth = $this->getMock('phpbb_auth');
|
||||||
$auth->expects($this->any())
|
$auth->expects($this->any())
|
||||||
|
@ -72,6 +69,14 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
set_config(null, null, null, $config);
|
set_config(null, null, null, $config);
|
||||||
set_config_count(null, null, null, $config);
|
set_config_count(null, null, null, $config);
|
||||||
|
|
||||||
|
$cache = new phpbb_cache_service(
|
||||||
|
new phpbb_cache_driver_null(),
|
||||||
|
$config,
|
||||||
|
$db,
|
||||||
|
$phpbb_root_path,
|
||||||
|
$phpEx
|
||||||
|
);
|
||||||
|
|
||||||
// Event dispatcher
|
// Event dispatcher
|
||||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
|
||||||
|
@ -94,23 +99,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
|
|
||||||
$user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
$user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
|
||||||
|
|
||||||
// Notification Manager
|
|
||||||
$phpbb_notifications = new phpbb_notification_manager(array(), array(),
|
|
||||||
$phpbb_container, $user_loader, $db, $user,
|
|
||||||
$phpbb_root_path, $phpEx,
|
|
||||||
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
|
|
||||||
$phpbb_container->set('notification_manager', $phpbb_notifications);
|
|
||||||
|
|
||||||
// Notification Types
|
// Notification Types
|
||||||
$notification_types = array('quote', 'bookmark', 'post', 'post_in_queue');
|
$notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'approve_topic', 'approve_post');
|
||||||
|
$notification_types_array = array();
|
||||||
foreach ($notification_types as $type)
|
foreach ($notification_types as $type)
|
||||||
{
|
{
|
||||||
$class_name = 'phpbb_notification_type_' . $type;
|
$class_name = 'phpbb_notification_type_' . $type;
|
||||||
$phpbb_container->set('notification.type.' . $type, new $class_name(
|
$class = new $class_name(
|
||||||
$user_loader, $db, $cache, $user, $auth, $config,
|
$user_loader, $db, $cache->get_driver(), $user, $auth, $config,
|
||||||
$phpbb_root_path, $phpEx,
|
$phpbb_root_path, $phpEx,
|
||||||
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE));
|
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
|
||||||
|
|
||||||
|
$phpbb_container->set('notification.type.' . $type, $class);
|
||||||
|
|
||||||
|
$notification_types_array['notification.type.' . $type] = $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notification Manager
|
||||||
|
$phpbb_notifications = new phpbb_notification_manager($notification_types_array, array(),
|
||||||
|
$phpbb_container, $user_loader, $db, $cache, $user,
|
||||||
|
$phpbb_root_path, $phpEx,
|
||||||
|
NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE);
|
||||||
|
$phpbb_container->set('notification_manager', $phpbb_notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,8 +129,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
public function test_submit_post($additional_post_data, $expected_before, $expected_after)
|
public function test_submit_post($additional_post_data, $expected_before, $expected_after)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT user_id, item_id, item_parent_id
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
FROM ' . NOTIFICATIONS_TABLE . "
|
FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
|
||||||
WHERE item_type = '" . $this->item_type . "'
|
WHERE nt.notification_type_name = '" . $this->item_type . "'
|
||||||
|
AND n.notification_type_id = nt.notification_type_id
|
||||||
ORDER BY user_id, item_id ASC";
|
ORDER BY user_id, item_id ASC";
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
$this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
|
$this->assertEquals($expected_before, $this->db->sql_fetchrowset($result));
|
||||||
|
@ -131,8 +142,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case
|
||||||
submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false);
|
submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false);
|
||||||
|
|
||||||
$sql = 'SELECT user_id, item_id, item_parent_id
|
$sql = 'SELECT user_id, item_id, item_parent_id
|
||||||
FROM ' . NOTIFICATIONS_TABLE . "
|
FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt
|
||||||
WHERE item_type = '" . $this->item_type . "'
|
WHERE nt.notification_type_name = '" . $this->item_type . "'
|
||||||
|
AND n.notification_type_id = nt.notification_type_id
|
||||||
ORDER BY user_id ASC, item_id ASC";
|
ORDER BY user_id ASC, item_id ASC";
|
||||||
$result = $this->db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
$this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));
|
$this->assertEquals($expected_after, $this->db->sql_fetchrowset($result));
|
||||||
|
|
Loading…
Add table
Reference in a new issue