From 306143ba7ac72085084f16c8f74358e1a30a4813 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 19 Dec 2017 19:44:04 +0100 Subject: [PATCH] Force synchronous, non-fail-safe email sending while debugging Closes #2501 --- .../background/BackgroundQueueHandler.class.php | 15 +++++++++++++-- .../files/lib/system/email/Email.class.php | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index 6ae3f32f1b..6452a2d778 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/system/email/Email.class.php b/wcfsetup/install/files/lib/system/email/Email.class.php index 361c9ab905..efb8f63daa 100644 --- a/wcfsetup/install/files/lib/system/email/Email.class.php +++ b/wcfsetup/install/files/lib/system/email/Email.class.php @@ -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(); + } } /** -- 2.20.1