aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2012-11-20 20:56:00 -0800
committerNathan Guse <nathaniel.guse@gmail.com>2012-11-20 20:56:00 -0800
commit25d4809c9257f29902450c19e1a4eb248211a8ed (patch)
treeab584092e7e54f50a15dd9a22ed5b31200ea03f1 /phpBB/includes
parentd2187424da6ff2e0d4a69a6e21bac7e92f68335a (diff)
parent2afb8b9df873c3f9572a32ab7a62ea8ba8d8a45b (diff)
downloadforums-25d4809c9257f29902450c19e1a4eb248211a8ed.tar
forums-25d4809c9257f29902450c19e1a4eb248211a8ed.tar.gz
forums-25d4809c9257f29902450c19e1a4eb248211a8ed.tar.bz2
forums-25d4809c9257f29902450c19e1a4eb248211a8ed.tar.xz
forums-25d4809c9257f29902450c19e1a4eb248211a8ed.zip
Merge pull request #1 from EXreaction/ticket/11103-dev
[ticket/11103] Create user loader class, update for DIC
Diffstat (limited to 'phpBB/includes')
-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
21 files changed, 284 insertions, 206 deletions
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