Project

General

Profile

Bug #10800

Duplicate email notifications on blog comments

Added by Gina Cherry 8 months ago. Updated 5 months ago.

Status:
Resolved
Priority name:
Normal
Assignee:
Category name:
Email Notifications
Target version:
Start date:
2018-12-07
Due date:
% Done:

0%

Estimated time:

Description

I have a blog (bmcccetls.commons.gc.cuny.edu) connected to a group (BMCC CETLS). When I approve a comment on the blog, I get two identical notifications via email. It's possible that this only happens for comments that mistakenly went to spam and were released and then approved, but I'm not sure.


Related issues

Related to CUNY Academic Commons - Bug #8225: replies to a blog post activity itemResolved2017-06-05

Related to CUNY Academic Commons - Bug #11160: Return of duplicate email notifactions for blog commentsResolved2019-02-25

Related to CUNY Academic Commons - Bug #11174: Email notifications of spammed comment on groupblogResolved2019-02-26

History

#1 Updated by Boone Gorges 8 months ago

Hi Gina - Could you please share the content of the email notifications? The Commons sends a few different ones in different scenarios, and it would be helpful to see which is which.

#2 Updated by Gina Cherry 8 months ago

Screen shot of email 1: https://screencast.com/t/ODgtgKnBbTeT
Screen shot of email 2: https://screencast.com/t/ODgtgKnBbTeT

This happened on all 3 comments that I approved today.

#3 Updated by Boone Gorges 8 months ago

  • Assignee set to Raymond Hoh

Thanks, Gina. This is helpful.

Ray, could you please take a look to see if unspamming triggers double-notifications?

#4 Updated by Raymond Hoh 8 months ago

Hi Gina,

The link to screenshot 2 is the same as screenshot 1. If possible, can you provide the link to screenshot 2?

#5 Updated by Gina Cherry 7 months ago

Sorry about that. Here's the second screen shot: https://www.screencast.com/t/5tP5u2a2sqlc

#6 Updated by Boone Gorges 7 months ago

  • Target version set to 1.14.3

#7 Updated by Raymond Hoh 7 months ago

  • Related to Bug #8225: replies to a blog post activity item added

#8 Updated by Raymond Hoh 7 months ago

  • Status changed from New to In Progress

I was able to replicate this on cdev.

The duplicate problem occurs when recording non-member blog comments into the group activity stream. Recording blog comments into the group activity stream was implemented as part of the BP Groupblog plugin in #8225.

The issue here is another plugin, bp-include-non-member-comments, first records non-member blog comments into the activity stream. BP Groupblog then modifies this activity item so it is recorded into the group activity stream. Both save attempts triggers the BP Group Email Subscription plugin to record the same item into the wp_bpges_queued_item DB table.

Here's a quick backtrace:

// First save
do_action('wp_ajax_dim-comment'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, wp_ajax_dim_comment, wp_set_comment_status, do_action('wp_set_comment_status'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, bp_blogs_record_nonmember_comment_approved, bp_blogs_record_nonmember_comment, bp_blogs_record_activity, bp_activity_add, BP_Activity_Activity->save, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, ass_group_notification_activity

// Second save
do_action('wp_ajax_dim-comment'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, wp_ajax_dim_comment, wp_set_comment_status, wp_transition_comment_status, do_action('transition_comment_status'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, bp_activity_transition_post_type_comment_status, BP_Activity_Activity->save, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, ass_group_notification_activity

I decided to fix this in BPGES to ignore duplicate entries from being recorded here.

The alternative is patching bp-groupblog to bail out of bp_groupblog_transition_comment_status if the comment is anonymous and if bp-include-non-member-comments is active:
https://github.com/boonebgorges/bp-groupblog/blob/master/bp-groupblog.php#L1448

This might not be 100% foolproof, so I decided to go with the BPGES fix.

Boone, let me know what you think of the approach.

#9 Updated by Boone Gorges 7 months ago

Wow, thanks for tracking down, Ray!

I've merged the GES PR. Could I ask you to do the following?
- update the Commons with the change (I guess this should be a hotfix? leave it up to your judgment)
- run the necessary ALTER routines on our tables to bring the schema up to date

#10 Updated by Raymond Hoh 7 months ago

  • Category name set to Email Notifications
  • Status changed from In Progress to Resolved

Added as a hotfix here - https://github.com/cuny-academic-commons/cac/commit/b6969b875ad3e1f3a7a5b10bcb601d6558fe782c

- Ran ALTER TABLE wp_bpges_queued_items DROP INDEX group_id
- Attempted to run wp bpges install-database. But this returned some DB errors because of existing duplicate entries in the DB table.


WordPress database error Duplicate entry '{user_id}-{group_id}-{activity_id}-{type}' for key 'user_group_activity_type' for query ALTER TABLE wp_bpges_queued_items ADD UNIQUE KEY `user_group_activity_type` (`user_id`,`group_id`,`activity_id`,`type`) made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->_run_command_and_exit, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, BPGES_Command->install_database, bpges_install_queued_items_table, dbDelta

Next, I removed all the duplicates with DELETE FROM wp_bpges_queued_items WHERE id = X. After removing all the duplicate entries, the CLI command finally worked and the indexes have been updated:

wp db query 'SHOW INDEX FROM wp_bpges_queued_items'
+-----------------------+------------+--------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table                 | Non_unique | Key_name                 | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------------------+------------+--------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| wp_bpges_queued_items |          0 | PRIMARY                  |            1 | id            | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          0 | user_group_activity_type |            1 | user_id       | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          0 | user_group_activity_type |            2 | group_id      | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          0 | user_group_activity_type |            3 | activity_id   | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          0 | user_group_activity_type |            4 | type          | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | user_id                  |            1 | user_id       | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | activity_id              |            1 | activity_id   | A         |         534 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | user_group_type_date     |            1 | user_id       | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | user_group_type_date     |            2 | type          | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | user_group_type_date     |            3 | date_recorded | A         |        3204 |     NULL | NULL   |      | BTREE      |         |               |
| wp_bpges_queued_items |          1 | group_id                 |            1 | group_id      | A         |         110 |     NULL | NULL   |      | BTREE      |         |               |
+-----------------------+------------+--------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

#11 Updated by Raymond Hoh 7 months ago

Side note: I noticed a lot of older items in the wp_bpges_queued_items DB table, dating as far back as May 22nd. Is it safe to delete everything older than a week?

#12 Updated by Boone Gorges 7 months ago

Thank you, Ray!

I checked the old items in the queue table and you're right that they're no longer needed. The vast majority are instances of the bug fixed a few weeks ago where immediately queued items sometimes wouldn't sent. I've cleared them all out.

#13 Updated by Gina Cherry 5 months ago

I'm either still having this issue or am having this issue again (I can't remember if anyone commented on a blog post between the time when this was fixed and now). Both comments on our most recent post generated duplicate email notifications.

#14 Updated by Raymond Hoh 5 months ago

  • Related to Bug #11160: Return of duplicate email notifactions for blog comments added

#15 Updated by Raymond Hoh 5 months ago

  • Related to Bug #11174: Email notifications of spammed comment on groupblog added

Also available in: Atom PDF