Enable Forum topic activity notification on new member


Could anyone give me some php coding snipits as to how at automatically enable the "Forum topic activity" email notification setting when a new member joins.
Currently its disabled but the nature of our group and the skill set means that is proving changing for quite a few peopleto change it themselves. and this would really help everyone involved.
Many Thanks
Chris


I didn't test it, but try this sources_custom/hooks/systems/upon_query/auto_notifications.php:
Code
<?php
class Hook_upon_query_auto_notifications
{
public function run_post($ob, $query, $max, $start, $fail_ok, $get_insert_id, $ret)
{
if (isset($GLOBALS['FORUM_DB']) && strpos($query, 'INTO ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members') !== false) {
require_code('notifications');
enable_notifications('cns_topic', null, $ret);
}
}
}
Last edit: by Chris Graham
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


Your auto_notifications.php code worked first time
I would have never worked out to put it in that directory !!
Sincere thanks
Chris


Although the hook is working as intended there is a slight problem that new members who have not yet been validated by staff are receiving notifications which should not yet be receiving (until they are validated)
How and where in notifications.php can I check to only send notifications to members who are validated ?
Chris


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


I've now completely rewritten the _all_members_who_have_enabled method, as it's complexity density had gotten too high to understand it.
Please grab the full function from:
https://github.com/ocproducts/composr/blob/master/sources/notifications.php
And put it into your version of the file.
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


sorry for the delay, but have just tried the new code from git, and we have a constant problem when people try to set their password from their profile. Here's an example error, generated from the sources_custom/notifications.php
Unfortunately a query has failed [SELECT m.id AS l_member_id,l_setting FROM cms_f_members m LEFT JOIN cms_notifications_enabled l ON m.id=l.l_member_id AND l_notification_code='cns_password_changed' AND l_code_category='' WHERE 1=1 AND ( OR m.id=743) AND m_validated_email_confirm_code='' AND m_validated=1 AND m.id<>1 AND l_setting IS NULL OR l_setting<>0 LIMIT 0,300] [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR m.id=743) AND m_validated_email_confirm_code='' AND m_validated=1 AND m.id<>1' at line 1] (version: 10.custom, PHP version: 7.1.26, URL: /c10/index.php?page=members&type=view&id=743)
Thanks
Chris


I suspect you didn't use the very latest code. There were a couple of fixes I had to make unfortunately after my changes…
https://github.com/ocproducts/composr/commit/a608c526c3b262612585d5bdc16d884c118470f5#diff-da9c5b50898a13f5f3a985360ba719bd
https://github.com/ocproducts/composr/commit/567fc9b4cefb3532203dec653dca7e44e5a7e436#diff-da9c5b50898a13f5f3a985360ba719bd
Maybe you'd already downloaded the file before I made the changes or something.
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


I have just added the changed lines, and after changing the password on an account that has just sent an e-mail notification saying their password has been changed to EVERYONE ! - Big problem
I have been logging the resulting SQL, and this is what it generated
SELECT m.id AS l_member_id,l_setting FROM cms_f_members m LEFT JOIN cms_notifications_enabled l ON m.id=l.l_member_id AND l_notification_code='cns_password_changed' AND l_code_category='' WHERE 1=1 AND (m.id=743) AND m_validated_email_confirm_code='' AND m_validated=1 AND m.id<>1 AND l_setting IS NULL OR l_setting<>0



Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


https://github.com/ocproducts/composr/commit/a608c526c3b262612585d5bdc16d884c118470f5#diff-da9c5b50898a13f5f3a985360ba719bd
Perhaps you didn't see I posted 2 links?
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.


I have just run the query in phpmyadmin, and it returned 191 records,
phpmyadmin :
Showing rows 25 - 49 (191 total, Query took 0.0029 seconds.)
SELECT m.id AS l_member_id,l_setting FROM cms_f_members m LEFT JOIN cms_notifications_enabled l ON m.id=l.l_member_id AND l_notification_code='cns_password_changed' AND l_code_category='' WHERE 1=1 AND (m.id=743) AND m_validated_email_confirm_code='' AND m_validated=1 AND m.id<>1 AND l_setting IS NULL OR l_setting<>0
l_member_id , l_setting
535 2
537 2
542 2
543 2
544 2
548 2
550 2
….
edit - let me checkout the other github code change.....
Last edit: by supertramp4


Thanks, I had missed the other git change.
That's sorted now and seems to be working.
Many Thanks
Chris


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.