From d5340a87dce5939cd99dd8e25c55cc1bc7af679e Mon Sep 17 00:00:00 2001 From: Cam Findlay Date: Mon, 3 Jul 2017 13:56:26 +1200 Subject: [PATCH] FEATURE config to disable sending spam notifications --- code/extensions/BlogPostNotifications.php | 12 ++++++++++++ docs/en/configuring-notifications.md | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 docs/en/configuring-notifications.md diff --git a/code/extensions/BlogPostNotifications.php b/code/extensions/BlogPostNotifications.php index e3d7ca2..f733b04 100644 --- a/code/extensions/BlogPostNotifications.php +++ b/code/extensions/BlogPostNotifications.php @@ -7,6 +7,12 @@ */ class BlogPostNotifications extends DataExtension { + /** + * Configure whether to send notifications even for spam comments + * @config + */ + private static $notification_on_spam = true; + /** * Notify all authors of notifications. * @@ -15,7 +21,13 @@ class BlogPostNotifications extends DataExtension */ public function updateNotificationRecipients(&$list, &$comment) { + //default is notification is on regardless of spam status $list = $this->owner->Authors(); + + // If comment is spam and notification are set to not send on spam clear the recipient list + if (Config::inst()->get(__CLASS__, 'notification_on_spam') == false && $comment->IsSpam) { + $list = array(); + } } /** diff --git a/docs/en/configuring-notifications.md b/docs/en/configuring-notifications.md new file mode 100644 index 0000000..6558838 --- /dev/null +++ b/docs/en/configuring-notifications.md @@ -0,0 +1,15 @@ +# Configuring notifications + +## Configuring whether notifications will send to authors of blogs if comments are spam + +Default behaviour using the `silverstripe/comment-notifications` module is to send notification to authors of comments occuring regardless if they are spam or not. + +In some cases you may wish to not send a notification email to an author if the comment is spam, this is a configurable option. + +Add the following into your yaml config: + +``` +BlogPostNotifications: + notification_on_spam: false +``` +