[FEATURE] Add possibility to use session data in TS conditions 10/55310/15
authorWolfgang Klinger <wolfgang@wazum.com>
Tue, 9 Jan 2018 19:17:56 +0000 (20:17 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 14 Feb 2018 09:43:15 +0000 (10:43 +0100)
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>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-83506-DeprecateFeUserSesDataCondition.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-83506-RetrieveSessionDataInTSConditions.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

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 (file)
index 0000000..84902ad
--- /dev/null
@@ -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 (file)
index 0000000..b7ea80f
--- /dev/null
@@ -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
index 439e064..a2bb7fa 100644 (file)
@@ -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:
                 }
             }
index 8a1e0f8..afa8c26 100644 (file)
@@ -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]'));
     }
 
     /**