From c924fbdab76263fc5121c9073f51b0d63b129d64 Mon Sep 17 00:00:00 2001
From: Wolfgang Klinger <wolfgang@wazum.com>
Date: Tue, 9 Jan 2018 20:17:56 +0100
Subject: [PATCH] [FEATURE] Add possibility to use session data in TS
 conditions

Since the session API has been adjusted it is no longer possible
to access the (now protected) sesData property of the fe_user object.
Using TSFE:fe_user|sesData|foo|bar in a TS condition will trigger
a deprecation log entry.

Instead a cleaner approach is now available:
 [globalVar = session:foo|bar = 1234567]

Resolves: #83506
Releases: master
Change-Id: Idbb079334186eac1dfe062a71a601e556a9bd247
Reviewed-on: https://review.typo3.org/55310
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
---
 ...-83506-DeprecateFeUserSesDataCondition.rst | 34 +++++++++++++++++++
 ...3506-RetrieveSessionDataInTSConditions.rst | 23 +++++++++++++
 .../ConditionMatching/ConditionMatcher.php    |  9 ++++-
 .../ConditionMatcherTest.php                  | 15 ++++++--
 4 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-83506-DeprecateFeUserSesDataCondition.rst
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-83506-RetrieveSessionDataInTSConditions.rst

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83506-DeprecateFeUserSesDataCondition.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83506-DeprecateFeUserSesDataCondition.rst
new file mode 100644
index 000000000000..84902ad82ed8
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83506-DeprecateFeUserSesDataCondition.rst
@@ -0,0 +1,34 @@
+
+.. include:: ../../Includes.txt
+
+===============================================================================
+Deprecation: #83506 - Deprecated usage of TSFE:fe_user|sesData in TS conditions
+===============================================================================
+
+See :issue:`83506`
+
+Description
+===========
+
+Since the session API has been adjusted it is no longer possible
+to access the (now protected) sesData property of the fe_user object.
+
+
+Impact
+======
+
+Using :typoscript:`[globalVar = TSFE:fe_user|sesData|foo|bar = 1234567]` will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any installation using the old value TSFE:fe_user|sesData in a TypoScript condition.
+
+
+Migration
+=========
+
+Use :typoscript:`[globalVar = session:foo|bar = 1234567]` instead.
+
+.. index:: Frontend, TypoScript, NotScanned
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83506-RetrieveSessionDataInTSConditions.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83506-RetrieveSessionDataInTSConditions.rst
new file mode 100644
index 000000000000..b7ea80ff6aa2
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-83506-RetrieveSessionDataInTSConditions.rst
@@ -0,0 +1,23 @@
+.. include:: ../../Includes.txt
+
+========================================================
+Feature: #83506 - Retrieve session data in TS conditions
+========================================================
+
+See :issue:`83506`
+
+Description
+===========
+
+As the session API has been modified, it is no longer possible to access
+session data in TypoScript conditions by using the formerly public
+property ``sesData`` of the frontend user object.
+
+So now there is a more direct way using the keyword ``session``
+with the same function:
+
+.. code-block:: typoscript
+
+   [globalVar = session:foo|bar = 1234567]
+
+.. index:: Frontend, TypoScript
diff --git a/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php b/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
index 439e064e1f11..a2bb7fa6faf0 100644
--- a/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
+++ b/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
@@ -88,7 +88,7 @@ class ConditionMatcher extends AbstractConditionMatcher
     }
 
     /**
-     * Returns GP / ENV / TSFE vars
+     * Returns GP / ENV / TSFE / session vars
      *
      * @example GP:L
      * @example TSFE:fe_user|sesData|foo|bar
@@ -109,11 +109,18 @@ class ConditionMatcher extends AbstractConditionMatcher
                 switch ((string)trim($vars[0])) {
                     case 'TSFE':
                         if (strpos($vars[1], 'fe_user|sesData|') === 0) {
+                            trigger_error(
+                                'Condition on TSFE|fe_user|sesData is deprecated and will be removed in TYPO3 CMS 10',
+                                E_USER_DEPRECATED
+                            );
                             $val = $this->getSessionVariable(substr($vars[1], 16));
                         } else {
                             $val = $this->getGlobal('TSFE|' . $vars[1]);
                         }
                         break;
+                    case 'session':
+                        $val = $this->getSessionVariable($vars[1]);
+                        break;
                     default:
                 }
             }
diff --git a/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php b/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
index 8a1e0f88c0d2..afa8c267ac9a 100644
--- a/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
+++ b/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
@@ -615,13 +615,22 @@ class ConditionMatcherTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
         $GLOBALS['TSFE']->testSimpleObject = new \stdClass();
         $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
 
+        $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
+        $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
+    }
+
+    /**
+     * Tests whether the generic fetching of variables works with the namespace 'session'.
+     *
+     * @test
+     */
+    public function genericGetVariablesSucceedsWithNamespaceSession()
+    {
         $prophecy = $this->prophesize(FrontendUserAuthentication::class);
         $prophecy->getSessionData(Argument::exact('foo'))->willReturn(['bar' => 1234567]);
         $GLOBALS['TSFE']->fe_user = $prophecy->reveal();
 
-        $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
-        $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
-        $this->assertTrue($this->matchCondition->match('[globalString = TSFE:fe_user|sesData|foo|bar = 1234567]'));
+        $this->assertTrue($this->matchCondition->match('[globalString = session:foo|bar = 1234567]'));
     }
 
     /**
-- 
GitLab