Skip to content

Commit 6ecb41f

Browse files
authored
Merge pull request phpbb#6794 from rxu/ticket/17489
[ticket/17489] Fix various messenger issues
2 parents 10cb499 + 43d3488 commit 6ecb41f

File tree

11 files changed

+95
-31
lines changed

11 files changed

+95
-31
lines changed

phpBB/includes/acp/acp_email.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ function main($id, $mode)
227227
$used_lang = $email_list[$i][0]['lang'];
228228
$used_method = $email_list[$i][0]['method'];
229229

230+
/**
231+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
232+
* @psalm-suppress UndefinedMethod
233+
*/
230234
foreach ($messenger_collection_iterator as $messenger_method)
231235
{
232236
$notify_method = $messenger_method->get_id();
@@ -265,19 +269,12 @@ function main($id, $mode)
265269
}
266270

267271
$errored = !$messenger_method->send() || $errored;
272+
$messenger_method->save_queue();
268273
}
269274
}
270275
}
271276
unset($email_list);
272277

273-
if ($use_queue)
274-
{
275-
foreach ($messenger_collection_iterator as $messenger_method)
276-
{
277-
$messenger_method->save_queue();
278-
}
279-
}
280-
281278
if ($generate_log_entry)
282279
{
283280
if (!empty($usernames))

phpBB/includes/acp/acp_inactive.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ function main($id, $mode)
205205

206206
do
207207
{
208+
/**
209+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
210+
* @psalm-suppress UndefinedMethod
211+
*/
208212
foreach ($messenger_collection_iterator as $messenger_method)
209213
{
210214
if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == $messenger_method::NOTIFY_BOTH)
@@ -219,6 +223,7 @@ function main($id, $mode)
219223
]);
220224

221225
$messenger_method->send();
226+
$messenger_method->save_queue();
222227
}
223228
}
224229

@@ -227,11 +232,6 @@ function main($id, $mode)
227232
}
228233
while ($row = $db->sql_fetchrow($result));
229234

230-
foreach ($messenger_collection_iterator as $messenger_method)
231-
{
232-
$messenger_method->save_queue();
233-
}
234-
235235
// Add the remind state to the database and increase activation expiration by one day
236236
$sql = 'UPDATE ' . USERS_TABLE . '
237237
SET user_reminded = user_reminded + 1,

phpBB/includes/ucp/ucp_activate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ function main($id, $mode)
133133

134134
$messenger = $phpbb_container->get('messenger.method_collection');
135135
$messenger_collection_iterator = $messenger->getIterator();
136+
137+
/**
138+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
139+
* @psalm-suppress UndefinedMethod
140+
*/
136141
foreach ($messenger_collection_iterator as $messenger_method)
137142
{
138143
if ($messenger_method->get_id() == $user_row['user_notify_type'] || $user_row['user_notify_type'] == $messenger_method::NOTIFY_BOTH)

phpBB/includes/ucp/ucp_resend.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ function main($id, $mode)
138138
$messenger_collection_iterator = $messenger->getIterator();
139139
while ($row = $db->sql_fetchrow($result))
140140
{
141+
/**
142+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
143+
* @psalm-suppress UndefinedMethod
144+
*/
141145
foreach ($messenger_collection_iterator as $messenger_method)
142146
{
143147
$messenger_method->set_use_queue(false);
@@ -157,12 +161,6 @@ function main($id, $mode)
157161
}
158162
}
159163
$db->sql_freeresult($result);
160-
161-
// Save the queue in the messenger method class (has to be called or these messages could be lost)
162-
foreach ($messenger_collection_iterator as $messenger_method)
163-
{
164-
$messenger_method->save_queue();
165-
}
166164
}
167165

168166
$this->update_activation_expiration();

phpBB/phpbb/message/message.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ public function send(\phpbb\di\service_collection $messenger, $contact)
249249
{
250250
/** @psalm-suppress InvalidTemplateParam */
251251
$messenger_collection_iterator = $messenger->getIterator();
252+
253+
/**
254+
* @var messenger_interface $messenger_method
255+
* @psalm-suppress UndefinedMethod
256+
*/
252257
foreach ($messenger_collection_iterator as $messenger_method)
253258
{
254259
$messenger_method->set_use_queue(false);
@@ -264,6 +269,7 @@ public function send(\phpbb\di\service_collection $messenger, $contact)
264269
{
265270
$messenger_method->header('X-AntiAbuse', 'User_id - ' . $this->sender_id);
266271
}
272+
267273
if ($this->sender_username)
268274
{
269275
$messenger_method->header('X-AntiAbuse', 'Username - ' . $this->sender_username);

phpBB/phpbb/messenger/method/base.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,12 @@ protected function set_template_paths(string|array $path_name, string|array $pat
481481
$this->setup_template();
482482
$this->template->set_custom_style($path_name, $paths);
483483
}
484+
485+
/**
486+
* {@inheritdoc}
487+
*/
488+
public function header(string $header_name, mixed $header_value): void
489+
{
490+
return;
491+
}
484492
}

phpBB/phpbb/messenger/method/email.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function init(): void
105105
$this->mail_priority = symfony_email::PRIORITY_NORMAL;
106106

107107
$this->additional_headers = [];
108-
$this->use_queue = true;
108+
$this->set_use_queue();
109109
unset($this->template, $this->reply_to, $this->from);
110110
}
111111

@@ -242,10 +242,10 @@ public function subject(string $subject = ''): void
242242
*/
243243
public function anti_abuse_headers(\phpbb\config\config $config, \phpbb\user $user): void
244244
{
245-
$this->headers->addHeader('X-AntiAbuse', 'Board servername - ' . $config['server_name']);
246-
$this->headers->addHeader('X-AntiAbuse', 'User_id - ' . $user->data['user_id']);
247-
$this->headers->addHeader('X-AntiAbuse', 'Username - ' . $user->data['username']);
248-
$this->headers->addHeader('X-AntiAbuse', 'User IP - ' . $user->ip);
245+
$this->header('X-AntiAbuse', 'Board servername - ' . $config['server_name']);
246+
$this->header('X-AntiAbuse', 'User_id - ' . $user->data['user_id']);
247+
$this->header('X-AntiAbuse', 'Username - ' . $user->data['username']);
248+
$this->header('X-AntiAbuse', 'User IP - ' . $user->ip);
249249
}
250250

251251
/**
@@ -313,7 +313,7 @@ protected function build_headers(): void
313313

314314
foreach ($headers as $header => $value)
315315
{
316-
$this->headers->addHeader($header, $value);
316+
$this->header($header, $value);
317317
}
318318

319319
}
@@ -576,4 +576,12 @@ public function send(): bool
576576

577577
return true;
578578
}
579+
580+
/**
581+
* {@inheritdoc}
582+
*/
583+
public function header(string $header_name, mixed $header_value): void
584+
{
585+
$this->headers->addHeader($header_name, $header_value);
586+
}
579587
}

phpBB/phpbb/messenger/method/messenger_interface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,16 @@ public function send(): bool;
6464
*
6565
* @return void
6666
*/
67+
6768
public function error(string $msg): void;
69+
70+
/**
71+
* Add message header
72+
*
73+
* @param string $header_name Message header name
74+
* @param mixed $header_value Message header value
75+
*
76+
* @return void
77+
*/
78+
public function header(string $header_name, mixed $header_value): void;
6879
}

phpBB/phpbb/messenger/queue.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public function process(): void
116116

117117
/** @psalm-suppress InvalidTemplateParam */
118118
$messenger_collection_iterator = $this->messenger_method_collection->getIterator();
119+
120+
/**
121+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
122+
* @psalm-suppress UndefinedMethod
123+
*/
119124
foreach ($messenger_collection_iterator as $messenger_method)
120125
{
121126
if (isset($this->queue_data[$messenger_method->get_queue_object_name()]))

phpBB/phpbb/notification/method/messenger_base.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ protected function notify_using_messenger($notify_method, $template_dir_prefix =
114114
continue;
115115
}
116116

117+
/**
118+
* @var \phpbb\messenger\method\messenger_interface $messenger_method
119+
* @psalm-suppress UndefinedMethod
120+
*/
117121
foreach ($messenger_collection_iterator as $messenger_method)
118122
{
119123
if ($messenger_method->get_id() == $notify_method || $notify_method == $messenger_method::NOTIFY_BOTH)
@@ -126,16 +130,13 @@ protected function notify_using_messenger($notify_method, $template_dir_prefix =
126130
], $notification->get_email_template_variables()));
127131

128132
$messenger_method->send();
133+
134+
// Save the queue in the messenger method class (has to be called or these messages could be lost)
135+
$messenger_method->save_queue();
129136
}
130137
}
131138
}
132139

133-
// Save the queue in the messenger method class (has to be called or these messages could be lost)
134-
foreach ($messenger_collection_iterator as $messenger_method)
135-
{
136-
$messenger_method->save_queue();
137-
}
138-
139140
// We're done, empty the queue
140141
$this->empty_queue();
141142
}

0 commit comments

Comments
 (0)