From 276a6976e4db37bbd93e426346d94250936a4226 Mon Sep 17 00:00:00 2001
From: Achim Fritz <achim.fritz@b13.de>
Date: Fri, 25 Aug 2023 16:11:39 +0200
Subject: [PATCH] [TASK] Add UserSession to BeforeUserLogoutEvent

Resolves: #101754
Related: #100307
Releases: main, 12.4
Change-Id: I43c43f1635fd789e3f035e9840d37fb70528cb66
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80682
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Authentication/AbstractUserAuthentication.php        | 2 +-
 .../Authentication/Event/BeforeUserLogoutEvent.php       | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php b/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
index 71d4ede7c6bc..9d99df6c7b2d 100644
--- a/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
+++ b/typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php
@@ -875,7 +875,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
 
         $dispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class);
 
-        $event = new BeforeUserLogoutEvent($this);
+        $event = new BeforeUserLogoutEvent($this, $this->userSession);
         $event = $dispatcher->dispatch($event);
 
         if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'] ?? null)) {
diff --git a/typo3/sysext/core/Classes/Authentication/Event/BeforeUserLogoutEvent.php b/typo3/sysext/core/Classes/Authentication/Event/BeforeUserLogoutEvent.php
index 98246b515769..df69f7a6aeb5 100644
--- a/typo3/sysext/core/Classes/Authentication/Event/BeforeUserLogoutEvent.php
+++ b/typo3/sysext/core/Classes/Authentication/Event/BeforeUserLogoutEvent.php
@@ -18,6 +18,7 @@ declare(strict_types=1);
 namespace TYPO3\CMS\Core\Authentication\Event;
 
 use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
+use TYPO3\CMS\Core\Session\UserSession;
 
 /**
  * Event fired before a user is going to be actively logged out.
@@ -29,7 +30,8 @@ final class BeforeUserLogoutEvent
     private bool $shouldLogout = true;
 
     public function __construct(
-        private readonly AbstractUserAuthentication $user
+        private readonly AbstractUserAuthentication $user,
+        private readonly ?UserSession $userSession
     ) {
     }
 
@@ -52,4 +54,9 @@ final class BeforeUserLogoutEvent
     {
         return $this->shouldLogout;
     }
+
+    public function getUserSession(): ?UserSession
+    {
+        return $this->userSession;
+    }
 }
-- 
GitLab