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

[ticket/17135] Use email method instead of service collection where appropriate

PHPBB-17135
This commit is contained in:
rxu
2024-06-23 14:29:17 +07:00
parent 499464e1d3
commit 3fddff240c
9 changed files with 124 additions and 57 deletions

View File

@@ -327,7 +327,7 @@ services:
- '@config'
- '@language'
- '@log'
- '@messenger.method_collection'
- '@messenger.method.email'
- '@notification_manager'
- '@user_loader'
- '%core.root_path%'
@@ -342,7 +342,7 @@ services:
- '@dbal.conn'
- '@config'
- '@language'
- '@messenger.method_collection'
- '@messenger.method.email'
- '@passwords.manager'
- '%core.root_path%'
- '%core.php_ext%'

View File

@@ -5,6 +5,7 @@ imports:
- { resource: ../../default/container/services_filesystem.yml }
- { resource: ../../default/container/services_http.yml }
- { resource: ../../default/container/services_language.yml }
- { resource: ../../default/container/services_messenger.yml }
- { resource: ../../default/container/services_php.yml }
- { resource: ../../default/container/services_routing.yml }
- { resource: ../../default/container/services_twig.yml }

View File

@@ -17,10 +17,10 @@ use phpbb\config\config;
use phpbb\console\command\command;
use phpbb\language\language;
use phpbb\log\log_interface;
use phpbb\messenger\method\email;
use phpbb\notification\manager;
use phpbb\user;
use phpbb\user_loader;
use phpbb\di\service_collection;
use Symfony\Component\Console\Command\Command as symfony_command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -33,15 +33,15 @@ class activate extends command
/** @var config */
protected $config;
/** @var email */
protected $email_method;
/** @var language */
protected $language;
/** @var log_interface */
protected $log;
/** @var service_collection */
protected $messenger;
/** @var manager */
protected $notifications;
@@ -69,18 +69,18 @@ class activate extends command
* @param config $config
* @param language $language
* @param log_interface $log
* @param service_collection $messenger
* @param email $email_method
* @param manager $notifications
* @param user_loader $user_loader
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(user $user, config $config, language $language, log_interface $log, service_collection $messenger, manager $notifications, user_loader $user_loader, $phpbb_root_path, $php_ext)
public function __construct(user $user, config $config, language $language, log_interface $log, email $email_method, manager $notifications, user_loader $user_loader, $phpbb_root_path, $php_ext)
{
$this->config = $config;
$this->email_method = $email_method;
$this->language = $language;
$this->log = $log;
$this->messenger = $messenger;
$this->notifications = $notifications;
$this->user_loader = $user_loader;
$this->phpbb_root_path = $phpbb_root_path;
@@ -200,15 +200,14 @@ class activate extends command
if ($input->getOption('send-email'))
{
$email_method = $this->messenger->offsetGet('messenger.method.email');
$email_method->set_use_queue(false);
$email_method->template('admin_welcome_activated', $user_row['user_lang']);
$email_method->set_addresses($user_row);
$email_method->anti_abuse_headers($this->config, $this->user);
$email_method->assign_vars([
$this->email_method->set_use_queue(false);
$this->email_method->template('admin_welcome_activated', $user_row['user_lang']);
$this->email_method->set_addresses($user_row);
$this->email_method->anti_abuse_headers($this->config, $this->user);
$this->email_method->assign_vars([
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
]);
$email_method->send();
$this->email_method->send();
}
}
}

View File

@@ -18,9 +18,9 @@ use phpbb\console\command\command;
use phpbb\db\driver\driver_interface;
use phpbb\exception\runtime_exception;
use phpbb\language\language;
use phpbb\messenger\method\email;
use phpbb\passwords\manager;
use phpbb\user;
use phpbb\di\service_collection;
use Symfony\Component\Console\Command\Command as symfony_command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
@@ -40,12 +40,12 @@ class add extends command
/** @var config */
protected $config;
/** @var email */
protected $email_method;
/** @var language */
protected $language;
/** @var service_collection */
protected $messenger;
/** @var manager */
protected $password_manager;
@@ -75,12 +75,12 @@ class add extends command
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(user $user, driver_interface $db, config $config, language $language, service_collection $messenger, manager $password_manager, $phpbb_root_path, $php_ext)
public function __construct(user $user, driver_interface $db, config $config, language $language, email $email_method, manager $password_manager, $phpbb_root_path, $php_ext)
{
$this->db = $db;
$this->config = $config;
$this->db = $db;
$this->email_method = $email_method;
$this->language = $language;
$this->messenger = $messenger;
$this->password_manager = $password_manager;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@@ -313,18 +313,17 @@ class add extends command
$user_actkey = $this->get_activation_key($user_id);
$email_method = $this->messenger->offsetGet('messenger.method.email');
$email_method->set_use_queue(false);
$email_method->template($email_template, $this->user->lang_name);
$email_method->to($this->data['email'], $this->data['username']);
$email_method->anti_abuse_headers($this->config, $this->user);
$email_method->assign_vars([
$this->email_method->set_use_queue(false);
$this->email_method->template($email_template, $this->user->lang_name);
$this->email_method->to($this->data['email'], $this->data['username']);
$this->email_method->anti_abuse_headers($this->config, $this->user);
$this->email_method->assign_vars([
'WELCOME_MSG' => html_entity_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename']), ENT_COMPAT),
'USERNAME' => html_entity_decode($this->data['username'], ENT_COMPAT),
'PASSWORD' => html_entity_decode($this->data['new_password'], ENT_COMPAT),
'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey",
]);
$email_method->send();
$this->email_method->send();
}
/**

View File

@@ -20,7 +20,7 @@ use phpbb\auth\auth;
use phpbb\log\log_interface;
use phpbb\user;
use phpbb\install\helper\container_factory;
use phpbb\di\service_collection;
use phpbb\messenger\method\email;
/**
* Logs installation and sends an email to the admin
@@ -39,6 +39,9 @@ class notify_user extends \phpbb\install\task_base
/** @var db */
protected $config;
/** @var email */
protected $email_method;
/** @var log_interface */
protected $log;
@@ -48,9 +51,6 @@ class notify_user extends \phpbb\install\task_base
/** @var user */
protected $user;
/** @var service_collection */
protected $messenger;
/**
* Constructor
*
@@ -67,7 +67,7 @@ class notify_user extends \phpbb\install\task_base
$this->auth = $container->get('auth');
$this->log = $container->get('log');
$this->user = $container->get('user');
$this->messenger = $container->get('messenger.method_collection');
$this->email_method = $container->get('messenger.method.email');
$this->phpbb_root_path = $phpbb_root_path;
// We need to reload config for cases when it doesn't have all values
@@ -97,16 +97,15 @@ class notify_user extends \phpbb\install\task_base
if ($this->config['email_enable'])
{
$email_method = $this->messenger->offsetGet('messenger.method.email');
$email_method->set_use_queue(false);
$email_method->template('installed', $this->install_config->get('user_language', 'en'));
$email_method->to($this->config['board_email'], $this->install_config->get('admin_name'));
$email_method->anti_abuse_headers($this->config, $this->user);
$email_method->assign_vars([
$this->email_method->set_use_queue(false);
$this->email_method->template('installed', $this->install_config->get('user_language', 'en'));
$this->email_method->to($this->config['board_email'], $this->install_config->get('admin_name'));
$this->email_method->anti_abuse_headers($this->config, $this->user);
$this->email_method->assign_vars([
'USERNAME' => html_entity_decode($this->install_config->get('admin_name'), ENT_COMPAT),
'PASSWORD' => html_entity_decode($this->install_config->get('admin_passwd'), ENT_COMPAT),
]);
$email_method->send();
$this->email_method->send();
}
// Login admin

View File

@@ -17,13 +17,7 @@ use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email as symfony_email;
use Symfony\Component\Mime\Header\DateHeader;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Header\IdentificationHeader;
use Symfony\Component\Mime\Header\MailboxHeader;
use Symfony\Component\Mime\Header\MailboxListHeader;
use Symfony\Component\Mime\Header\PathHeader;
use Symfony\Component\Mime\Header\UnstructuredHeader;
/**
* Messenger class
@@ -308,7 +302,7 @@ class email extends base
// Add additional headers
$phpbb_headers = array_merge($phpbb_headers, $this->additional_headers);
foreach ($phpbb_headers as $header => $value)
{
$this->headers->addHeader($header, $value);