Call `finalizeLog` for all exceptions within a chain
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 11:57:26 +0000 (13:57 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 27 Aug 2021 11:57:26 +0000 (13:57 +0200)
wcfsetup/install/files/lib/core.functions.php

index cb5758411d013945431c75d673c9146434adef57..f98bb53f37509607468d5444e152bc908d5ff451 100644 (file)
@@ -254,13 +254,17 @@ namespace wcf\functions\exception {
                file_put_contents($logFile, $entry, FILE_APPEND);
 
                // let the Exception know it has been logged
-               if (
-                       $e instanceof ILoggingAwareException
-                       || (method_exists($e, 'finalizeLog') && is_callable([$e, 'finalizeLog']))
-               ) {
-                       /** @var ILoggingAwareException $e */
-                       $e->finalizeLog($exceptionID, $logFile);
+               $prev = $e;
+               do {
+                       if (
+                               $prev instanceof ILoggingAwareException
+                               || (method_exists($prev, 'finalizeLog') && is_callable([$prev, 'finalizeLog']))
+                       ) {
+                               /** @var ILoggingAwareException $prev */
+                               $prev->finalizeLog($exceptionID, $logFile);
+                       }
                }
+               while ($prev = $prev->getPrevious());
 
                return $exceptionID;
        }