Skip to content

Commit e826192

Browse files
committed
[ticket/17135] Move notify method constants to interface class
PHPBB-17135
1 parent b60b37b commit e826192

File tree

10 files changed

+34
-15
lines changed

10 files changed

+34
-15
lines changed

db/migration/data/v310/notification_options_reconvert.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace phpbb\db\migration\data\v310;
1515

16+
use phpbb\messenger\method\messenger_interface;
17+
1618
class notification_options_reconvert extends \phpbb\db\migration\migration
1719
{
1820
public static function depends_on()
@@ -67,12 +69,12 @@ public function perform_conversion(\phpbb\db\sql_insert_buffer $insert_buffer, $
6769
// In-board notification
6870
$notification_methods[] = '';
6971

70-
if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH)
72+
if ($row['user_notify_type'] == messenger_interface::NOTIFY_EMAIL || $row['user_notify_type'] == messenger_interface::NOTIFY_BOTH)
7173
{
7274
$notification_methods[] = 'email';
7375
}
7476

75-
if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH)
77+
if ($row['user_notify_type'] == messenger_interface::NOTIFY_IM || $row['user_notify_type'] == messenger_interface::NOTIFY_BOTH)
7678
{
7779
$notification_methods[] = 'jabber';
7880
}

message/admin_form.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace phpbb\message;
1515

16+
use phpbb\messenger\method\messenger_interface;
17+
1618
/**
1719
* Class admin_form
1820
* Displays a message to the user and allows him to send an email
@@ -155,7 +157,7 @@ public function submit(\phpbb\di\service_collection $messenger)
155157
}
156158

157159
$this->message->set_sender($this->user->ip, $this->sender_name, $this->sender_address, $this->user->lang_name);
158-
$this->message->set_sender_notify_type(NOTIFY_EMAIL);
160+
$this->message->set_sender_notify_type(messenger_interface::NOTIFY_EMAIL);
159161
}
160162

161163
$this->message->set_template('contact_admin');
@@ -165,7 +167,7 @@ public function submit(\phpbb\di\service_collection $messenger)
165167
$this->user->lang['ADMINISTRATOR'],
166168
$this->config['board_contact'],
167169
$this->config['default_lang'],
168-
NOTIFY_EMAIL
170+
messenger_interface::NOTIFY_EMAIL
169171
);
170172

171173
$this->message->set_template_vars(array(

message/message.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace phpbb\message;
1515

16+
use phpbb\messenger\method\messenger_interface;
17+
1618
/**
1719
* Class message
1820
* Holds all information for an email and sends it in the end
@@ -46,7 +48,7 @@ class message
4648
/** @var string */
4749
protected $sender_jabber = '';
4850
/** @var int */
49-
protected $sender_notify_type = NOTIFY_EMAIL;
51+
protected $sender_notify_type = messenger_interface::NOTIFY_EMAIL;
5052

5153
/** @var array */
5254
protected $recipients;
@@ -134,7 +136,7 @@ public function add_recipient_from_user_row(array $user)
134136
* @param string $recipient_jabber
135137
* @return void
136138
*/
137-
public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '')
139+
public function add_recipient($recipient_name, $recipient_address, $recipient_lang, $recipient_notify_type = messenger_interface::NOTIFY_EMAIL, $recipient_username = '', $recipient_jabber = '')
138140
{
139141
$this->recipients[] = array(
140142
'name' => $recipient_name,
@@ -250,7 +252,7 @@ public function send(\phpbb\di\service_collection $messenger, $contact)
250252
foreach ($messenger_collection_iterator as $messenger_method)
251253
{
252254
$messenger_method->set_use_queue(false);
253-
if ($messenger_method->get_id() == $recipient['notify_type'] || $recipient['notify_type'] == NOTIFY_BOTH)
255+
if ($messenger_method->get_id() == $recipient['notify_type'] || $recipient['notify_type'] == $messenger_method::NOTIFY_BOTH)
254256
{
255257
$messenger_method->template($this->template, $recipient['lang']);
256258
$messenger_method->set_addresses($recipient);

message/topic_form.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace phpbb\message;
1515

16+
use phpbb\messenger\method\messenger_interface;
17+
1618
/**
1719
* Class topic_form
1820
* Form used to send topics as notification emails
@@ -130,9 +132,9 @@ public function submit(\phpbb\di\service_collection $messenger)
130132
$this->recipient_name,
131133
$this->recipient_address,
132134
$this->recipient_lang,
133-
NOTIFY_EMAIL
135+
messenger_interface::NOTIFY_EMAIL
134136
);
135-
$this->message->set_sender_notify_type(NOTIFY_EMAIL);
137+
$this->message->set_sender_notify_type(messenger_interface::NOTIFY_EMAIL);
136138

137139
parent::submit($messenger);
138140
}

messenger/method/email.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class email extends base
7575
*/
7676
public function get_id(): int
7777
{
78-
return NOTIFY_EMAIL;
78+
return self::NOTIFY_EMAIL;
7979
}
8080

8181
/**

messenger/method/jabber.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function init(): void
115115
*/
116116
public function get_id(): int
117117
{
118-
return NOTIFY_IM;
118+
return self::NOTIFY_IM;
119119
}
120120

121121
/**

messenger/method/messenger_interface.php

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
*/
1919
interface messenger_interface
2020
{
21+
/** @var int Email notify method used */
22+
public const NOTIFY_EMAIL = 0;
23+
24+
/** @var int Instant messaging (Jabber) notify method used */
25+
public const NOTIFY_IM = 1;
26+
27+
/** @var int Both notify methods used */
28+
public const NOTIFY_BOTH = 2;
29+
2130
/**
2231
* Get messenger method id
2332
*

notification/method/email.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use phpbb\config\config;
2020
use phpbb\db\driver\driver_interface;
2121
use phpbb\di\service_collection;
22+
use phpbb\messenger\method\messenger_interface;
2223

2324
/**
2425
* Email notification method class
@@ -135,7 +136,7 @@ public function notify()
135136

136137
$insert_buffer->flush();
137138

138-
$this->notify_using_messenger(NOTIFY_EMAIL);
139+
$this->notify_using_messenger(messenger_interface::NOTIFY_EMAIL);
139140
}
140141

141142
/**

notification/method/jabber.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpbb\user_loader;
1919
use phpbb\config\config;
2020
use phpbb\di\service_collection;
21+
use phpbb\messenger\method\messenger_interface;
2122

2223
/**
2324
* Jabber notification method class
@@ -98,6 +99,6 @@ public function notify()
9899
return;
99100
}
100101

101-
$this->notify_using_messenger(NOTIFY_IM, 'short/');
102+
$this->notify_using_messenger(messenger_interface::NOTIFY_IM, 'short/');
102103
}
103104
}

notification/method/messenger_base.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function is_available(type_interface $notification_type = null)
6767
/**
6868
* Notify using phpBB messenger
6969
*
70-
* @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM)
70+
* @param int $notify_method Notify method for messenger (e.g. \phpbb\messenger\method\messenger_interface::NOTIFY_IM)
7171
* @param string $template_dir_prefix Base directory to prepend to the email template name
7272
*
7373
* @return void
@@ -115,7 +115,7 @@ protected function notify_using_messenger($notify_method, $template_dir_prefix =
115115
$messenger_collection_iterator = $this->messenger->getIterator();
116116
foreach ($messenger_collection_iterator as $messenger_method)
117117
{
118-
if ($messenger_method->get_id() == $notify_method || $notify_method == NOTIFY_BOTH)
118+
if ($messenger_method->get_id() == $notify_method || $notify_method == $messenger_method::NOTIFY_BOTH)
119119
{
120120
$messenger_method->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix);
121121
$messenger_method->set_addresses($user);

0 commit comments

Comments
 (0)