Disable Email Notification only

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Disable Email Notification only

Post by Dark❶ » Sun Jul 07, 2019 8:21 am

Is there any PHP hook event that can be used to disable specific or all notification email.
Of-course except the Registration Activation email.

Thanking you , Best regards :+1:
Dark❶ [dark1]

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Thu Jul 11, 2019 5:32 pm

Dark❶ wrote:
Sun Jul 07, 2019 8:21 am
Is there any PHP hook event that can be used to disable specific or all notification email.
Not that I am aware of.
I use queries (custom function's call) in a migration for my notifications and I think you can do that for standard ones too.
The notification manager could be used instead of queries, just I didn't investigate further, too much of code to inject for a such job IMHO.

Moreover, the only event where you will have to replicate the same code but only for users who will register in the future is
core.user_add_after, which I am using too.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Thu Jul 11, 2019 9:56 pm

3Di wrote:
Thu Jul 11, 2019 5:32 pm
Dark❶ wrote:
Sun Jul 07, 2019 8:21 am
Is there any PHP hook event that can be used to disable specific or all notification email.
Not that I am aware of.
I use queries (custom function's call) in a migration for my notifications and I think you can do that for standard ones too.
The notification manager could be used instead of queries, just I didn't investigate further, too much of code to inject for a such job IMHO.

Moreover, the only event where you will have to replicate the same code but only for users who will register in the future is
core.user_add_after, which I am using too.
Thanks 3Di ,
I am already using core.user_add_after to unset all the notification ...
But required a proper solution , as you have rightly said there isn't any proper php hooks I guess..

Thanking you , best regards :+1:
Dark❶ [dark1]

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3717
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Disable Email Notification only

Post by kasimi » Thu Jul 11, 2019 10:06 pm

What you can do is disable all email notifications. Subscribe to core.modify_notification_message:

Code: Select all

public function handler($event)
{
    if ($event['method'] == NOTIFY_EMAIL)
    {
        $event['break'] = true;
    }
}
I can't find a way to allow specific notification types though. To do that, you would need a new event in the add_notifications_for_users() method in phpbb/notification/manager.php

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Fri Jul 12, 2019 6:56 am

kasimi wrote:
Thu Jul 11, 2019 10:06 pm
What you can do is disable all email notifications. Subscribe to core.modify_notification_message:

Code: Select all

public function handler($event)
{
    if ($event['method'] == NOTIFY_EMAIL)
    {
        $event['break'] = true;
    }
}
I can't find a way to allow specific notification types though. To do that, you would need a new event in the add_notifications_for_users() method in phpbb/notification/manager.php
I'll see if I can make an event at add_notifications_for_users() method in phpbb/notification/manager.php.

Thanks kasimi :D

Best regards :+1:
Dark❶ [dark1]

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Fri Jul 12, 2019 11:31 am

kasimi wrote:
Thu Jul 11, 2019 10:06 pm
What you can do is disable all email notifications. Subscribe to core.modify_notification_message:

Code: Select all

public function handler($event)
{
    if ($event['method'] == NOTIFY_EMAIL)
    {
        $event['break'] = true;
    }
}
I can't find a way to allow specific notification types though. To do that, you would need a new event in the add_notifications_for_users() method in phpbb/notification/manager.php
Using such event breaks the delivery of an already parsed message
core.modify_notification_template
instead can do the same thing but before of that.

Instead, with my method above described, I opted to directly disable === un-check the boxes in the UCP for all users.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Fri Jul 12, 2019 11:42 am

3Di wrote:
Fri Jul 12, 2019 11:31 am
...
Instead, with my method above described, I opted to directly disable === un-check the boxes in the UCP for all users.
But user can again opt for it right???

Best regards :+1:
Dark❶ [dark1]

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Fri Jul 12, 2019 11:46 am

Yes, in my use case.
It is possible to grey those boxes completely though, or make that part of the UCP invisible once done I believe.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Fri Jul 12, 2019 12:14 pm

3Di wrote:
Fri Jul 12, 2019 11:46 am
Yes, in my use case.
It is possible to grey those boxes completely though, or make that part of the UCP invisible once done I believe.
Currently I am using JS to disable those box...
But if user disables the JS then ... :roll:

Best regards :+1:
Dark❶ [dark1]

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3717
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Disable Email Notification only

Post by kasimi » Fri Jul 12, 2019 4:49 pm

3Di wrote:
Fri Jul 12, 2019 11:31 am
Using such event breaks the delivery of an already parsed message
core.modify_notification_template
instead can do the same thing but before of that.
The $break variable is evaluated only after both events core.modify_notification_template and core.modify_notification_message are triggered, so in this scenario, it doesn't make a difference which event you use: email messages are rendered and then discarded in both cases.

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Fri Jul 12, 2019 8:49 pm

kasimi wrote:
Fri Jul 12, 2019 4:49 pm
The $break variable is evaluated only after both events core.modify_notification_template and core.modify_notification_message are triggered, so in this scenario, it doesn't make a difference which event you use: email messages are rendered and then discarded in both cases.
Correct. I just reread the code. Thx. :)
Dark❶ wrote:
Fri Jul 12, 2019 12:14 pm
Currently I am using JS to disable those box...
But if user disables the JS then ... :roll:
Then? You already know the answer I guess.

To do what you want to do you can break the dispatch of ALL notifications forcing it as per above.
But since you want at least one notification type to be excluded from that, you have to create an event, as per kasimi.

Otherwise here is the array of native notifications type, the one you want to be excluded is commented out.
You can add other type of notifications (custom) to the array indeed.

Code: Select all

$type_ary = [
	'notification.type.topic',
	'notification.type.approve_topic',
	'notification.type.quote',
	'notification.type.bookmark',
	'notification.type.post',
	'notification.type.approve_post',
	'notification.type.group_request',
	'notification.type.post_in_queue',
	'notification.type.report_post',
	//'notification.type.admin_activate_user',
	'notification.type.disapprove_post',
	'notification.type.disapprove_topic',
	'notification.type.group_request_approved',
	'notification.type.pm',
	'notification.type.report_pm',
	'notification.type.report_pm_closed',
	'notification.type.report_post_closed',
	'notification.type.topic_in_queue',
];
Have a look at the migration: notification_options_reconvert migration (v310)
So to see how to deal with big boards (many users in batch).
For the newly registered users you already have an event.

Once done, you have to see how to grey-out those boxes without JS. ;)

example of code (NOT tested!)

Code: Select all

		/* Grab all registered users (excluding bots and guests) */
		$sql = 'SELECT user_id
			FROM ' . USERS_TABLE . '
			WHERE user_type <> ' . USER_IGNORE;
		$result = $this->db->sql_query($sql);
		$row = $this->db->sql_fetchrowset($result);
		$this->db->sql_freeresult($result);

		$type_ary = [
			'notification.type.topic',
			'notification.type.approve_topic',
			'notification.type.quote',
			'notification.type.bookmark',
			'notification.type.post',
			'notification.type.approve_post',
			'notification.type.group_request',
			'notification.type.post_in_queue',
			'notification.type.report_post',
			//'notification.type.admin_activate_user',
			'notification.type.disapprove_post',
			'notification.type.disapprove_topic',
			'notification.type.group_request_approved',
			'notification.type.pm',
			'notification.type.report_pm',
			'notification.type.report_pm_closed',
			'notification.type.report_post_closed',
			'notification.type.topic_in_queue',
		];

		foreach ($row as $user)
		{
			foreach ($type_ary as $type)
			{
				$sql_ary = [
					'item_type'		=> $type,
					'item_id'		=> 0,
					'user_id'		=> (int) $user['user_id'],
					'method'		=> 'notification.method.email',
					'notify'		=> 0,
				];

				$sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);

				$this->db->sql_query($sql);
			}
		}
Note:
in the above code we are working with notifications type EMAIL as per
'method' => 'notification.method.email',
instead for type board that should be
'method' => 'notification.method.board',

Moreover, you should check first if there are already some of those notifications there in order to use UPDATE instead of INSERT.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Sat Jul 13, 2019 7:27 am

3Di wrote:
Fri Jul 12, 2019 8:49 pm
...
Otherwise here is the array of native notifications type, the one you want to be excluded is commented out.
You can add other type of notifications (custom) to the array indeed.

Code: Select all

$type_ary = [
	'notification.type.topic',
	'notification.type.approve_topic',
	'notification.type.quote',
	'notification.type.bookmark',
	'notification.type.post',
	'notification.type.approve_post',
	'notification.type.group_request',
	'notification.type.post_in_queue',
	'notification.type.report_post',
	// 'notification.type.admin_activate_user',
	'notification.type.disapprove_post',
	'notification.type.disapprove_topic',
	'notification.type.group_request_approved',
	'notification.type.pm',
	'notification.type.report_pm',
	'notification.type.report_pm_closed',
	'notification.type.report_post_closed',
	'notification.type.topic_in_queue',
];
...
Thanks for all the Info 3Di ,
But just one question: Which notification.type is that user activates them-self ??

Thanking you , best regards :+1:
Dark❶ [dark1]

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Sat Jul 13, 2019 3:53 pm

Dark❶ wrote:
Sat Jul 13, 2019 7:27 am
But just one question: Which notification.type is that user activates them-self ??
There is no such notification, if the user still has to activate or reactivate himself explain to me how could he ever see his notifications?

In this case the email is sent directly from the Messenger. See core.ucp_register_welcome_email_before.

Why don't you explain what you want to do instead? What's your goal.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
Dark❶
Registered User
Posts: 99
Joined: Mon Jan 15, 2018 1:22 pm
Location: DarK V0id
Name: Dark❶ [dark1]

Re: Disable Email Notification only

Post by Dark❶ » Sat Jul 13, 2019 4:18 pm

3Di wrote:
Sat Jul 13, 2019 3:53 pm
Dark❶ wrote:
Sat Jul 13, 2019 7:27 am
But just one question: Which notification.type is that user activates them-self ??
There is no such notification, if the user still has to activate or reactivate himself explain to me how could he ever see his notifications?

In this case the email is sent directly from the Messenger. See core.ucp_register_welcome_email_before.

Why don't you explain what you want to do instead? What's your goal.
My goal : Disable all notification email(s) except User Registration Activation email.

I hope this clears the stuff...

Best regards :+1:
Dark❶ [dark1]

User avatar
3Di
Former Team Member
Posts: 13766
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Disable Email Notification only

Post by 3Di » Sat Jul 13, 2019 4:22 pm

You've got all you need already. There is no such notification type.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

Post Reply

Return to “Extension Writers Discussion”