Project

General

Profile

Actions

Bug #10800

closed

Duplicate email notifications on blog comments

Added by Gina Cherry over 5 years ago. Updated about 5 years ago.

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

0%

Estimated time:
Deployment actions:

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 itemResolvedRaymond Hoh2017-06-05

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

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

Actions
Actions #1

Updated by Boone Gorges over 5 years 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.

Actions #2

Updated by Gina Cherry over 5 years 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.

Actions #3

Updated by Boone Gorges over 5 years 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?

Actions #4

Updated by Raymond Hoh over 5 years ago

Hi Gina,

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

Actions #5

Updated by Gina Cherry over 5 years ago

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

Actions #6

Updated by Boone Gorges over 5 years ago

  • Target version set to 1.14.3
Actions #7

Updated by Raymond Hoh over 5 years ago

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

Updated by Raymond Hoh over 5 years 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.

Actions #9

Updated by Boone Gorges over 5 years 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

Actions #10

Updated by Raymond Hoh over 5 years 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      |         |               |
+-----------------------+------------+--------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
Actions #11

Updated by Raymond Hoh over 5 years 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?

Actions #12

Updated by Boone Gorges over 5 years 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.

Actions #13

Updated by Gina Cherry about 5 years 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.

Actions #14

Updated by Raymond Hoh about 5 years ago

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

Updated by Raymond Hoh about 5 years ago

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

Also available in: Atom PDF