From cea94d89848a806f449610ddb2a7df7b7eec1328 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:27:43 -0500 Subject: [PATCH] [ticket/11103] Use dependency injection instead of phpbb_container PHPBB3-11103 --- phpBB/config/services.yml | 10 +- phpBB/includes/notification/manager.php | 93 ++++++++++++------- phpBB/includes/notification/method/base.php | 30 +++--- phpBB/includes/notification/method/email.php | 6 +- phpBB/includes/notification/method/jabber.php | 6 +- .../notification/type/approve_post.php | 15 ++- .../notification/type/approve_topic.php | 15 ++- phpBB/includes/notification/type/base.php | 60 ++++++------ phpBB/includes/notification/type/bookmark.php | 23 ++--- .../notification/type/disapprove_post.php | 2 +- .../notification/type/disapprove_topic.php | 2 +- .../includes/notification/type/interface.php | 6 +- phpBB/includes/notification/type/pm.php | 23 ++--- phpBB/includes/notification/type/post.php | 25 +++-- .../notification/type/post_in_queue.php | 19 ++-- phpBB/includes/notification/type/quote.php | 43 ++++----- phpBB/includes/notification/type/topic.php | 25 +++-- .../notification/type/topic_in_queue.php | 19 ++-- 18 files changed, 204 insertions(+), 218 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 598c152fce..f9ae35ba57 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -92,7 +92,15 @@ services: notifications: class: phpbb_notification_manager arguments: - - @container + - @dbal.conn + - @cache.driver + - @template + - @ext.manager + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% processor.ext: class: phpbb_di_processor_ext diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 15db3f89fd..e2c6c9d0f4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -23,8 +23,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { - protected $phpbb_container; - protected $db; + protected $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Users loaded from the DB @@ -33,12 +32,17 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - $this->phpbb_container = $phpbb_container; - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); + $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; } /** @@ -56,12 +60,10 @@ class phpbb_notification_manager */ public function load_notifications($options = array()) { - $user = $this->phpbb_container->get('user'); - // Merge default options $options = array_merge(array( 'notification_id' => false, - 'user_id' => $user->data['user_id'], + 'user_id' => $this->user->data['user_id'], 'order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 0, @@ -74,7 +76,7 @@ class phpbb_notification_manager $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; // Anonymous users and bots never receive notifications - if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) + if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE)) { return array( 'notifications' => array(), @@ -136,7 +138,7 @@ class phpbb_notification_manager { $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = new $item_type_class_name($this->phpbb_container, $row); + $notification = $this->get_item_type_class($item_type_class_name, $row); // Array of user_ids to query all at once $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -153,12 +155,14 @@ class phpbb_notification_manager $this->load_users($user_ids); - // Allow each type to load it's own special items + // Allow each type to load its own special items foreach ($load_special as $item_type => $data) { $item_type_class_name = $this->get_item_type_class_name($item_type, true); - $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + $item_class = $this->get_item_type_class($item_type_class_name); + + $item_class->load_special($data, $notifications); } return array( @@ -283,7 +287,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); + $notify_users = $this->get_item_type_class($item_type_class_name)->find_users_for_notification($data, $options); $this->add_notifications_for_users($item_type, $data, $notify_users); @@ -343,7 +347,7 @@ class phpbb_notification_manager // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $notification->user_id = (int) $user; @@ -361,7 +365,7 @@ class phpbb_notification_manager if (!isset($notification_methods[$method])) { $method_class_name = 'phpbb_notification_method_' . $method; - $notification_methods[$method] = new $method_class_name($this->phpbb_container); + $notification_methods[$method] = $this->get_method_class($method_class_name); } $notification_methods[$method]->add_to_queue($notification); @@ -406,7 +410,7 @@ class phpbb_notification_manager if (method_exists($item_type_class_name, 'update_notifications')) { // Return False to over-ride the rest of the update - if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) { return; } @@ -414,7 +418,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' @@ -460,24 +464,26 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + foreach ($this->get_subscription_files('notifications/type/') as $class_name => $file) { - $class = $this->get_item_type_class_name($class); + $class_name = $this->get_item_type_class_name($class_name); - if (!class_exists($class)) + if (!class_exists($class_name)) { include($file); } - if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) + $class = $this->get_item_type_class($class_name); + + if ($class->is_available() && method_exists($class_name, 'get_item_type')) { - if ($class::$notification_option === false) + if ($class_name::$notification_option === false) { - $subscription_types[$class::get_item_type()] = $class::get_item_type(); + $subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); } else { - $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + $subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; } } } @@ -503,7 +509,7 @@ class phpbb_notification_manager include($file); } - $method = new $class_name($this->phpbb_container); + $method = $this->get_method_class($class_name); if ($method->is_available()) { @@ -524,7 +530,7 @@ class phpbb_notification_manager */ public function get_subscriptions($user_id = false, $only_global = false) { - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $subscriptions = array(); @@ -566,7 +572,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( @@ -590,7 +596,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -654,15 +660,32 @@ class phpbb_notification_manager return 'phpbb_notification_type_' . $item_type; } + /** + * Helper to get the notifications item type class and set it up + */ + private function get_item_type_class($item_type, $data = array()) + { + $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + private function get_method_class($method_name) + { + return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + } + /** * Helper to get subscription related files with the finder */ private function get_subscription_files($path) { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $php_ext = $this->phpbb_container->getParameter('core.php_ext'); - - $finder = $ext_manager->get_finder(); + $finder = $this->extension_manager->get_finder(); $subscription_files = array(); @@ -673,7 +696,7 @@ class phpbb_notification_manager foreach ($files as $file) { $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + $class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1)); if ($class == 'interface' || $class == 'base') { diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index b502d3afd0..ced85e2582 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -23,12 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $user; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Desired notifications @@ -56,20 +51,17 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - $this->user = $phpbb_container->get('user'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $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; } /** diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 1b6b44d137..c2e272aca1 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -57,12 +57,12 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { - include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need - $this->service->load_users($user_ids); + $this->notification_manager->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -75,7 +75,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { - $user = $this->service->get_user($notification->user_id); + $user = $this->notification_manager->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index 9232d8fc45..664e387d61 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -36,7 +36,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function is_available() { - return ($this->global_available() && $this->phpbb_container->get('user')->data['jabber']); + return ($this->global_available() && $this->user->data['jabber']); } /** @@ -45,9 +45,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function global_available() { - $config = $this->phpbb_container->get('config'); - - return ($config['jab_enable'] && @extension_loaded('xml')); + return ($this->config['jab_enable'] && @extension_loaded('xml')); } public function notify() diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 9a3def6217..3a88d9f54a 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 00af312018..0a6ca14a84 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 40462bccfb..626fe821e6 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -23,11 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Array of user data containing information needed to output the notifications to the template @@ -39,7 +35,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Notification option data (for outputting to the user) * - * @var bool|array False if the service should use it's default data + * @var bool|array False if the service should use its default data * Array of data (including keys 'id' and 'lang') */ public static $notification_option = false; @@ -60,20 +56,27 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(ContainerBuilder $phpbb_container, $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, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $this->notification_manager = $notification_manager; + $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; + } + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data = array()) + { // The row from the database (unless this is a new notification we're going to add) $this->data = $data; $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); @@ -117,15 +120,13 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ public function prepare_for_display() { - $user = $this->phpbb_container->get('user'); - return array( 'AVATAR' => $this->get_avatar(), 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), + 'TIME' => $this->user->format_date($this->time), 'UNREAD' => $this->unread, @@ -239,7 +240,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Load the special items (fall-back) */ - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + public function load_special($data, $notifications) { return; } @@ -247,7 +248,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Is available (fall-back) */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { return true; } @@ -259,27 +260,24 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Find the users who want to receive notifications (helper) * - * @param ContainerBuilder $phpbb_container * @param array $item_id The item_id to search for * * @return array */ - protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) + protected function _find_users_for_notification($item_id, $options) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $rowset = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . static::get_item_type() . "' AND item_id = " . (int) $item_id; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -293,7 +291,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $rowset; } @@ -306,7 +304,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function _get_avatar($user_id) { - $user = $this->service->get_user($user_id); + $user = $this->notification_manager->get_user($user_id); if (!function_exists('get_user_avatar')) { diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 51f23bc294..5ff39821dc 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -51,38 +51,35 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -94,9 +91,9 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -110,7 +107,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 8fa0102e3d..3ef45fb8e3 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 186c42d2b6..afd293a94f 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index aa54c62a97..c17f248080 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -25,9 +25,9 @@ interface phpbb_notification_type_interface public static function get_item_id($type_data); - public static function is_available(ContainerBuilder $phpbb_container); + public function is_available(); - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data, $options); + public function find_users_for_notification($type_data, $options); public function get_title(); @@ -45,5 +45,5 @@ interface phpbb_notification_type_interface public function get_load_special(); - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications); + public function load_special($data, $notifications); } diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 8252a8577b..9c1f353514 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -65,36 +65,31 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $pm Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm, $options = array()) + public function find_users_for_notification($pm, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - if (!sizeof($pm['recipients'])) { return array(); } - $service->load_users(array_keys($pm['recipients'])); + $this->notification_manager->load_users(array_keys($pm['recipients'])); $notify_users = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -108,7 +103,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -128,11 +123,11 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->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']); - return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); + return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } /** @@ -142,7 +137,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->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 1e654ef51b..37020825d3 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -71,12 +71,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_post extends phpbb_notification_type_base WHERE topic_id = ' . (int) $post['topic_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')) diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index f0a5e0baec..44f4f9391c 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -62,9 +62,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from the post * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $post['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index dd3cbedee2..32ee06787c 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -58,19 +58,16 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $usernames = false; preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); @@ -87,21 +84,21 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -113,9 +110,9 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -129,7 +126,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -137,28 +134,24 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * Update a notification * - * @param ContainerBuilder $phpbb_container * @param array $data Data specific for this type that will be updated */ - public static function update_notifications(ContainerBuilder $phpbb_container, $post) + public function update_notifications($post) { - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $old_notifications[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Find the new users to notify - $notifications = self::find_users_for_notification($phpbb_container, $post); + $notifications = $this->find_users_for_notification($post); // Find the notifications we must delete $remove_notifications = array_diff($old_notifications, array_keys($notifications)); @@ -185,8 +178,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post) . ' - AND ' . $db->sql_in_set('user_id', $remove_notifications); - $db->sql_query($sql); + AND ' . $this->db->sql_in_set('user_id', $remove_notifications); + $this->db->sql_query($sql); } // return true to continue with the update code in the notifications service (this will update the rest of the notifications) @@ -200,7 +193,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->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/topic.php b/phpBB/includes/notification/type/topic.php index 7753b196e8..01f394ccd2 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -71,12 +71,11 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base WHERE forum_id = ' . (int) $topic['forum_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $topic['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')), diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 385578cec8..d931168013 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -53,9 +53,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $topic['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; }