Skip to content

Commit a7ce501

Browse files
authored
Merge pull request #63 from phpbb-extensions/fix/symfony_mailer
Fix compatibility with symfony mailer for phpBB 4.0 dev
2 parents de94714 + c983f20 commit a7ce501

File tree

6 files changed

+115
-42
lines changed

6 files changed

+115
-42
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ jobs:
238238

239239
services:
240240
postgres:
241-
image: ${{ matrix.db != 'postgres:9.5' && matrix.db != 'postgres:9.6' && matrix.db != 'postgres:10' && matrix.db != 'postgres:11' && matrix.db != 'postgres:12' && matrix.db != 'postgres:13' && 'postgres:10' || matrix.db }}
241+
image: ${{ matrix.db != 'postgres:9.5' && matrix.db != 'postgres:9.6' && matrix.db != 'postgres:10' && matrix.db != 'postgres:11' && matrix.db != 'postgres:12' && matrix.db != 'postgres:13' && matrix.db != 'postgres:14' && matrix.db != 'postgres:15' && 'postgres:10' || matrix.db }}
242242
env:
243243
POSTGRES_HOST: localhost
244244
POSTGRES_USER: postgres

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "Security measures to help watch over team member accounts.",
55
"homepage": "https://www.phpbb.com",
6-
"version": "1.0.0",
6+
"version": "1.1.0-dev",
77
"license": "GPL-2.0-only",
88
"authors": [
99
{
@@ -19,13 +19,18 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=5.4",
22+
"php": ">=8.1",
2323
"composer/installers": "~1.0"
2424
},
2525
"extra": {
2626
"display-name": "Team Security Measures",
2727
"soft-require": {
28-
"phpbb/phpbb": ">=3.2.0"
28+
"phpbb/phpbb": ">=4.0.0@dev,<4.1.0@dev"
29+
}
30+
},
31+
"config": {
32+
"allow-plugins": {
33+
"composer/installers": true
2934
}
3035
}
3136
}

composer.lock

Lines changed: 75 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
class: phpbb\teamsecurity\event\listener
44
arguments:
55
- '@config'
6+
- '@messenger.method.email'
67
- '@language'
78
- '@log'
89
- '@user'

event/listener.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,31 @@
1010

1111
namespace phpbb\teamsecurity\event;
1212

13+
use phpbb\config\config;
14+
use phpbb\language\language;
15+
use phpbb\log\log;
16+
use phpbb\messenger\method\email;
17+
use phpbb\user;
1318
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1419

1520
/**
1621
* Event listener
1722
*/
1823
class listener implements EventSubscriberInterface
1924
{
20-
/** @var \phpbb\config\config */
25+
/** @var config */
2126
protected $config;
2227

23-
/** @var \phpbb\language\language */
28+
/** @var email */
29+
protected $email_method;
30+
31+
/** @var language */
2432
protected $language;
2533

26-
/** @var \phpbb\log\log */
34+
/** @var log */
2735
protected $log;
2836

29-
/** @var \phpbb\user */
37+
/** @var user */
3038
protected $user;
3139

3240
/** @var string phpBB root path */
@@ -38,17 +46,19 @@ class listener implements EventSubscriberInterface
3846
/**
3947
* Constructor
4048
*
41-
* @param \phpbb\config\config $config Config object
42-
* @param \phpbb\language\language $language Language object
43-
* @param \phpbb\log\log $log The phpBB log system
44-
* @param \phpbb\user $user User object
49+
* @param config $config Config object
50+
* @param email $email_method Email method
51+
* @param language $language Language object
52+
* @param log $log The phpBB log system
53+
* @param user $user User object
4554
* @param string $phpbb_root_path phpBB root path
4655
* @param string $phpEx phpEx
4756
* @access public
4857
*/
49-
public function __construct(\phpbb\config\config $config, \phpbb\language\language $language, \phpbb\log\log $log, \phpbb\user $user, $phpbb_root_path, $phpEx)
58+
public function __construct(config $config, email $email_method, language $language, log $log, user $user, string $phpbb_root_path, string $phpEx)
5059
{
5160
$this->config = $config;
61+
$this->email_method = $email_method;
5262
$this->language = $language;
5363
$this->log = $log;
5464
$this->user = $user;
@@ -283,16 +293,11 @@ protected function in_watch_group($user_id)
283293
*/
284294
protected function send_message($message_data, $template, $cc_user = '')
285295
{
286-
if (!class_exists('messenger'))
287-
{
288-
include $this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext;
289-
}
290-
291-
$messenger = new \messenger(false);
292-
$messenger->template('@phpbb_teamsecurity/' . $template);
293-
$messenger->to(!empty($this->config['sec_contact']) ? $this->config['sec_contact'] : $this->config['board_contact'], $this->config['board_contact_name']);
294-
$messenger->cc($cc_user);
295-
$messenger->assign_vars($message_data);
296-
$messenger->send();
296+
$this->email_method->set_use_queue(false);
297+
$this->email_method->template('@phpbb_teamsecurity/' . $template);
298+
$this->email_method->to(!empty($this->config['sec_contact']) ? $this->config['sec_contact'] : $this->config['board_contact'], $this->config['board_contact_name']);
299+
$this->email_method->cc($cc_user);
300+
$this->email_method->assign_vars($message_data);
301+
$this->email_method->send();
297302
}
298303
}

tests/event/listener_base.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class listener_base extends \phpbb_test_case
1818
/** @var \phpbb\config\config */
1919
protected $config;
2020

21+
/** @var hpbb\messenger\method\email */
22+
protected $email_method;
23+
2124
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\log\log */
2225
protected $log;
2326

@@ -44,6 +47,7 @@ protected function setUp(): void
4447

4548
// Load/Mock classes required by the event listener class
4649
$this->config = new \phpbb\config\config(array('default_dateformat' => 'D M d, Y H:i:s A'));
50+
$this->email_method = $this->getMockBuilder('\phpbb\messenger\method\email')->disableOriginalConstructor()->getMock();
4751
$this->log = $this->getMockBuilder('\phpbb\log\log')
4852
->disableOriginalConstructor()
4953
->getMock();
@@ -70,6 +74,7 @@ protected function set_listener()
7074
))
7175
->setConstructorArgs(array(
7276
$this->config,
77+
$this->email_method,
7378
$this->lang,
7479
$this->log,
7580
$this->user,

0 commit comments

Comments
 (0)