aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/config/notifications.yml82
-rw-r--r--phpBB/config/services.yml18
-rw-r--r--phpBB/config/tables.yml1
-rw-r--r--phpBB/includes/functions.php36
-rw-r--r--phpBB/includes/functions_admin.php16
-rw-r--r--phpBB/includes/functions_posting.php30
-rw-r--r--phpBB/includes/functions_privmsgs.php14
-rw-r--r--phpBB/includes/mcp/mcp_pm_reports.php2
-rw-r--r--phpBB/includes/mcp/mcp_queue.php28
-rw-r--r--phpBB/includes/mcp/mcp_reports.php10
-rw-r--r--phpBB/includes/notification/manager.php127
-rw-r--r--phpBB/includes/notification/method/base.php14
-rw-r--r--phpBB/includes/notification/method/email.php4
-rw-r--r--phpBB/includes/notification/type/base.php39
-rw-r--r--phpBB/includes/notification/type/bookmark.php4
-rw-r--r--phpBB/includes/notification/type/pm.php8
-rw-r--r--phpBB/includes/notification/type/post.php10
-rw-r--r--phpBB/includes/notification/type/quote.php10
-rw-r--r--phpBB/includes/notification/type/report_pm.php4
-rw-r--r--phpBB/includes/notification/type/report_pm_closed.php2
-rw-r--r--phpBB/includes/notification/type/report_post.php4
-rw-r--r--phpBB/includes/notification/type/report_post_closed.php4
-rw-r--r--phpBB/includes/notification/type/topic.php6
-rw-r--r--phpBB/includes/user_loader.php118
-rw-r--r--phpBB/install/database_update.php12
-rw-r--r--phpBB/report.php4
-rw-r--r--tests/mock/container_builder.php19
-rw-r--r--tests/mock/notifications_notification_manager.php69
-rw-r--r--tests/notification/ext/test/notification/type/test.php7
-rw-r--r--tests/notification/notification.php139
30 files changed, 517 insertions, 324 deletions
diff --git a/phpBB/config/notifications.yml b/phpBB/config/notifications.yml
index 7c8e05494c..f8a5b5f9fa 100644
--- a/phpBB/config/notifications.yml
+++ b/phpBB/config/notifications.yml
@@ -1,12 +1,24 @@
services:
+ notification.type_collection:
+ class: phpbb_di_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: notification.type }
+
+ notification.method_collection:
+ class: phpbb_di_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: notification.method }
+
notification.type.approve_post:
class: phpbb_notification_type_approve_post
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -20,11 +32,9 @@ services:
notification.type.approve_topic:
class: phpbb_notification_type_approve_topic
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -38,11 +48,9 @@ services:
notification.type.bookmark:
class: phpbb_notification_type_bookmark
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -56,11 +64,9 @@ services:
notification.type.disapprove_post:
class: phpbb_notification_type_disapprove_post
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -74,11 +80,9 @@ services:
notification.type.disapprove_topic:
class: phpbb_notification_type_disapprove_topic
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -92,11 +96,9 @@ services:
notification.type.pm:
class: phpbb_notification_type_pm
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -110,11 +112,9 @@ services:
notification.type.post:
class: phpbb_notification_type_post
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -128,11 +128,9 @@ services:
notification.type.post_in_queue:
class: phpbb_notification_type_post_in_queue
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -146,11 +144,9 @@ services:
notification.type.quote:
class: phpbb_notification_type_quote
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -164,11 +160,9 @@ services:
notification.type.report_pm:
class: phpbb_notification_type_report_pm
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -182,11 +176,9 @@ services:
notification.type.report_pm_closed:
class: phpbb_notification_type_report_pm_closed
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -200,11 +192,9 @@ services:
notification.type.report_post:
class: phpbb_notification_type_report_post
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -218,11 +208,9 @@ services:
notification.type.report_post_closed:
class: phpbb_notification_type_report_post
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -236,11 +224,9 @@ services:
notification.type.topic:
class: phpbb_notification_type_topic
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -254,11 +240,9 @@ services:
notification.type.topic_in_queue:
class: phpbb_notification_type_topic_in_queue
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -272,11 +256,9 @@ services:
notification.method.email:
class: phpbb_notification_method_email
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
@@ -288,11 +270,9 @@ services:
notification.method.jabber:
class: phpbb_notification_method_jabber
arguments:
- - @notification_manager
+ - @user_loader
- @dbal.conn
- @cache.driver
- - @template
- - @ext.manager
- @user
- @auth
- @config
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index af80d28b15..bbc28e903f 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -97,14 +97,12 @@ services:
notification_manager:
class: phpbb_notification_manager
arguments:
- - @container
+ - @notification.type_collection
+ - @notification.method_collection
+ - @service_container
+ - @user_loader
- @dbal.conn
- - @cache.driver
- - @template
- - @ext.manager
- @user
- - @auth
- - @config
- %core.root_path%
- %core.php_ext%
- %tables.notifications%
@@ -151,3 +149,11 @@ services:
user:
class: phpbb_user
+
+ user_loader:
+ class: phpbb_user_loader
+ arguments:
+ - @dbal.conn
+ - %core.root_path%
+ - %core.php_ext%
+ - %tables.users%
diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml
index 8791c5e89b..528470d6ca 100644
--- a/phpBB/config/tables.yml
+++ b/phpBB/config/tables.yml
@@ -3,3 +3,4 @@ parameters:
tables.ext: %core.table_prefix%ext
tables.notifications: %core.table_prefix%notifications
tables.user_notifications: %core.table_prefix%user_notifications
+ tables.users: %core.table_prefix%users
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 4e26d2c642..283ed4a657 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1331,12 +1331,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
// Mark all topic notifications read for this user
$phpbb_notifications->mark_notifications_read(array(
- 'phpbb_notification_type_topic',
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
- 'phpbb_notification_type_approve_topic',
- 'phpbb_notification_type_approve_post',
+ 'topic',
+ 'quote',
+ 'bookmark',
+ 'post',
+ 'approve_topic',
+ 'approve_post',
), false, $user->data['user_id'], $post_time);
if ($config['load_db_lastread'] && $user->data['is_registered'])
@@ -1394,8 +1394,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
}
$phpbb_notifications->mark_notifications_read_by_parent(array(
- 'phpbb_notification_type_topic',
- 'phpbb_notification_type_approve_topic',
+ 'topic',
+ 'approve_topic',
), $forum_id, $user->data['user_id'], $post_time);
// Mark all post/quote notifications read for this user in this forum
@@ -1411,10 +1411,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
$db->sql_freeresult($result);
$phpbb_notifications->mark_notifications_read_by_parent(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
- 'phpbb_notification_type_approve_post',
+ 'quote',
+ 'bookmark',
+ 'post',
+ 'approve_post',
), $topic_ids, $user->data['user_id'], $post_time);
// Add 0 to forums array to mark global announcements correctly
@@ -1516,14 +1516,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
// Mark post notifications read for this user in this topic
$phpbb_notifications->mark_notifications_read(array(
- 'phpbb_notification_type_topic',
- 'phpbb_notification_type_approve_topic',
+ 'topic',
+ 'approve_topic',
), $topic_id, $user->data['user_id'], $post_time);
$phpbb_notifications->mark_notifications_read_by_parent(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
- 'phpbb_notification_type_approve_post',
+ 'quote',
+ 'bookmark',
+ 'post',
+ 'approve_post',
), $topic_id, $user->data['user_id'], $post_time);
if ($config['load_db_lastread'] && $user->data['is_registered'])
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index fdae1905a0..e15bf12279 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -717,9 +717,9 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
}
$phpbb_notifications->delete_notifications(array(
- 'phpbb_notification_type_topic',
- 'phpbb_notification_type_approve_topic',
- 'phpbb_notification_type_topic_in_queue',
+ 'topic',
+ 'approve_topic',
+ 'topic_in_queue',
), $topic_ids);
return $return;
@@ -901,11 +901,11 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
}
$phpbb_notifications->delete_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
- 'phpbb_notification_type_approve_post',
- 'phpbb_notification_type_post_in_queue',
+ 'quote',
+ 'bookmark',
+ 'post',
+ 'approve_post',
+ 'post_in_queue',
), $post_ids);
return sizeof($post_ids);
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 4df199d72d..8ba1fed6a7 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -2237,17 +2237,17 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
{
case 'post':
$phpbb_notifications->add_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_topic',
+ 'quote',
+ 'topic',
), $notification_data);
break;
case 'reply':
case 'quote':
$phpbb_notifications->add_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
+ 'quote',
+ 'bookmark',
+ 'post',
), $notification_data);
break;
@@ -2256,10 +2256,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
case 'edit':
case 'edit_last_post':
$phpbb_notifications->update_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_topic',
- 'phpbb_notification_type_post',
+ 'quote',
+ 'bookmark',
+ 'topic',
+ 'post',
), $notification_data);
break;
}
@@ -2269,23 +2269,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
switch ($mode)
{
case 'post':
- $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data);
+ $phpbb_notifications->add_notifications('topic_in_queue', $notification_data);
break;
case 'reply':
case 'quote':
- $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data);
+ $phpbb_notifications->add_notifications('post_in_queue', $notification_data);
break;
case 'edit_topic':
case 'edit_first_post':
case 'edit':
case 'edit_last_post':
- $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']);
+ $phpbb_notifications->delete_notifications('topic', $data['topic_id']);
$phpbb_notifications->delete_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
+ 'quote',
+ 'bookmark',
+ 'post',
), $data['post_id']);
break;
}
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php
index 54e8ced679..ae8ffbe90e 100644
--- a/phpBB/includes/functions_privmsgs.php
+++ b/phpBB/includes/functions_privmsgs.php
@@ -878,7 +878,7 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id)
global $db, $user, $phpbb_notifications;
- $phpbb_notifications->mark_notifications_read('phpbb_notification_type_pm', $msg_id, $user_id);
+ $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id);
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
SET pm_unread = 0
@@ -1096,7 +1096,7 @@ function delete_pm($user_id, $msg_ids, $folder_id)
$user->data['user_unread_privmsg'] -= $num_unread;
}
- $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', array_keys($delete_rows));
+ $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows));
// Now we have to check which messages we can delete completely
$sql = 'SELECT msg_id
@@ -1277,7 +1277,7 @@ function phpbb_delete_users_pms($user_ids)
AND ' . $db->sql_in_set('msg_id', $delivered_msg);
$db->sql_query($sql);
- $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delivered_msg);
+ $phpbb_notifications->delete_notifications('pm', $delivered_msg);
}
if (!empty($undelivered_msg))
@@ -1290,7 +1290,7 @@ function phpbb_delete_users_pms($user_ids)
WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
$db->sql_query($sql);
- $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $undelivered_msg);
+ $phpbb_notifications->delete_notifications('pm', $undelivered_msg);
}
}
@@ -1334,7 +1334,7 @@ function phpbb_delete_users_pms($user_ids)
WHERE ' . $db->sql_in_set('msg_id', $delete_ids);
$db->sql_query($sql);
- $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delete_ids);
+ $phpbb_notifications->delete_notifications('pm', $delete_ids);
}
}
@@ -1879,11 +1879,11 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true)
if ($mode == 'edit')
{
- $phpbb_notifications->update_notifications('phpbb_notification_type_pm', $pm_data);
+ $phpbb_notifications->update_notifications('pm', $pm_data);
}
else
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_pm', $pm_data);
+ $phpbb_notifications->add_notifications('pm', $pm_data);
}
return $data['msg_id'];
diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php
index 2a52a0b4fd..4ba1b2fd0c 100644
--- a/phpBB/includes/mcp/mcp_pm_reports.php
+++ b/phpBB/includes/mcp/mcp_pm_reports.php
@@ -90,7 +90,7 @@ class mcp_pm_reports
trigger_error('NO_REPORT');
}
- $phpbb_notifications->mark_notifications_read_by_parent('phpbb_notification_type_report_pm', $report_id, $user->data['user_id']);
+ $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']);
$pm_id = $report['pm_id'];
$report_id = $report['report_id'];
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index f13ce914bf..4a3d443006 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -86,7 +86,7 @@ class mcp_queue
{
$post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
- $phpbb_notifications->mark_notifications_read('phpbb_notification_type_topic_in_queue', $topic_id, $user->data['user_id']);
+ $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']);
}
else
{
@@ -94,7 +94,7 @@ class mcp_queue
}
}
- $phpbb_notifications->mark_notifications_read('phpbb_notification_type_post_in_queue', $post_id, $user->data['user_id']);
+ $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']);
$post_info = get_post_data(array($post_id), 'm_approve', true);
@@ -610,28 +610,28 @@ function approve_post($post_id_list, $id, $mode)
{
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{
- $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']);
+ $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']);
- $phpbb_notifications->add_notifications('phpbb_notification_type_topic', $post_data);
+ $phpbb_notifications->add_notifications('topic', $post_data);
if ($notify_poster)
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_approve_topic', $post_data);
+ $phpbb_notifications->add_notifications('approve_topic', $post_data);
}
}
else
{
- $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id);
+ $phpbb_notifications->delete_notifications('post_in_queue', $post_id);
$phpbb_notifications->add_notifications(array(
- 'phpbb_notification_type_quote',
- 'phpbb_notification_type_bookmark',
- 'phpbb_notification_type_post',
+ 'quote',
+ 'bookmark',
+ 'post',
), $post_data);
if ($notify_poster)
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_approve_post', $post_data);
+ $phpbb_notifications->add_notifications('approve_post', $post_data);
}
}
}
@@ -859,11 +859,11 @@ function disapprove_post($post_id_list, $id, $mode)
{
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{
- $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']);
+ $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']);
}
else
{
- $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id);
+ $phpbb_notifications->delete_notifications('post_in_queue', $post_id);
}
}
@@ -909,14 +909,14 @@ function disapprove_post($post_id_list, $id, $mode)
{
if ($notify_poster)
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_topic', $post_data);
+ $phpbb_notifications->add_notifications('disapprove_topic', $post_data);
}
}
else
{
if ($notify_poster)
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_post', $post_data);
+ $phpbb_notifications->add_notifications('disapprove_post', $post_data);
}
}
}
diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php
index 41cdbc75d6..85723ab3f7 100644
--- a/phpBB/includes/mcp/mcp_reports.php
+++ b/phpBB/includes/mcp/mcp_reports.php
@@ -88,7 +88,7 @@ class mcp_reports
trigger_error('NO_REPORT');
}
- $phpbb_notifications->mark_notifications_read('phpbb_notification_type_report_post', $post_id, $user->data['user_id']);
+ $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']);
if (!$report_id && $report['report_closed'])
{
@@ -647,20 +647,20 @@ function close_report($report_id_list, $mode, $action, $pm = false)
if ($pm)
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm_closed', array_merge($post_info[$post_id], array(
+ $phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array(
'reporter' => $reporter['user_id'],
'closer_id' => $user->data['user_id'],
'from_user_id' => $post_info[$post_id]['author_id'],
)));
- $phpbb_notifications->delete_notifications('phpbb_notification_type_report_pm', $post_id);
+ $phpbb_notifications->delete_notifications('report_pm', $post_id);
}
else
{
- $phpbb_notifications->add_notifications('phpbb_notification_type_report_post_closed', array_merge($post_info[$post_id], array(
+ $phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array(
'reporter' => $reporter['user_id'],
'closer_id' => $user->data['user_id'],
)));
- $phpbb_notifications->delete_notifications('phpbb_notification_type_report_post', $post_id);
+ $phpbb_notifications->delete_notifications('report_post', $post_id);
}
}
}
diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php
index 3d0ada4a43..fbfe388c80 100644
--- a/phpBB/includes/notification/manager.php
+++ b/phpBB/includes/notification/manager.php
@@ -7,8 +7,6 @@
*
*/
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
/**
* @ignore
*/
@@ -23,30 +21,24 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_notification_manager
{
+ /** @var array */
+ protected $notification_types = null;
+
+ /** @var array */
+ protected $notification_methods = null;
+
/** @var ContainerBuilder */
protected $phpbb_container = null;
-
- /** @var dbal */
- protected $db = null;
-
- /** @var phpbb_cache_service */
- protected $cache = null;
- /** @var phpbb_template */
- protected $template = null;
+ /** @var phpbb_user_loader */
+ protected $user_loader = null;
- /** @var phpbb_extension_manager */
- protected $extension_manager = null;
+ /** @var dbal */
+ protected $db = null;
/** @var phpbb_user */
protected $user = null;
- /** @var phpbb_auth */
- protected $auth = null;
-
- /** @var phpbb_config */
- protected $config = null;
-
/** @var string */
protected $phpbb_root_path = null;
@@ -59,23 +51,15 @@ class phpbb_notification_manager
/** @var string */
protected $user_notifications_table = null;
- /**
- * Users loaded from the DB
- *
- * @var array Array of user data that we've loaded from the DB
- */
- protected $users = array();
-
- public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table)
+ public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table)
{
+ $this->notification_types = $notification_types;
+ $this->notification_methods = $notification_methods;
$this->phpbb_container = $phpbb_container;
+
+ $this->user_loader = $user_loader;
$this->db = $db;
- $this->cache = $cache;
- $this->template = $template;
- $this->extension_manager = $extension_manager;
$this->user = $user;
- $this->auth = $auth;
- $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@@ -209,7 +193,7 @@ class phpbb_notification_manager
$notifications[$row['notification_id']] = $notification;
}
- $this->load_users($user_ids);
+ $this->user_loader->load_users($user_ids);
// Allow each type to load its own special items
foreach ($load_special as $item_type => $data)
@@ -334,7 +318,7 @@ class phpbb_notification_manager
return $notified_users;
}
- $item_id = $item_type::get_item_id($data);
+ $item_id = $this->get_item_type_class($item_type)->get_item_id($data);
// 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);
@@ -363,7 +347,7 @@ class phpbb_notification_manager
return;
}
- $item_id = $item_type::get_item_id($data);
+ $item_id = $this->get_item_type_class($item_type)->get_item_id($data);
$user_ids = array();
$notification_objects = $notification_methods = array();
@@ -428,7 +412,7 @@ class phpbb_notification_manager
$this->db->sql_multi_insert($this->notifications_table, $new_rows);
// We need to load all of the users to send notifications
- $this->load_users($user_ids);
+ $this->user_loader->load_users($user_ids);
// run the queue for each method to send notifications
foreach ($notification_methods as $method)
@@ -467,7 +451,7 @@ class phpbb_notification_manager
}
}
- $item_id = $item_type::get_item_id($data);
+ $item_id = $notification->get_item_id($data);
$update_array = $notification->create_update_array($data);
$sql = 'UPDATE ' . $this->notifications_table . '
@@ -511,7 +495,7 @@ class phpbb_notification_manager
{
$subscription_types = array();
- foreach ($this->phpbb_container->findTaggedServiceIds('notification.type') as $type_name => $data)
+ foreach ($this->notification_types as $type_name => $data)
{
$type = $this->get_item_type_class($type_name);
@@ -547,7 +531,7 @@ class phpbb_notification_manager
{
$subscription_methods = array();
- foreach ($this->phpbb_container->findTaggedServiceIds('notification.method') as $method_name => $data)
+ foreach ($this->notification_methods as $method_name => $data)
{
$method = $this->get_method_class($method_name);
@@ -759,63 +743,48 @@ class phpbb_notification_manager
}
/**
- * Load user helper
- *
- * @param array $user_ids
+ * Helper to get the notifications item type class and set it up
*/
- public function load_users($user_ids)
+ public function get_item_type_class($item_type, $data = array())
{
- $user_ids[] = ANONYMOUS;
-
- // Load the users
- $user_ids = array_unique($user_ids);
-
- // Do not load users we already have in $this->users
- $user_ids = array_diff($user_ids, array_keys($this->users));
+ $item = $this->load_object('notification.type.' . $item_type);
- if (sizeof($user_ids))
- {
- $sql = 'SELECT *
- FROM ' . USERS_TABLE . '
- WHERE ' . $this->db->sql_in_set('user_id', $user_ids);
- $result = $this->db->sql_query($sql);
+ $item->set_initial_data($data);
- while ($row = $this->db->sql_fetchrow($result))
- {
- $this->users[$row['user_id']] = $row;
- }
- $this->db->sql_freeresult($result);
- }
+ return $item;
}
/**
- * Get a user row from our users cache
- *
- * @param int $user_id
- * @return array
+ * Helper to get the notifications method class and set it up
*/
- public function get_user($user_id)
+ public function get_method_class($method_name)
{
- return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS];
+ return $this->load_object('notification.method.' . $method_name);
}
/**
- * Helper to get the notifications item type class and set it up
+ * Helper to load objects (notification types/methods)
*/
- public function get_item_type_class($item_type, $data = array())
+ protected function load_object($object_name)
{
- $item = $this->phpbb_container->get($item_type);
+ // Here we cannot just use ContainerBuilder->get(name)
+ // The reason for this is because get handles services
+ // which are initialized once and shared. Here we need
+ // separate new objects because we pass around objects
+ // that store row data in each object, which would lead
+ // to over-writing of data if we used get()
- $item->set_initial_data($data);
+ $parameterBag = $this->phpbb_container->getParameterBag();
+ $definition = $this->phpbb_container->getDefinition($object_name);
+ $arguments = $this->phpbb_container->resolveServices(
+ $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments()))
+ );
+ $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
- return $item;
- }
+ $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
- /**
- * Helper to get the notifications method class and set it up
- */
- public function get_method_class($method_name)
- {
- return $this->phpbb_container->get($method_name);
+ $object->set_notification_manager($this);
+
+ return $object;
}
}
diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php
index 88ec2674be..3f85d62a09 100644
--- a/phpBB/includes/notification/method/base.php
+++ b/phpBB/includes/notification/method/base.php
@@ -24,6 +24,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
/** @var phpbb_notification_manager */
protected $notification_manager = null;
+ /** @var phpbb_user_loader */
+ protected $user_loader = null;
+
/** @var dbal */
protected $db = null;
@@ -58,13 +61,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
*/
protected $queue = array();
- public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
+ public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext)
{
- $this->notification_manager = $notification_manager;
+ $this->user_loader = $user_loader;
$this->db = $db;
$this->cache = $cache;
- $this->template = $template;
- $this->extension_manager = $extension_manager;
$this->user = $user;
$this->auth = $auth;
$this->config = $config;
@@ -72,6 +73,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth
$this->php_ext = $php_ext;
}
+ public function set_notification_manager(phpbb_notification_manager $notification_manager)
+ {
+ $this->notification_manager = $notification_manager;
+ }
+
/**
* Add a notification to the queue
*
diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php
index 2ff30b177f..429dfda2ba 100644
--- a/phpBB/includes/notification/method/email.php
+++ b/phpBB/includes/notification/method/email.php
@@ -82,7 +82,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base
$banned_users = phpbb_get_banned_user_ids($user_ids);
// Load all the users we need
- $this->notification_manager->load_users($user_ids);
+ $this->user_loader->load_users($user_ids);
// Load the messenger
if (!class_exists('messenger'))
@@ -100,7 +100,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base
continue;
}
- $user = $this->notification_manager->get_user($notification->user_id);
+ $user = $this->user_loader->get_user($notification->user_id);
if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users))
{
diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php
index 419dce3dd0..d596c06167 100644
--- a/phpBB/includes/notification/type/base.php
+++ b/phpBB/includes/notification/type/base.php
@@ -24,6 +24,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/** @var phpbb_notification_manager */
protected $notification_manager = null;
+ /** @var phpbb_user_loader */
+ protected $user_loader = null;
+
/** @var dbal */
protected $db = null;
@@ -33,9 +36,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
/** @var phpbb_template */
protected $template = null;
- /** @var phpbb_extension_manager */
- protected $extension_manager = null;
-
/** @var phpbb_user */
protected $user = null;
@@ -84,13 +84,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*/
private $data = array();
- public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table)
+ public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table)
{
- $this->notification_manager = $notification_manager;
+ $this->user_loader = $user_loader;
$this->db = $db;
$this->cache = $cache;
- $this->template = $template;
- $this->extension_manager = $extension_manager;
$this->user = $user;
$this->auth = $auth;
$this->config = $config;
@@ -102,6 +100,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$this->user_notifications_table = $user_notifications_table;
}
+ public function set_notification_manager(phpbb_notification_manager $notification_manager)
+ {
+ $this->notification_manager = $notification_manager;
+ }
+
/**
* Set initial data from the database
*
@@ -357,7 +360,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$rowset = $resulting_user_ids = array();
$sql = 'SELECT user_id, method, notify
- FROM ' . USER_NOTIFICATIONS_TABLE . '
+ FROM ' . $this->user_notifications_table . '
WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . "
AND item_type = '" . $this->db->sql_escape($options['item_type']) . "'
AND item_id = " . (int) $options['item_id'];
@@ -395,24 +398,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
}
/**
- * Get avatar helper
- *
- * @param int $user_id
- * @return string
- */
- protected function get_user_avatar($user_id)
- {
- $user = $this->notification_manager->get_user($user_id);
-
- if (!function_exists('get_user_avatar'))
- {
- include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
- }
-
- return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar');
- }
-
- /**
* Mark this item read/unread helper
*
* @param bool $unread Unread (True/False) (Default: False)
@@ -435,7 +420,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
return $where;
}
- $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ $sql = 'UPDATE ' . $this->notifications_table . '
SET unread = ' . (int) $this->unread . '
WHERE ' . $where;
$this->db->sql_query($sql);
diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php
index a40bbde5e4..a17d8f5db7 100644
--- a/phpBB/includes/notification/type/bookmark.php
+++ b/phpBB/includes/notification/type/bookmark.php
@@ -102,7 +102,7 @@ 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
$update_notifications = array();
$sql = 'SELECT *
- FROM ' . NOTIFICATIONS_TABLE . "
+ FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1
@@ -114,7 +114,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
- $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ $sql = 'UPDATE ' . $this->notifications_table . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id'];
$this->db->sql_query($sql);
diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php
index fbdf351062..1eaeb1a250 100644
--- a/phpBB/includes/notification/type/pm.php
+++ b/phpBB/includes/notification/type/pm.php
@@ -92,7 +92,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base
unset($pm['recipients'][$pm['from_user_id']]);
- $this->notification_manager->load_users(array_keys($pm['recipients']));
+ $this->user_loader->load_users(array_keys($pm['recipients']));
return $this->check_user_notification_options(array_keys($pm['recipients']), $options);
}
@@ -102,7 +102,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('from_user_id'));
+ return $this->user_loader->get_avatar($this->get_data('from_user_id'));
}
/**
@@ -112,7 +112,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base
*/
public function get_title()
{
- $user_data = $this->notification_manager->get_user($this->get_data('from_user_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('from_user_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
@@ -136,7 +136,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base
*/
public function get_email_template_variables()
{
- $user_data = $this->notification_manager->get_user($this->get_data('from_user_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('from_user_id'));
return array(
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php
index a99558efe7..7e06779982 100644
--- a/phpBB/includes/notification/type/post.php
+++ b/phpBB/includes/notification/type/post.php
@@ -123,7 +123,7 @@ 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
$update_notifications = array();
$sql = 'SELECT *
- FROM ' . NOTIFICATIONS_TABLE . "
+ FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1
@@ -135,7 +135,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
- $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ $sql = 'UPDATE ' . $this->notifications_table . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id'];
$this->db->sql_query($sql);
@@ -150,7 +150,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('poster_id'));
+ return $this->user_loader->get_avatar($this->get_data('poster_id'));
}
/**
@@ -181,7 +181,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
}
else
{
- $user_data = $this->notification_manager->get_user($responder['poster_id']);
+ $user_data = $this->user_loader->get_user($responder['poster_id']);
$usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
}
@@ -217,7 +217,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
}
else
{
- $user_data = $this->notification_manager->get_user($this->get_data('poster_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
$username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
}
diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php
index f45bb1ae7d..1796343a0e 100644
--- a/phpBB/includes/notification/type/quote.php
+++ b/phpBB/includes/notification/type/quote.php
@@ -121,7 +121,7 @@ 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
$update_notifications = array();
$sql = 'SELECT *
- FROM ' . NOTIFICATIONS_TABLE . "
+ FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1
@@ -133,7 +133,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
- $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ $sql = 'UPDATE ' . $this->notifications_table . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id'];
$this->db->sql_query($sql);
@@ -152,7 +152,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
{
$old_notifications = array();
$sql = 'SELECT user_id
- FROM ' . NOTIFICATIONS_TABLE . "
+ FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_id = " . self::get_item_id($post) . '
AND is_enabled = 1';
@@ -182,7 +182,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
// Remove the necessary notifications
if (!empty($remove_notifications))
{
- $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
+ $sql = 'DELETE FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_id = " . self::get_item_id($post) . '
AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
@@ -210,7 +210,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
*/
public function get_email_template_variables()
{
- $user_data = $this->notification_manager->get_user($this->get_data('poster_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
return array_merge(parent::get_email_template_variables(), array(
'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']),
diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php
index 9bdc59a4ef..73e22dc83b 100644
--- a/phpBB/includes/notification/type/report_pm.php
+++ b/phpBB/includes/notification/type/report_pm.php
@@ -160,7 +160,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm
{
$this->user->add_lang('mcp');
- $user_data = $this->notification_manager->get_user($this->get_data('reporter_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('reporter_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
@@ -197,7 +197,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('reporter_id'));
+ return $this->user_loader->get_avatar($this->get_data('reporter_id'));
}
/**
diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php
index de87c9f760..51e5204304 100644
--- a/phpBB/includes/notification/type/report_pm_closed.php
+++ b/phpBB/includes/notification/type/report_pm_closed.php
@@ -106,7 +106,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p
*/
public function get_title()
{
- $user_data = $this->notification_manager->get_user($this->get_data('closer_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('closer_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php
index d80c7b754f..2508644b0b 100644
--- a/phpBB/includes/notification/type/report_post.php
+++ b/phpBB/includes/notification/type/report_post.php
@@ -127,7 +127,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i
{
$this->user->add_lang('mcp');
- $user_data = $this->notification_manager->get_user($this->get_data('reporter_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('reporter_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
@@ -164,7 +164,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('reporter_id'));
+ return $this->user_loader->get_avatar($this->get_data('reporter_id'));
}
/**
diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php
index cde0ff85a8..a7016a8f3d 100644
--- a/phpBB/includes/notification/type/report_post_closed.php
+++ b/phpBB/includes/notification/type/report_post_closed.php
@@ -106,7 +106,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type
*/
public function get_title()
{
- $user_data = $this->notification_manager->get_user($this->get_data('closer_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('closer_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
@@ -122,7 +122,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('closer_id'));
+ return $this->user_loader->get_avatar($this->get_data('closer_id'));
}
/**
diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php
index 4eb03194f5..6e9347d4a8 100644
--- a/phpBB/includes/notification/type/topic.php
+++ b/phpBB/includes/notification/type/topic.php
@@ -126,7 +126,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
*/
public function get_avatar()
{
- return $this->get_user_avatar($this->get_data('poster_id'));
+ return $this->user_loader->get_avatar($this->get_data('poster_id'));
}
/**
@@ -142,7 +142,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
}
else
{
- $user_data = $this->notification_manager->get_user($this->get_data('poster_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
}
@@ -178,7 +178,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
}
else
{
- $user_data = $this->notification_manager->get_user($this->get_data('poster_id'));
+ $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
$username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
}
diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php
new file mode 100644
index 0000000000..a530f21f75
--- /dev/null
+++ b/phpBB/includes/user_loader.php
@@ -0,0 +1,118 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* User loader class
+*
+* This handles loading users from the database and
+* storing in them in a temporary cache so we do not
+* have to query the same user multiple times in
+* different services.
+*/
+class phpbb_user_loader
+{
+ /** @var dbal */
+ protected $db = null;
+
+ /** @var string */
+ protected $phpbb_root_path = null;
+
+ /** @var string */
+ protected $php_ext = null;
+
+ /** @var string */
+ protected $users_table = null;
+
+ /**
+ * Users loaded from the DB
+ *
+ * @var array Array of user data that we've loaded from the DB
+ */
+ protected $users = array();
+
+ public function __construct(dbal $db, $phpbb_root_path, $php_ext, $users_table)
+ {
+ $this->db = $db;
+
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+
+ $this->users_table = $users_table;
+ }
+
+ /**
+ * Load user helper
+ *
+ * @param array $user_ids
+ */
+ public function load_users(array $user_ids)
+ {
+ $user_ids[] = ANONYMOUS;
+
+ // Load the users
+ $user_ids = array_unique($user_ids);
+
+ // Do not load users we already have in $this->users
+ $user_ids = array_diff($user_ids, array_keys($this->users));
+
+ if (sizeof($user_ids))
+ {
+ $sql = 'SELECT *
+ FROM ' . $this->users_table . '
+ WHERE ' . $this->db->sql_in_set('user_id', $user_ids);
+ $result = $this->db->sql_query($sql);
+
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $this->users[$row['user_id']] = $row;
+ }
+ $this->db->sql_freeresult($result);
+ }
+ }
+
+ /**
+ * Get a user row from our users cache
+ *
+ * @param int $user_id
+ * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist
+ * or bool False if the anonymous user was not loaded
+ */
+ public function get_user($user_id)
+ {
+ return (isset($this->users[$user_id])) ? $this->users[$user_id] : (isset($this->users[ANONYMOUS]) ? $this->users[ANONYMOUS] : false);
+ }
+
+ /**
+ * Get avatar
+ *
+ * @param int $user_id
+ * @return string
+ */
+ public function get_avatar($user_id)
+ {
+ if (!($user = $this->get_user($user_id)))
+ {
+ return '';
+ }
+
+ if (!function_exists('get_user_avatar'))
+ {
+ include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
+ }
+
+ return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']);
+ }
+} \ No newline at end of file
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index ab48da059d..768280ec7e 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -2814,19 +2814,19 @@ function change_database_data(&$no_updates, $version)
$convert_notifications = array(
array(
'check' => ($config['allow_topic_notify']),
- 'item_type' => 'phpbb_notification_type_post',
+ 'item_type' => 'post',
),
array(
'check' => ($config['allow_forum_notify']),
- 'item_type' => 'phpbb_notification_type_topic',
+ 'item_type' => 'topic',
),
array(
'check' => ($config['allow_bookmarks']),
- 'item_type' => 'phpbb_notification_type_bookmark',
+ 'item_type' => 'bookmark',
),
array(
'check' => ($config['allow_privmsg']),
- 'item_type' => 'phpbb_notification_type_pm',
+ 'item_type' => 'pm',
),
);
@@ -2853,7 +2853,7 @@ function change_database_data(&$no_updates, $version)
'item_type' => $convert_data['item_type'],
'item_id' => 0,
'user_id' => $row['user_id'],
- 'method' => 'phpbb_notification_method_email',
+ 'method' => 'email',
)), $errored, $error_ary);
}
@@ -2863,7 +2863,7 @@ function change_database_data(&$no_updates, $version)
'item_type' => $convert_data['item_type'],
'item_id' => 0,
'user_id' => $row['user_id'],
- 'method' => 'phpbb_notification_method_jabber',
+ 'method' => 'jabber',
)), $errored, $error_ary);
}
}
diff --git a/phpBB/report.php b/phpBB/report.php
index 95043a6978..07cec7afbc 100644
--- a/phpBB/report.php
+++ b/phpBB/report.php
@@ -191,7 +191,7 @@ if ($submit && $reason_id)
$lang_return = $user->lang['RETURN_TOPIC'];
$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
- $phpbb_notifications->add_notifications('phpbb_notification_type_report_post', array_merge($report_data, $row, $forum_data, array(
+ $phpbb_notifications->add_notifications('report_post', array_merge($report_data, $row, $forum_data, array(
'report_text' => $report_text,
)));
}
@@ -221,7 +221,7 @@ if ($submit && $reason_id)
$lang_return = $user->lang['RETURN_PM'];
$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
- $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm', array_merge($report_data, $row, array(
+ $phpbb_notifications->add_notifications('report_pm', array_merge($report_data, $row, array(
'report_text' => $report_text,
'from_user_id' => $report_data['author_id'],
'report_id' => $report_id,
diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php
index 8a81dd72d1..734d3e1741 100644
--- a/tests/mock/container_builder.php
+++ b/tests/mock/container_builder.php
@@ -11,6 +11,9 @@ use Symfony\Component\DependencyInjection\ScopeInterface;
class phpbb_mock_container_builder implements ContainerInterface
{
+ protected $services = array();
+ protected $parameters = array();
+
/**
* Sets a service.
*
@@ -22,6 +25,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
{
+ $this->services[$id] = $service;
}
/**
@@ -42,6 +46,12 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
+ if ($this->has($id))
+ {
+ return $this->services[$id];
+ }
+
+ throw new Exception('Could not find service: ' . $id);
}
/**
@@ -55,6 +65,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function has($id)
{
+ return isset($this->services[$id]);
}
/**
@@ -70,6 +81,12 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function getParameter($name)
{
+ if ($this->hasParameter($name))
+ {
+ return $this->parameters[$name];
+ }
+
+ throw new Exception('Could not find parameter: ' . $name);
}
/**
@@ -83,6 +100,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function hasParameter($name)
{
+ return isset($this->parameters[$name]);
}
/**
@@ -95,6 +113,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function setParameter($name, $value)
{
+ $this->parameters[$name] = $value;
}
/**
diff --git a/tests/mock/notifications_notification_manager.php b/tests/mock/notifications_notification_manager.php
new file mode 100644
index 0000000000..81f24e67c0
--- /dev/null
+++ b/tests/mock/notifications_notification_manager.php
@@ -0,0 +1,69 @@
+<?php
+/**
+*
+* @package notifications
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Notifications service class
+* @package notifications
+*/
+class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager
+{
+ public function set_var($name, $value)
+ {
+ $this->$name = $value;
+ }
+
+ // Extra dependencies for get_*_class functions
+ protected $auth = null;
+ protected $cache = null;
+ protected $config = null;
+ public function setDependencies($auth, $cache, $config)
+ {
+ $this->auth = $auth;
+ $this->cache = $cache;
+ $this->config = $config;
+ }
+
+ /**
+ * Helper to get the notifications item type class and set it up
+ */
+ public function get_item_type_class($item_type, $data = array())
+ {
+ $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->notifications_table, $this->user_notifications_table);
+
+ $item->set_notification_manager($this);
+
+ $item->set_initial_data($data);
+
+ return $item;
+ }
+
+ /**
+ * Helper to get the notifications method class and set it up
+ */
+ public function get_method_class($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->notifications_table, $this->user_notifications_table);
+
+ $method->set_notification_manager($this);
+
+ return $method;
+ }
+}
diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php
index 34149484df..45670e1c2d 100644
--- a/tests/notification/ext/test/notification/type/test.php
+++ b/tests/notification/ext/test/notification/type/test.php
@@ -15,8 +15,13 @@ if (!defined('IN_PHPBB'))
exit;
}
-class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base
+class phpbb_notification_type_test extends phpbb_notification_type_base
{
+ public function get_type()
+ {
+ return 'test';
+ }
+
public static function get_item_id($post)
{
return (int) $post['post_id'];
diff --git a/tests/notification/notification.php b/tests/notification/notification.php
index 9c88ad892e..8fa77ff651 100644
--- a/tests/notification/notification.php
+++ b/tests/notification/notification.php
@@ -6,10 +6,10 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
-
+//calls: [ [set_notification_manager, [@notification_manager]] ]
class phpbb_notification_test extends phpbb_database_test_case
{
- protected $notifications;
+ protected $notifications, $db, $container, $user, $config, $auth, $cache;
public function getDataSet()
{
@@ -30,34 +30,69 @@ class phpbb_notification_test extends phpbb_database_test_case
include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
- $db = $this->new_dbal();
- $config = new phpbb_config(array(
+ $db = $this->db = $this->new_dbal();
+ $this->config = new phpbb_config(array(
'allow_privmsg' => true,
'allow_bookmarks' => true,
'allow_topic_notify' => true,
'allow_forum_notify' => true,
));
- $user = new phpbb_mock_user();
-
- $this->notifications = new phpbb_notification_manager(
- $db,
- new phpbb_mock_cache(),
- new phpbb_template($phpbb_root_path, $phpEx, $config, $user, new phpbb_style_resource_locator()),
- new phpbb_mock_extension_manager($phpbb_root_path,
- array(
- 'test' => array(
- 'ext_name' => 'test',
- 'ext_active' => '1',
- 'ext_path' => 'ext/test/',
- ),
- )
- ),
- $user,
- new phpbb_mock_notifications_auth(),
- $config,
+ $this->user = new phpbb_mock_user();
+ $this->user_loader = new phpbb_user_loader($this->db, 'phpbb_users');
+ $this->auth = new phpbb_mock_notifications_auth();
+ $this->cache = new phpbb_mock_cache();
+
+ $this->container = new phpbb_mock_container_builder();
+
+ $this->notifications = new phpbb_mock_notifications_notification_manager(
+ array(),
+ array(),
+ $this->container,
+ $this->user_loader,
+ $this->db,
+ $this->user,
$phpbb_root_path,
- $phpEx
+ $phpEx,
+ 'phpbb_notifications',
+ 'phpbb_user_notifications'
);
+
+ $this->notifications->setDependencies($this->auth, $this->cache, $this->config);
+
+ $types = array();
+ foreach (array(
+ 'test',
+ 'approve_post',
+ 'approve_topic',
+ 'bookmark',
+ 'disapprove_post',
+ 'disapprove_topic',
+ 'pm',
+ 'post',
+ 'post_in_queue',
+ 'quote',
+ 'report_pm',
+ 'report_pm_closed',
+ 'report_post',
+ 'report_post_closed',
+ 'topic',
+ 'topic_in_queue',
+ ) as $type)
+ {
+ $class = $this->build_type('phpbb_notification_type_' . $type);
+
+ $types[$type] = $class;
+ $this->container->set('notification.type.' . $type, $class);
+ }
+
+ $this->notifications->set_var('notification_types', $types);
+ }
+
+ protected function build_type($type)
+ {
+ 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_notifications', 'phpbb_user_notifications');
}
public function test_get_subscription_types()
@@ -67,12 +102,12 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
$this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
- $this->assertArrayHasKey('phpbb_notification_type_bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
- $this->assertArrayHasKey('phpbb_notification_type_post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
- $this->assertArrayHasKey('phpbb_notification_type_quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
- $this->assertArrayHasKey('phpbb_notification_type_topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
+ $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
- $this->assertArrayHasKey('phpbb_notification_type_pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
+ $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
//get_subscription_types
//get_subscription_methods
@@ -80,13 +115,13 @@ class phpbb_notification_test extends phpbb_database_test_case
public function test_subscriptions()
{
- $this->notifications->delete_subscription('phpbb_notification_type_post', 0, '', 2);
+ $this->notifications->delete_subscription('post', 0, '', 2);
- $this->assertArrayNotHasKey('phpbb_notification_type_post', $this->notifications->get_global_subscriptions(2));
+ $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2));
- $this->notifications->add_subscription('phpbb_notification_type_post', 0, '', 2);
+ $this->notifications->add_subscription('post', 0, '', 2);
- $this->assertArrayHasKey('phpbb_notification_type_post', $this->notifications->get_global_subscriptions(2));
+ $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2));
}
public function test_notifications()
@@ -108,25 +143,25 @@ class phpbb_notification_test extends phpbb_database_test_case
'count_unread' => true,
)));
- $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->add_notifications('test', array(
'post_id' => '1',
'topic_id' => '1',
'post_time' => 1349413321,
));
- $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->add_notifications('test', array(
'post_id' => '2',
'topic_id' => '2',
'post_time' => 1349413322,
));
- $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->add_notifications('test', array(
'post_id' => '3',
'topic_id' => '2',
'post_time' => 1349413323,
));
- $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
+ $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
'post_id' => '4',
'topic_id' => '2',
'post_time' => 1349413324,
@@ -142,7 +177,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'user_id' => 0,
)));
- $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
+ $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
'post_id' => '5',
'topic_id' => '2',
'post_time' => 1349413325,
@@ -153,9 +188,9 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum',
));
- $this->notifications->delete_subscription('phpbb_ext_test_notification_type_test');
+ $this->notifications->delete_subscription('test');
- $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->add_notifications('test', array(
'post_id' => '6',
'topic_id' => '2',
'post_time' => 1349413326,
@@ -167,7 +202,7 @@ class phpbb_notification_test extends phpbb_database_test_case
$expected = array(
1 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
@@ -176,7 +211,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
2 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
@@ -185,7 +220,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
3 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
@@ -194,7 +229,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
4 => array(
- 'item_type' => 'phpbb_notification_type_post',
+ 'item_type' => 'post',
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
@@ -210,7 +245,7 @@ class phpbb_notification_test extends phpbb_database_test_case
),
),
5 => array(
- 'item_type' => 'phpbb_notification_type_bookmark',
+ 'item_type' => 'bookmark',
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
@@ -245,19 +280,19 @@ class phpbb_notification_test extends phpbb_database_test_case
// Now test updating -------------------------------
- $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->update_notifications('test', array(
'post_id' => '1',
'topic_id' => '2', // change parent_id
'post_time' => 1349413321,
));
- $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
+ $this->notifications->update_notifications('test', array(
'post_id' => '3',
'topic_id' => '2',
'post_time' => 1234, // change time
));
- $this->notifications->update_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
+ $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array(
'post_id' => '5',
'topic_id' => '2',
'poster_id' => 2,
@@ -273,7 +308,7 @@ class phpbb_notification_test extends phpbb_database_test_case
$expected = array(
1 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
@@ -282,7 +317,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
2 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
@@ -291,7 +326,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
3 => array(
- 'item_type' => 'phpbb_ext_test_notification_type_test',
+ 'item_type' => 'test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
@@ -300,7 +335,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'data' => array(),
),
4 => array(
- 'item_type' => 'phpbb_notification_type_post',
+ 'item_type' => 'post',
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
@@ -316,7 +351,7 @@ class phpbb_notification_test extends phpbb_database_test_case
),
),
5 => array(
- 'item_type' => 'phpbb_notification_type_bookmark',
+ 'item_type' => 'bookmark',
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,