Force synchronous, non-fail-safe email sending while debugging
authorAlexander Ebert <ebert@woltlab.com>
Tue, 19 Dec 2017 18:44:04 +0000 (19:44 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 19 Dec 2017 18:44:10 +0000 (19:44 +0100)
Closes #2501

wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php
wcfsetup/install/files/lib/system/email/Email.class.php

index 6ae3f32f1b3d3a78640a5ede66ba8698793cd124..6452a2d7782d6438e3e65b3c622e5636e6c261e4 100644 (file)
@@ -84,9 +84,10 @@ class BackgroundQueueHandler extends SingletonFactory {
         * don't want to miss the automated error handling mechanism of the
         * queue.
         * 
-        * @param       AbstractBackgroundJob   $job    The job to perform.
+        * @param       AbstractBackgroundJob   $job                            The job to perform.
+        * @param       boolean                 $debugSynchronousExecution      Disables fail-safe mechanisms, errors will no longer be suppressed.
         */
-       public function performJob(AbstractBackgroundJob $job) {
+       public function performJob(AbstractBackgroundJob $job, $debugSynchronousExecution = false) {
                $user = WCF::getUser();
                
                try {
@@ -97,6 +98,11 @@ class BackgroundQueueHandler extends SingletonFactory {
                        $job->perform();
                }
                catch (\Throwable $e) {
+                       // do not suppress exceptions for debugging purposes, see https://github.com/WoltLab/WCF/issues/2501
+                       if ($debugSynchronousExecution) {
+                               throw $e;
+                       }
+                       
                        // gotta catch 'em all
                        $job->fail();
                        
@@ -113,6 +119,11 @@ class BackgroundQueueHandler extends SingletonFactory {
                        }
                }
                catch (\Exception $e) {
+                       // do not suppress exceptions for debugging purposes, see https://github.com/WoltLab/WCF/issues/2501
+                       if ($debugSynchronousExecution) {
+                               throw $e;
+                       }
+                       
                        // gotta catch 'em all
                        $job->fail();
                        
index 361c9ab905e20f1ba23a1389bfd570f0c5e3d200..efb8f63daadad2cf96517803ff58079d6d83c189 100644 (file)
@@ -513,8 +513,17 @@ class Email {
         */
        public function send() {
                $jobs = $this->getJobs();
-               BackgroundQueueHandler::getInstance()->enqueueIn($jobs);
-               BackgroundQueueHandler::getInstance()->forceCheck();
+               
+               // force synchronous execution, see https://github.com/WoltLab/WCF/issues/2501
+               if (ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS) {
+                       foreach ($jobs as $job) {
+                               BackgroundQueueHandler::getInstance()->performJob($job);
+                       }
+               }
+               else {
+                       BackgroundQueueHandler::getInstance()->enqueueIn($jobs);
+                       BackgroundQueueHandler::getInstance()->forceCheck();
+               }
        }
        
        /**