[ticket/14237] Use $language class for notifications

PHPBB3-14237
This commit is contained in:
Matt Friedman 2015-10-13 23:40:52 -07:00
parent 03cb2a7b0c
commit b64a37d451
23 changed files with 133 additions and 82 deletions

View file

@ -9,6 +9,7 @@ services:
- @dispatcher - @dispatcher
- @dbal.conn - @dbal.conn
- @cache - @cache
- @language
- @user - @user
- %tables.notification_types% - %tables.notification_types%
- %tables.user_notifications% - %tables.user_notifications%
@ -26,6 +27,7 @@ services:
abstract: true abstract: true
arguments: arguments:
- @dbal.conn - @dbal.conn
- @language
- @user - @user
- @auth - @auth
- %core.root_path% - %core.root_path%

View file

@ -44,6 +44,9 @@ class manager
/** @var \phpbb\cache\service */ /** @var \phpbb\cache\service */
protected $cache; protected $cache;
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\user */ /** @var \phpbb\user */
protected $user; protected $user;
@ -63,13 +66,14 @@ class manager
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache * @param \phpbb\cache\service $cache
* @param \phpbb\language\language $language
* @param \phpbb\user $user * @param \phpbb\user $user
* @param string $notification_types_table * @param string $notification_types_table
* @param string $user_notifications_table * @param string $user_notifications_table
* *
* @return \phpbb\notification\manager * @return \phpbb\notification\manager
*/ */
public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\user $user, $notification_types_table, $user_notifications_table) public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\language\language $language, \phpbb\user $user, $notification_types_table, $user_notifications_table)
{ {
$this->notification_types = $notification_types; $this->notification_types = $notification_types;
$this->notification_methods = $notification_methods; $this->notification_methods = $notification_methods;
@ -79,6 +83,7 @@ class manager
$this->phpbb_dispatcher = $phpbb_dispatcher; $this->phpbb_dispatcher = $phpbb_dispatcher;
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;
$this->language = $language;
$this->user = $user; $this->user = $user;
$this->notification_types_table = $notification_types_table; $this->notification_types_table = $notification_types_table;
@ -111,7 +116,7 @@ class manager
if (! $method instanceof \phpbb\notification\method\method_interface) if (! $method instanceof \phpbb\notification\method\method_interface)
{ {
throw new \phpbb\notification\exception($this->user->lang('NOTIFICATION_METHOD_INVALID', $method_name)); throw new \phpbb\notification\exception($this->language->lang('NOTIFICATION_METHOD_INVALID', $method_name));
} }
else if ($method->is_available()) else if ($method->is_available())
{ {
@ -166,7 +171,7 @@ class manager
$notification_type_id = false; $notification_type_id = false;
} }
/** @var method_interface $method */ /** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->mark_notifications($notification_type_id, $item_id, $user_id, $time, $mark_read); $method->mark_notifications($notification_type_id, $item_id, $user_id, $time, $mark_read);
@ -208,6 +213,7 @@ class manager
$notification_type_id = $this->get_notification_type_id($notification_type_name); $notification_type_id = $this->get_notification_type_id($notification_type_name);
} }
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time, $mark_read); $method->mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time, $mark_read);
@ -263,8 +269,6 @@ class manager
return $notified_users; return $notified_users;
} }
$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
// find out which users want to receive this type of notification // find out which users want to receive this type of notification
$notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options); $notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options);
@ -317,7 +321,7 @@ class manager
$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data); $item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
$user_ids = array(); $user_ids = array();
$notification_objects = $notification_methods = array(); $notification_methods = array();
// Never send notifications to the anonymous user! // Never send notifications to the anonymous user!
unset($notify_users[ANONYMOUS]); unset($notify_users[ANONYMOUS]);
@ -325,6 +329,7 @@ class manager
// Make sure not to send new notifications to users who've already been notified about this item // Make sure not to send new notifications to users who've already been notified about this item
// This may happen when an item was added, but now new users are able to see the item // This may happen when an item was added, but now new users are able to see the item
// We remove each user which was already notified by at least one method. // We remove each user which was already notified by at least one method.
/** @var method\method_interface $method */
foreach ($this->get_subscription_methods_instances() as $method) foreach ($this->get_subscription_methods_instances() as $method)
{ {
$notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id)); $notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id));
@ -415,6 +420,7 @@ class manager
$options['item_id'] = $notification->get_item_id($data); $options['item_id'] = $notification->get_item_id($data);
} }
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->update_notification($notification, $data, $options); $method->update_notification($notification, $data, $options);
@ -443,6 +449,7 @@ class manager
$notification_type_id = $this->get_notification_type_id($notification_type_name); $notification_type_id = $this->get_notification_type_id($notification_type_name);
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->delete_notifications($notification_type_id, $item_id, $parent_id, $user_id); $method->delete_notifications($notification_type_id, $item_id, $parent_id, $user_id);
@ -462,6 +469,7 @@ class manager
foreach ($this->notification_types as $type_name => $data) foreach ($this->notification_types as $type_name => $data)
{ {
/** @var type\base $type */
$type = $this->get_item_type_class($type_name); $type = $this->get_item_type_class($type_name);
if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available()) if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())
@ -497,6 +505,7 @@ class manager
{ {
$subscription_methods = array(); $subscription_methods = array();
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method_name => $method) foreach ($this->get_available_subscription_methods() as $method_name => $method)
{ {
$subscription_methods[$method_name] = array( $subscription_methods[$method_name] = array(
@ -539,6 +548,7 @@ class manager
{ {
$subscription_methods = array(); $subscription_methods = array();
/** @var method\method_interface $method */
foreach ($this->get_subscription_methods_instances() as $method_name => $method) foreach ($this->get_subscription_methods_instances() as $method_name => $method)
{ {
if ($method->is_available()) if ($method->is_available())
@ -768,6 +778,7 @@ class manager
{ {
$notification_type_id = $this->get_notification_type_id($notification_type_name); $notification_type_id = $this->get_notification_type_id($notification_type_name);
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->purge_notifications($notification_type_id); $method->purge_notifications($notification_type_id);
@ -805,6 +816,7 @@ class manager
*/ */
public function prune_notifications($timestamp, $only_read = true) public function prune_notifications($timestamp, $only_read = true)
{ {
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$method->prune_notifications($timestamp, $only_read); $method->prune_notifications($timestamp, $only_read);
@ -834,7 +846,9 @@ class manager
/** /**
* Helper to get the notifications item type class and set it up * Helper to get the notifications item type class and set it up
* *
* @return type\type_interface * @param string $notification_type_name
* @param array $data
* @return \phpbb\notification\type\type_interface
*/ */
public function get_item_type_class($notification_type_name, $data = array()) public function get_item_type_class($notification_type_name, $data = array())
{ {
@ -848,7 +862,8 @@ class manager
/** /**
* Helper to get the notifications method class and set it up * Helper to get the notifications method class and set it up
* *
* @return method\method_interface * @param string $method_name
* @return \phpbb\notification\method\method_interface
*/ */
public function get_method_class($method_name) public function get_method_class($method_name)
{ {
@ -858,7 +873,8 @@ class manager
/** /**
* Helper to load objects (notification types/methods) * Helper to load objects (notification types/methods)
* *
* @return method\method_interface|type\type_interface * @param string $object_name
* @return \phpbb\notification\method\method_interface|\phpbb\notification\type\type_interface
*/ */
protected function load_object($object_name) protected function load_object($object_name)
{ {
@ -950,6 +966,8 @@ class manager
$notification_type_id = $this->get_notification_type_id($notification_type_name); $notification_type_id = $this->get_notification_type_id($notification_type_name);
$notified_users = array(); $notified_users = array();
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method) foreach ($this->get_available_subscription_methods() as $method)
{ {
$notified_users = $notified_users + $method->get_notified_users($notification_type_id, $options); $notified_users = $notified_users + $method->get_notified_users($notification_type_id, $options);

View file

@ -266,6 +266,7 @@ class board extends \phpbb\notification\method\base
{ {
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table); $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);
/** @var \phpbb\notification\type\type_interface $notification */
foreach ($this->queue as $notification) foreach ($this->queue as $notification)
{ {
$data = $notification->get_insert_array(); $data = $notification->get_insert_array();

View file

@ -82,6 +82,7 @@ abstract class messenger_base extends \phpbb\notification\method\base
$messenger = new \messenger(); $messenger = new \messenger();
// Time to go through the queue and send emails // Time to go through the queue and send emails
/** @var \phpbb\notification\type\type_interface $notification */
foreach ($this->queue as $notification) foreach ($this->queue as $notification)
{ {
if ($notification->get_email_template() === false) if ($notification->get_email_template() === false)

View file

@ -130,7 +130,7 @@ class admin_activate_user extends \phpbb\notification\type\base
{ {
$username = $this->user_loader->get_username($this->item_id, 'no_profile'); $username = $this->user_loader->get_username($this->item_id, 'no_profile');
return $this->user->lang($this->language_key, $username); return $this->language->lang($this->language_key, $username);
} }
/** /**

View file

@ -24,6 +24,9 @@ abstract class base implements \phpbb\notification\type\type_interface
/** @var \phpbb\db\driver\driver_interface */ /** @var \phpbb\db\driver\driver_interface */
protected $db; protected $db;
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\user */ /** @var \phpbb\user */
protected $user; protected $user;
@ -56,7 +59,7 @@ abstract class base implements \phpbb\notification\type\type_interface
protected $notification_type_id; protected $notification_type_id;
/** /**
* Indentification data * Identification data
* notification_type_id - ID of the item type (auto generated, from notification types table) * notification_type_id - ID of the item type (auto generated, from notification types table)
* item_id - ID of the item (e.g. post_id, msg_id) * item_id - ID of the item (e.g. post_id, msg_id)
* item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc)
@ -74,16 +77,17 @@ abstract class base implements \phpbb\notification\type\type_interface
* Notification Type Base Constructor * Notification Type Base Constructor
* *
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\language\language $language
* @param \phpbb\user $user * @param \phpbb\user $user
* @param \phpbb\auth\auth $auth * @param \phpbb\auth\auth $auth
* @param string $phpbb_root_path * @param string $phpbb_root_path
* @param string $php_ext * @param string $php_ext
* @param string $user_notifications_table * @param string $user_notifications_table
* @return \phpbb\notification\type\base
*/ */
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\auth\auth $auth, $phpbb_root_path, $php_ext, $user_notifications_table) public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\user $user, \phpbb\auth\auth $auth, $phpbb_root_path, $php_ext, $user_notifications_table)
{ {
$this->db = $db; $this->db = $db;
$this->language = $language;
$this->user = $user; $this->user = $user;
$this->auth = $auth; $this->auth = $auth;
@ -304,6 +308,7 @@ abstract class base implements \phpbb\notification\type\type_interface
* URL to unsubscribe to this notification (fall back) * URL to unsubscribe to this notification (fall back)
* *
* @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item
* @return false
*/ */
public function get_unsubscribe_url($method = false) public function get_unsubscribe_url($method = false)
{ {
@ -372,6 +377,9 @@ abstract class base implements \phpbb\notification\type\type_interface
/** /**
* Load the special items (fall back) * Load the special items (fall back)
*
* @param array $data
* @param array $notifications
*/ */
public function load_special($data, $notifications) public function load_special($data, $notifications)
{ {
@ -391,6 +399,8 @@ abstract class base implements \phpbb\notification\type\type_interface
/** /**
* Pre create insert array function (fall back) * Pre create insert array function (fall back)
* *
* @param array $type_data
* @param array $notify_users
* @return array * @return array
*/ */
public function pre_create_insert_array($type_data, $notify_users) public function pre_create_insert_array($type_data, $notify_users)
@ -405,9 +415,9 @@ abstract class base implements \phpbb\notification\type\type_interface
/** /**
* Find the users who want to receive notifications (helper) * Find the users who want to receive notifications (helper)
* *
* @param array $user_ids User IDs to check if they want to receive notifications * @param array|bool $user_ids User IDs to check if they want to receive notifications
* (Bool False to check all users besides anonymous and bots (USER_IGNORE)) * (Bool False to check all users besides anonymous and bots (USER_IGNORE))
* * @param array $options
* @return array * @return array
*/ */
protected function check_user_notification_options($user_ids = false, $options = array()) protected function check_user_notification_options($user_ids = false, $options = array())
@ -505,6 +515,8 @@ abstract class base implements \phpbb\notification\type\type_interface
{ {
$this->notification_manager->mark_notifications($this->get_type(), (int) $this->item_id, (int) $this->user_id, false, $this->notification_read); $this->notification_manager->mark_notifications($this->get_type(), (int) $this->item_id, (int) $this->user_id, false, $this->notification_read);
} }
return null;
} }
/** /**

View file

@ -73,7 +73,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post
*/ */
public function get_title() public function get_title()
{ {
return $this->user->lang($this->language_key); return $this->language->lang($this->language_key);
} }
/** /**
@ -83,7 +83,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title')) censor_text($this->get_data('topic_title'))
); );
@ -96,7 +96,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post
*/ */
public function get_reason() public function get_reason()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('disapprove_reason') $this->get_data('disapprove_reason')
); );

View file

@ -73,7 +73,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
*/ */
public function get_title() public function get_title()
{ {
return $this->user->lang($this->language_key); return $this->language->lang($this->language_key);
} }
/** /**
@ -83,7 +83,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title')) censor_text($this->get_data('topic_title'))
); );
@ -96,7 +96,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic
*/ */
public function get_reason() public function get_reason()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('disapprove_reason') $this->get_data('disapprove_reason')
); );

View file

@ -114,7 +114,7 @@ class group_request extends \phpbb\notification\type\base
{ {
$username = $this->user_loader->get_username($this->item_id, 'no_profile'); $username = $this->user_loader->get_username($this->item_id, 'no_profile');
return $this->user->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); return $this->language->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name'));
} }
/** /**

View file

@ -69,7 +69,7 @@ class group_request_approved extends \phpbb\notification\type\base
*/ */
public function get_title() public function get_title()
{ {
return $this->user->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name')); return $this->language->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name'));
} }
/** /**

View file

@ -128,7 +128,7 @@ class pm extends \phpbb\notification\type\base
{ {
$username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile');
return $this->user->lang('NOTIFICATION_PM', $username); return $this->language->lang('NOTIFICATION_PM', $username);
} }
/** /**
@ -138,7 +138,7 @@ class pm extends \phpbb\notification\type\base
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
$this->get_data('message_subject') $this->get_data('message_subject')
); );

View file

@ -83,6 +83,7 @@ class post extends \phpbb\notification\type\base
* Get the id of the item * Get the id of the item
* *
* @param array $post The data from the post * @param array $post The data from the post
* @return int The post id
*/ */
static public function get_item_id($post) static public function get_item_id($post)
{ {
@ -93,6 +94,7 @@ class post extends \phpbb\notification\type\base
* Get the id of the parent * Get the id of the parent
* *
* @param array $post The data from the post * @param array $post The data from the post
* @return int The topic id
*/ */
static public function get_item_parent_id($post) static public function get_item_parent_id($post)
{ {
@ -218,14 +220,14 @@ class post extends \phpbb\notification\type\base
if ($trimmed_responders_cnt > 20) if ($trimmed_responders_cnt > 20)
{ {
$usernames[] = $this->user->lang('NOTIFICATION_MANY_OTHERS'); $usernames[] = $this->language->lang('NOTIFICATION_MANY_OTHERS');
} }
else if ($trimmed_responders_cnt) else if ($trimmed_responders_cnt)
{ {
$usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); $usernames[] = $this->language->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
} }
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
phpbb_generate_string_list($usernames, $this->user), phpbb_generate_string_list($usernames, $this->user),
$responders_cnt $responders_cnt
@ -239,7 +241,7 @@ class post extends \phpbb\notification\type\base
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title')) censor_text($this->get_data('topic_title'))
); );
@ -407,6 +409,7 @@ class post extends \phpbb\notification\type\base
* Add responders to the notification * Add responders to the notification
* *
* @param mixed $post * @param mixed $post
* @return array Array of responder data
*/ */
public function add_responders($post) public function add_responders($post)
{ {

View file

@ -106,6 +106,7 @@ class quote extends \phpbb\notification\type\post
* Update a notification * Update a notification
* *
* @param array $post Data specific for this type that will be updated * @param array $post Data specific for this type that will be updated
* @return true
*/ */
public function update_notifications($post) public function update_notifications($post)
{ {

View file

@ -70,6 +70,7 @@ class report_pm extends \phpbb\notification\type\pm
* Get the id of the parent * Get the id of the parent
* *
* @param array $pm The data from the pm * @param array $pm The data from the pm
* @return int The report id
*/ */
static public function get_item_parent_id($pm) static public function get_item_parent_id($pm)
{ {
@ -168,11 +169,11 @@ class report_pm extends \phpbb\notification\type\pm
*/ */
public function get_title() public function get_title()
{ {
$this->user->add_lang('mcp'); $this->language->add_lang('mcp');
$username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
$username $username
); );
@ -185,7 +186,7 @@ class report_pm extends \phpbb\notification\type\pm
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('message_subject')) censor_text($this->get_data('message_subject'))
); );
@ -200,21 +201,21 @@ class report_pm extends \phpbb\notification\type\pm
{ {
if ($this->get_data('report_text')) if ($this->get_data('report_text'))
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('report_text') $this->get_data('report_text')
); );
} }
if (isset($this->user->lang[$this->get_data('reason_title')])) if ($this->language->is_set($this->get_data('reason_title')))
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->user->lang[$this->get_data('reason_title')] $this->language->lang($this->get_data('reason_title'))
); );
} }
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('reason_description') $this->get_data('reason_description')
); );

View file

@ -106,7 +106,7 @@ class report_pm_closed extends \phpbb\notification\type\pm
{ {
$username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
$username $username
); );
@ -119,7 +119,7 @@ class report_pm_closed extends \phpbb\notification\type\pm
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('message_subject')) censor_text($this->get_data('message_subject'))
); );

View file

@ -139,11 +139,11 @@ class report_post extends \phpbb\notification\type\post_in_queue
*/ */
public function get_title() public function get_title()
{ {
$this->user->add_lang('mcp'); $this->language->add_lang('mcp');
$username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
$username $username
); );
@ -156,7 +156,7 @@ class report_post extends \phpbb\notification\type\post_in_queue
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('post_subject')) censor_text($this->get_data('post_subject'))
); );
@ -171,21 +171,21 @@ class report_post extends \phpbb\notification\type\post_in_queue
{ {
if ($this->get_data('report_text')) if ($this->get_data('report_text'))
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('report_text') $this->get_data('report_text')
); );
} }
if (isset($this->user->lang[$this->get_data('reason_title')])) if ($this->language->is_set($this->get_data('reason_title')))
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->user->lang[$this->get_data('reason_title')] $this->language->lang($this->get_data('reason_title'))
); );
} }
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REASON', 'NOTIFICATION_REASON',
$this->get_data('reason_description') $this->get_data('reason_description')
); );

View file

@ -113,7 +113,7 @@ class report_post_closed extends \phpbb\notification\type\post
{ {
$username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
$username $username
); );
@ -126,7 +126,7 @@ class report_post_closed extends \phpbb\notification\type\post
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('post_subject')) censor_text($this->get_data('post_subject'))
); );

View file

@ -83,6 +83,7 @@ class topic extends \phpbb\notification\type\base
* Get the id of the item * Get the id of the item
* *
* @param array $post The data from the post * @param array $post The data from the post
* @return int The topic id
*/ */
static public function get_item_id($post) static public function get_item_id($post)
{ {
@ -93,6 +94,7 @@ class topic extends \phpbb\notification\type\base
* Get the id of the parent * Get the id of the parent
* *
* @param array $post The data from the post * @param array $post The data from the post
* @return int The forum id
*/ */
static public function get_item_parent_id($post) static public function get_item_parent_id($post)
{ {
@ -154,7 +156,7 @@ class topic extends \phpbb\notification\type\base
$username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile');
} }
return $this->user->lang( return $this->language->lang(
$this->language_key, $this->language_key,
$username $username
); );
@ -167,7 +169,7 @@ class topic extends \phpbb\notification\type\base
*/ */
public function get_reference() public function get_reference()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_REFERENCE', 'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title')) censor_text($this->get_data('topic_title'))
); );
@ -180,7 +182,7 @@ class topic extends \phpbb\notification\type\base
*/ */
public function get_forum() public function get_forum()
{ {
return $this->user->lang( return $this->language->lang(
'NOTIFICATION_FORUM', 'NOTIFICATION_FORUM',
$this->get_data('forum_name') $this->get_data('forum_name')
); );

View file

@ -21,11 +21,12 @@ if (!defined('IN_PHPBB'))
class phpbb_mock_notification_type_post extends \phpbb\notification\type\post class phpbb_mock_notification_type_post extends \phpbb\notification\type\post
{ {
public function __construct($user_loader, $db, $cache, $user, $auth, $config, $phpbb_root_path, $php_ext, $notification_types_table, $user_notifications_table) public function __construct($user_loader, $db, $cache, $language, $user, $auth, $config, $phpbb_root_path, $php_ext, $notification_types_table, $user_notifications_table)
{ {
$this->user_loader = $user_loader; $this->user_loader = $user_loader;
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;
$this->language = $language;
$this->user = $user; $this->user = $user;
$this->auth = $auth; $this->auth = $auth;
$this->config = $config; $this->config = $config;

View file

@ -90,6 +90,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$loader->load('services_notification.yml'); $loader->load('services_notification.yml');
$phpbb_container->set('user_loader', $this->user_loader); $phpbb_container->set('user_loader', $this->user_loader);
$phpbb_container->set('user', $user); $phpbb_container->set('user', $user);
$phpbb_container->set('language', $lang);
$phpbb_container->set('config', $this->config); $phpbb_container->set('config', $this->config);
$phpbb_container->set('dbal.conn', $this->db); $phpbb_container->set('dbal.conn', $this->db);
$phpbb_container->set('auth', $auth); $phpbb_container->set('auth', $auth);
@ -111,6 +112,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case
$this->phpbb_dispatcher, $this->phpbb_dispatcher,
$this->db, $this->db,
$this->cache, $this->cache,
$lang,
$this->user, $this->user,
'phpbb_notification_types', 'phpbb_notification_types',
'phpbb_user_notifications' 'phpbb_user_notifications'

View file

@ -17,6 +17,9 @@ services:
dbal.conn: dbal.conn:
synthetic: true synthetic: true
language:
synthetic: true
auth: auth:
synthetic: true synthetic: true

View file

@ -54,7 +54,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
{ {
parent::setUp(); parent::setUp();
global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path, $user_loader; global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $lang, $user, $request, $phpEx, $phpbb_root_path, $user_loader;
// Database // Database
$this->db = $this->new_dbal(); $this->db = $this->new_dbal();
@ -91,9 +91,12 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
// Event dispatcher // Event dispatcher
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
// Language
$lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
// User // User
$user = $this->getMock('\phpbb\user', array(), array( $user = $this->getMock('\phpbb\user', array(), array(
new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), $lang,
'\phpbb\datetime' '\phpbb\datetime'
)); ));
$user->ip = ''; $user->ip = '';
@ -117,6 +120,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
$loader->load('services_notification.yml'); $loader->load('services_notification.yml');
$phpbb_container->set('user_loader', $user_loader); $phpbb_container->set('user_loader', $user_loader);
$phpbb_container->set('user', $user); $phpbb_container->set('user', $user);
$phpbb_container->set('language', $lang);
$phpbb_container->set('config', $config); $phpbb_container->set('config', $config);
$phpbb_container->set('dbal.conn', $db); $phpbb_container->set('dbal.conn', $db);
$phpbb_container->set('auth', $auth); $phpbb_container->set('auth', $auth);
@ -146,7 +150,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
// Notification Manager // Notification Manager
$phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array, $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array,
$phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $user, $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $lang, $user,
NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE); NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE);
$phpbb_container->set('notification_manager', $phpbb_notifications); $phpbb_container->set('notification_manager', $phpbb_notifications);
} }

View file

@ -55,13 +55,13 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case
$lang = new \phpbb\language\language($lang_loader); $lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime'); $user = new \phpbb\user($lang, '\phpbb\datetime');
$user->data = array('user_lang' => 'en'); $user->data = array('user_lang' => 'en');
$user->add_lang('common'); $lang->add_lang('common');
$user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); $user_loader = new phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE);
$user_loader->load_users(array(2, 3, 4, 5, 6)); $user_loader->load_users(array(2, 3, 4, 5, 6));
$this->notification = new phpbb_mock_notification_type_post( $this->notification = new phpbb_mock_notification_type_post(
$user_loader, null, null, $user, null, null, $phpbb_root_path, $phpEx, null, null $user_loader, null, null, $lang, $user, null, null, $phpbb_root_path, $phpEx, null, null
); );
} }