1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/17135] Refactor messenger code to services [ci skip]

PHPBB3-17135
This commit is contained in:
rxu
2023-06-06 12:54:15 +07:00
parent df5b7fd66e
commit 5be1f5d5c9
20 changed files with 296 additions and 236 deletions

View File

@@ -14,6 +14,11 @@
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
use phpbb\user;
use phpbb\user_loader;
use phpbb\config\config;
use phpbb\db\driver\driver_interface;
use phpbb\di\service_collection;
/**
* Email notification method class
@@ -34,20 +39,33 @@ class email extends \phpbb\notification\method\messenger_base
/** @var string Notification emails table */
protected $notification_emails_table;
/** @var service_collection */
protected $messenger;
/**
* Notification Method email Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param user_loader $user_loader
* @param user $user
* @param config $config
* @param driver_interface $db
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_emails_table
* @param service_collection $messenger
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $notification_emails_table)
public function __construct(
user_loader $user_loader,
user $user,
config $config,
driver_interface $db,
$phpbb_root_path,
$php_ext,
$notification_emails_table,
service_collection $messenger
)
{
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
parent::__construct($messenger, $user_loader, $phpbb_root_path, $php_ext);
$this->user = $user;
$this->config = $config;

View File

@@ -14,6 +14,10 @@
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
use phpbb\user;
use phpbb\user_loader;
use phpbb\config\config;
use phpbb\di\service_collection;
/**
* Jabber notification method class
@@ -28,18 +32,22 @@ class jabber extends \phpbb\notification\method\messenger_base
/** @var \phpbb\config\config */
protected $config;
/** @var service_collection */
protected $messenger;
/**
* Notification Method jabber Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param user_loader $user_loader
* @param user $user
* @param config $config
* @param string $phpbb_root_path
* @param string $php_ext
* @param service_collection $messenger
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)
public function __construct(user_loader $user_loader, user $user, config $config, $phpbb_root_path, $php_ext, service_collection $messenger)
{
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
parent::__construct($messenger, $user_loader, $phpbb_root_path, $php_ext);
$this->user = $user;
$this->config = $config;

View File

@@ -14,6 +14,8 @@
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
use phpbb\di\service_collection;
use phpbb\user_loader;
/**
* Abstract notification method handling email and jabber notifications
@@ -21,7 +23,10 @@ use phpbb\notification\type\type_interface;
*/
abstract class messenger_base extends \phpbb\notification\method\base
{
/** @var \phpbb\user_loader */
/** @var service_collection */
protected $messenger;
/** @var user_loader */
protected $user_loader;
/** @var string */
@@ -33,12 +38,14 @@ abstract class messenger_base extends \phpbb\notification\method\base
/**
* Notification Method Board Constructor
*
* @param \phpbb\user_loader $user_loader
* @param service_collection $messenger
* @param user_loader $user_loader
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(\phpbb\user_loader $user_loader, $phpbb_root_path, $php_ext)
public function __construct(service_collection $messenger, user_loader $user_loader, $phpbb_root_path, $php_ext)
{
$this->messenger = $messenger;
$this->user_loader = $user_loader;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@@ -73,7 +80,7 @@ abstract class messenger_base extends \phpbb\notification\method\base
}
// Load all users we want to notify (we need their email address)
$user_ids = array();
$user_ids = [];
foreach ($this->queue as $notification)
{
$user_ids[] = $notification->user_id;
@@ -89,13 +96,6 @@ abstract class messenger_base extends \phpbb\notification\method\base
// Load all the users we need
$this->user_loader->load_users(array_diff($user_ids, $banned_users), array(USER_IGNORE));
// Load the messenger
if (!class_exists('messenger'))
{
include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$messenger = new \messenger();
// Time to go through the queue and send emails
/** @var type_interface $notification */
foreach ($this->queue as $notification)
@@ -112,22 +112,28 @@ abstract class messenger_base extends \phpbb\notification\method\base
continue;
}
$messenger->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix);
$messenger_collection_iterator = $this->messenger->getIterator();
while ($messenger_collection_iterator->valid())
{
$messenger_method = $messenger_collection_iterator->current();
if ($messenger_method->get_id() == $notify_method || $notify_method == NOTIFY_BOTH)
{
$messenger_method->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix);
$messenger_method->set_addresses($user);
$messenger_method->assign_vars(array_merge([
'USERNAME' => $user['username'],
'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications&mode=notification_options',
], $notification->get_email_template_variables()));
$messenger->set_addresses($user);
$messenger_method->send();
$messenger->assign_vars(array_merge(array(
'USERNAME' => $user['username'],
'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications&mode=notification_options',
), $notification->get_email_template_variables()));
$messenger->send($notify_method);
// Save the queue in the messenger method class (has to be called or these messages could be lost)
$messenger_method->save_queue();
}
$messenger_collection_iterator->next();
}
}
// Save the queue in the messenger class (has to be called or these emails could be lost?)
$messenger->save_queue();
// We're done, empty the queue
$this->empty_queue();
}