Only test instant emails for notifications triggered once
authorMatthias Schmidt <gravatronics@live.com>
Fri, 25 Aug 2017 09:13:05 +0000 (11:13 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 25 Aug 2017 09:13:05 +0000 (11:13 +0200)
See #2359

wcfsetup/install/files/acp/templates/devtoolsNotificationTestDialog.tpl
wcfsetup/install/files/lib/data/user/notification/event/UserNotificationEventAction.class.php

index 611aeb7e31ca8482e93157d75df477527334f384..8bd53e0b38d9af78c12a885ee079001abd2f47e1 100644 (file)
@@ -49,7 +49,7 @@
                                                <dt>{lang}wcf.acp.devtools.notificationTest.instantEmail{/lang}</dt>
                                                <dd><pre>{$event[instantEmail]}</pre></dd>
                                        </dl>
-                               {else}
+                               {elseif $event[instantEmailException]|isset}
                                        <dl>
                                                <dt>{lang}wcf.acp.devtools.notificationTest.instantEmail.exception{/lang}</dt>
                                                <dd><pre>{$event[instantEmailException]}</pre></dd>
                
                <dl>
                        {foreach from=$events item=event}
-                               <dt>{$event[description]}</dt>
-                               <dd><pre>{if $event[instantEmail]|isset}{$event[instantEmail]}{else}{$event[instantEmailException]}{/if}</pre></dd>
+                               {if $event[instantEmail]|isset || $event[instantEmailException]|isset}
+                                       <dt>{$event[description]}</dt>
+                                       <dd><pre>{if $event[instantEmail]|isset}{$event[instantEmail]}{else}{$event[instantEmailException]}{/if}</pre></dd>
+                               {/if}
                        {/foreach}
                </dl>
        </section>
index e875933e4bfa15cc2ccad3759f98676658c59672..f82b580deff368110b3d4948aba7917810ddb9dc 100644 (file)
@@ -162,16 +162,19 @@ class UserNotificationEventAction extends AbstractDatabaseObjectAction {
                                        $errors++;
                                }
                                
-                               try {
-                                       $eventData['instantEmail'] = TestableUserNotificationEventHandler::getInstance()->getEmailBody($event, 'instant');
-                               }
-                               catch (\Exception $e) {
-                                       $eventData['instantEmailException'] = $getRenderedException($e);
-                                       $errors++;
-                               }
-                               catch (\Throwable $e) {
-                                       $eventData['instantEmailException'] = $getRenderedException($e);
-                                       $errors++;
+                               // for instant emails, a notification can only be triggered once
+                               if ($event->getNotification()->timesTriggered == 1) {
+                                       try {
+                                               $eventData['instantEmail'] = TestableUserNotificationEventHandler::getInstance()->getEmailBody($event, 'instant');
+                                       }
+                                       catch (\Exception $e) {
+                                               $eventData['instantEmailException'] = $getRenderedException($e);
+                                               $errors++;
+                                       }
+                                       catch (\Throwable $e) {
+                                               $eventData['instantEmailException'] = $getRenderedException($e);
+                                               $errors++;
+                                       }
                                }
                        }