mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-16 13:48:58 +01:00
[ticket/17135] Refactor messenger code to services [ci skip]
PHPBB3-17135
This commit is contained in:
parent
5873c72ca5
commit
f95816cbe3
@ -33,7 +33,6 @@ require_once $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_content.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_mcp.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_module.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
|
||||
require_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
|
||||
|
@ -720,17 +720,17 @@ class acp_board
|
||||
{
|
||||
if ($config['email_enable'])
|
||||
{
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
$messenger = new messenger(false);
|
||||
$messenger->template('test');
|
||||
$messenger->set_addresses($user->data);
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
$messenger->assign_vars(array(
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$email = $messenger->offsetGet('messenger.method.email');
|
||||
$email->set_use_queue(false);
|
||||
$email->template('test');
|
||||
$email->set_addresses($user->data);
|
||||
$email->anti_abuse_headers($config, $user);
|
||||
$email->assign_vars([
|
||||
'USERNAME' => html_entity_decode($user->data['username'], ENT_COMPAT),
|
||||
'MESSAGE' => html_entity_decode($request->variable('send_test_email_text', '', true), ENT_COMPAT),
|
||||
));
|
||||
$messenger->send(NOTIFY_EMAIL);
|
||||
]);
|
||||
$email->send();
|
||||
|
||||
trigger_error($user->lang('TEST_EMAIL_SENT') . adm_back_link($this->u_action));
|
||||
}
|
||||
|
@ -182,25 +182,13 @@ class acp_email
|
||||
}
|
||||
}
|
||||
|
||||
// Send the messages
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
if (!function_exists('get_group_name'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
||||
}
|
||||
$messenger = new messenger($use_queue);
|
||||
|
||||
$errored = false;
|
||||
|
||||
$email_template = 'admin_send_email';
|
||||
$template_data = array(
|
||||
$template_data = [
|
||||
'CONTACT_EMAIL' => phpbb_get_board_contact($config, $phpEx),
|
||||
'MESSAGE' => html_entity_decode($message, ENT_COMPAT),
|
||||
);
|
||||
];
|
||||
$generate_log_entry = true;
|
||||
|
||||
/**
|
||||
@ -229,31 +217,50 @@ class acp_email
|
||||
);
|
||||
extract($phpbb_dispatcher->trigger_event('core.acp_email_send_before', compact($vars)));
|
||||
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$messenger_collection_iterator = $messenger->getIterator();
|
||||
for ($i = 0, $size = count($email_list); $i < $size; $i++)
|
||||
{
|
||||
$used_lang = $email_list[$i][0]['lang'];
|
||||
$used_method = $email_list[$i][0]['method'];
|
||||
|
||||
while ($messenger_collection_iterator->valid())
|
||||
{
|
||||
$messenger_method = $messenger_collection_iterator->current();
|
||||
if ($messenger_method->get_id() == $used_method || $used_method == NOTIFY_BOTH)
|
||||
{
|
||||
$messenger_method->set_use_queue($use_queue);
|
||||
$messenger_method->template($email_template, $used_lang);
|
||||
$messenger_method->subject(html_entity_decode($subject, ENT_COMPAT));
|
||||
$messenger_method->assign_vars($template_data);
|
||||
|
||||
if ($messenger_method->get_id() == NOTIFY_EMAIL)
|
||||
{
|
||||
for ($j = 0, $list_size = count($email_list[$i]); $j < $list_size; $j++)
|
||||
{
|
||||
$email_row = $email_list[$i][$j];
|
||||
|
||||
$messenger->{((count($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
|
||||
$messenger->im($email_row['jabber'], $email_row['name']);
|
||||
$messenger_method->{((count($email_list[$i]) == 1) ? 'to' : 'bcc')}($email_row['email'], $email_row['name']);
|
||||
}
|
||||
|
||||
$messenger->template($email_template, $used_lang);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->subject(html_entity_decode($subject, ENT_COMPAT));
|
||||
$messenger->set_mail_priority($priority);
|
||||
|
||||
$messenger->assign_vars($template_data);
|
||||
|
||||
if (!($messenger->send($used_method)))
|
||||
$messenger_method->anti_abuse_headers($config, $user);
|
||||
$messenger_method->set_mail_priority($priority);
|
||||
}
|
||||
else if ($messenger_method->get_id() == NOTIFY_JABBER)
|
||||
{
|
||||
$errored = true;
|
||||
for ($j = 0, $list_size = count($email_list[$i]); $j < $list_size; $j++)
|
||||
{
|
||||
$email_row = $email_list[$i][$j];
|
||||
$messenger_method->to($email_row['jabber'], $email_row['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$errored = !$messenger_method->send();
|
||||
if ($use_queue)
|
||||
{
|
||||
$messenger_method->save_queue();
|
||||
}
|
||||
}
|
||||
$messenger_collection_iterator->next();
|
||||
}
|
||||
}
|
||||
unset($email_list);
|
||||
|
@ -114,29 +114,20 @@ class acp_inactive
|
||||
|
||||
if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !empty($inactive_users))
|
||||
{
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
$messenger = new messenger(false);
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$email = $messenger->offsetGet('messenger.method.email');
|
||||
$email->set_use_queue(false);
|
||||
|
||||
foreach ($inactive_users as $row)
|
||||
{
|
||||
$messenger->template('admin_welcome_activated', $row['user_lang']);
|
||||
|
||||
$messenger->set_addresses($row);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
'USERNAME' => html_entity_decode($row['username'], ENT_COMPAT))
|
||||
);
|
||||
|
||||
$messenger->send(NOTIFY_EMAIL);
|
||||
$email->template('admin_welcome_activated', $row['user_lang']);
|
||||
$email->set_addresses($row);
|
||||
$email->anti_abuse_headers($config, $user);
|
||||
$email->assign_vars([
|
||||
'USERNAME' => html_entity_decode($row['username'], ENT_COMPAT),
|
||||
]);
|
||||
$email->send();
|
||||
}
|
||||
|
||||
$messenger->save_queue();
|
||||
}
|
||||
|
||||
if (!empty($inactive_users))
|
||||
@ -207,37 +198,37 @@ class acp_inactive
|
||||
if ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
// Send the messages
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
$messenger = new messenger();
|
||||
$usernames = $user_ids = array();
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$messenger_collection_iterator = $messenger->getIterator();
|
||||
|
||||
do
|
||||
{
|
||||
$messenger->template('user_remind_inactive', $row['user_lang']);
|
||||
|
||||
$messenger->set_addresses($row);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
while ($messenger_collection_iterator->valid())
|
||||
{
|
||||
$messenger_method = $messenger_collection_iterator->current();
|
||||
if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == NOTIFY_BOTH)
|
||||
{
|
||||
$messenger_method->template('user_remind_inactive', $row['user_lang']);
|
||||
$messenger_method->set_addresses($row);
|
||||
$messenger_method->anti_abuse_headers($config, $user);
|
||||
$messenger_method->assign_vars([
|
||||
'USERNAME' => html_entity_decode($row['username'], ENT_COMPAT),
|
||||
'REGISTER_DATE' => $user->format_date($row['user_regdate'], false, true),
|
||||
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
|
||||
);
|
||||
'U_ACTIVATE' => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'],
|
||||
]);
|
||||
|
||||
$messenger->send($row['user_notify_type']);
|
||||
$messenger_method->send();
|
||||
$messenger_method->save_queue();
|
||||
}
|
||||
$messenger_collection_iterator->next();
|
||||
}
|
||||
|
||||
$usernames[] = $row['username'];
|
||||
$user_ids[] = (int) $row['user_id'];
|
||||
}
|
||||
while ($row = $db->sql_fetchrow($result));
|
||||
|
||||
$messenger->save_queue();
|
||||
|
||||
// Add the remind state to the database and increase activation expiration by one day
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
SET user_reminded = user_reminded + 1,
|
||||
|
@ -364,11 +364,6 @@ class acp_users
|
||||
|
||||
if ($config['email_enable'])
|
||||
{
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
$server_url = generate_board_url();
|
||||
|
||||
$user_actkey = gen_rand_string(mt_rand(6, 10));
|
||||
@ -403,21 +398,18 @@ class acp_users
|
||||
$db->sql_query($sql);
|
||||
|
||||
// Start sending email
|
||||
$messenger = new messenger(false);
|
||||
|
||||
$messenger->template($email_template, $user_row['user_lang']);
|
||||
|
||||
$messenger->set_addresses($user_row);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$email = $messenger->offsetGet('messenger.method.email');
|
||||
$email->set_use_queue(false);
|
||||
$email->template($email_template, $user_row['user_lang']);
|
||||
$email->set_addresses($user_row);
|
||||
$email->anti_abuse_headers($config, $user);
|
||||
$email->assign_vars([
|
||||
'WELCOME_MSG' => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
|
||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
||||
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
|
||||
);
|
||||
|
||||
$messenger->send(NOTIFY_EMAIL);
|
||||
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey",
|
||||
]);
|
||||
$email->send();
|
||||
|
||||
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE', false, array($user_row['username']));
|
||||
$phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE_USER', false, array(
|
||||
@ -462,24 +454,16 @@ class acp_users
|
||||
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
||||
$phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
|
||||
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
$messenger = new messenger(false);
|
||||
|
||||
$messenger->template('admin_welcome_activated', $user_row['user_lang']);
|
||||
|
||||
$messenger->set_addresses($user_row);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT))
|
||||
);
|
||||
|
||||
$messenger->send(NOTIFY_EMAIL);
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$email = $messenger->offsetGet('messenger.method.email');
|
||||
$email->set_use_queue(false);
|
||||
$email->template('admin_welcome_activated', $user_row['user_lang']);
|
||||
$email->set_addresses($user_row);
|
||||
$email->anti_abuse_headers($config, $user);
|
||||
$email->assign_vars([
|
||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
||||
]);
|
||||
$email->send();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,6 @@ class mcp_pm_reports
|
||||
{
|
||||
case 'close':
|
||||
case 'delete':
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
$report_id_list = $request->variable('report_id_list', array(0));
|
||||
|
||||
if (!count($report_id_list))
|
||||
|
@ -50,8 +50,6 @@ class mcp_queue
|
||||
{
|
||||
case 'approve':
|
||||
case 'restore':
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
$post_id_list = $request->variable('post_id_list', array(0));
|
||||
$topic_id_list = $request->variable('topic_id_list', array(0));
|
||||
|
||||
@ -113,11 +111,6 @@ class mcp_queue
|
||||
return;
|
||||
}
|
||||
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
|
||||
if (!empty($topic_id_list))
|
||||
{
|
||||
$post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE);
|
||||
|
@ -49,8 +49,6 @@ class mcp_reports
|
||||
{
|
||||
case 'close':
|
||||
case 'delete':
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
$report_id_list = $request->variable('report_id_list', array(0));
|
||||
|
||||
if (!count($report_id_list))
|
||||
|
@ -107,7 +107,6 @@ function mcp_topic_view($id, $mode, $action)
|
||||
}
|
||||
|
||||
include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
if (!count($post_id_list))
|
||||
{
|
||||
|
@ -131,21 +131,25 @@ class ucp_activate
|
||||
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
||||
$phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
|
||||
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$messenger_collection_iterator = $messenger->getIterator();
|
||||
while ($messenger_collection_iterator->valid())
|
||||
{
|
||||
$messenger_method = $messenger_collection_iterator->current();
|
||||
if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == NOTIFY_BOTH)
|
||||
{
|
||||
$messenger_method->set_use_queue(false);
|
||||
$messenger_method->template('admin_welcome_activated', $user_row['user_lang']);
|
||||
$messenger_method->set_addresses($user_row);
|
||||
$messenger_method->anti_abuse_headers($config, $user);
|
||||
$messenger_method->assign_vars([
|
||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT),
|
||||
]);
|
||||
|
||||
$messenger = new messenger(false);
|
||||
|
||||
$messenger->template('admin_welcome_activated', $user_row['user_lang']);
|
||||
|
||||
$messenger->set_addresses($user_row);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
'USERNAME' => html_entity_decode($user_row['username'], ENT_COMPAT))
|
||||
);
|
||||
|
||||
$messenger->send($user_row['user_notify_type']);
|
||||
$messenger_method->send();
|
||||
}
|
||||
$messenger_collection_iterator->next();
|
||||
}
|
||||
|
||||
$message = 'ACCOUNT_ACTIVE_ADMIN';
|
||||
}
|
||||
|
@ -170,27 +170,21 @@ class ucp_profile
|
||||
{
|
||||
$message = ($config['require_activation'] == USER_ACTIVATION_SELF) ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN';
|
||||
|
||||
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
|
||||
$server_url = generate_board_url();
|
||||
|
||||
$user_actkey = gen_rand_string(mt_rand(6, 10));
|
||||
|
||||
$messenger = new messenger(false);
|
||||
|
||||
$messenger = $phpbb_container->get('messenger.method_collection');
|
||||
$email = $messenger->offsetGet('messenger.method.email');
|
||||
$template_file = ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? 'user_activate_inactive' : 'user_activate';
|
||||
$messenger->template($template_file, $user->data['user_lang']);
|
||||
|
||||
$messenger->to($data['email'], $data['username']);
|
||||
|
||||
$messenger->anti_abuse_headers($config, $user);
|
||||
|
||||
$messenger->assign_vars(array(
|
||||
$email->template($template_file, $user->data['user_lang']);
|
||||
$email->to($data['email'], $data['username']);
|
||||
$email->anti_abuse_headers($config, $user);
|
||||
$email->assign_vars([
|
||||
'USERNAME' => html_entity_decode($data['username'], ENT_COMPAT),
|
||||
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user->data['user_id']}&k=$user_actkey")
|
||||
);
|
||||
|
||||
$messenger->send(NOTIFY_EMAIL);
|
||||
'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user->data['user_id']}&k=$user_actkey",
|
||||
]);
|
||||
$email->send();
|
||||
|
||||
if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
|
||||
{
|
||||
|
@ -109,14 +109,17 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||
$phpbb_container->setParameter('core.root_path', $phpbb_root_path);
|
||||
$phpbb_container->setParameter('core.php_ext', $phpEx);
|
||||
|
||||
if (!class_exists('messenger'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
|
||||
}
|
||||
$core_cache_dir = $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/';
|
||||
$phpbb_container->setParameter('core.cache_dir', $core_cache_dir);
|
||||
$core_messenger_queue_file = $core_cache_dir . 'queue.' . $phpEx;
|
||||
$phpbb_container->setParameter('core.messenger_queue_file', $core_messenger_queue_file);
|
||||
$messenger_method_collection = new \phpbb\di\service_collection($phpbb_container);
|
||||
$phpbb_container->set('messenger.method_collection', $messenger_method_collection);
|
||||
$messenger_queue = new \phpbb\messenger\queue($config, $dispatcher, $messenger_method_collection, $core_messenger_queue_file);
|
||||
$phpbb_container->set('messenger.queue', $messenger_queue);
|
||||
$this->email = new \phpbb\messenger\email($config, $dispatcher, $lang, $log, $request, $user, $messenger_queue);
|
||||
|
||||
$this->messenger = new \messenger();
|
||||
|
||||
$reflection = new ReflectionObject($this->messenger);
|
||||
$reflection = new ReflectionObject($this->email);
|
||||
$this->reflection_template_property = $reflection->getProperty('template');
|
||||
$this->reflection_template_property->setAccessible(true);
|
||||
}
|
||||
@ -136,9 +139,9 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||
{
|
||||
global $config, $phpEx, $user;
|
||||
|
||||
$this->messenger->set_addresses($user->data);
|
||||
$this->email->set_addresses($user->data);
|
||||
|
||||
$this->messenger->assign_vars(array(
|
||||
$this->email->assign_vars(array(
|
||||
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . html_entity_decode($config['board_email_sig'], ENT_COMPAT)),
|
||||
'SITENAME' => html_entity_decode($config['sitename'], ENT_COMPAT),
|
||||
|
||||
@ -150,9 +153,9 @@ class phpbb_email_parsing_test extends phpbb_test_case
|
||||
'U_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?f=1",
|
||||
'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$phpEx}?uid=2&f=1&unwatch=forum",
|
||||
));
|
||||
$this->messenger->template('newtopic_notify', $user->data['user_lang'], '', '');
|
||||
$this->email->template('newtopic_notify', $user->data['user_lang'], '', '');
|
||||
|
||||
$reflection_template = $this->reflection_template_property->getValue($this->messenger);
|
||||
$reflection_template = $this->reflection_template_property->getValue($this->email);
|
||||
$msg = trim($reflection_template->assign_display('body'));
|
||||
|
||||
$this->assertStringContainsString($author_name, $msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user