From 030c5cdd255b4476ade043a11c6ccf7923d58a4e Mon Sep 17 00:00:00 2001
From: Mathias Brodala <mbrodala@pagemachine.de>
Date: Tue, 3 Mar 2015 15:44:11 +0100
Subject: [PATCH] [BUGFIX] Fix access to time tracker in eID scripts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

During refactoring of request handling setup of the global time
tracker was removed for eID scripts.

This also fixes the setup order in the frontend request handler
since this happened before the "preprocessRequest" hook was executed
in the old index_ts.php

Resolves: #65488
Releases: master
Change-Id: I5b0c63db37360039fdb9d9e0ff29adfa38da22c5
Reviewed-on: http://review.typo3.org/37503
Reviewed-by: Juan Manuel Vergés Solanas <juanmanuel.vergessolanas@gmail.com>
Tested-by: Juan Manuel Vergés Solanas <juanmanuel.vergessolanas@gmail.com>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
---
 .../frontend/Classes/EidRequestHandler.php    | 13 ++++++++++++
 .../frontend/Classes/RequestHandler.php       | 20 +++++++++----------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/EidRequestHandler.php b/typo3/sysext/frontend/Classes/EidRequestHandler.php
index 804d768c0260..fc4910ab68e4 100644
--- a/typo3/sysext/frontend/Classes/EidRequestHandler.php
+++ b/typo3/sysext/frontend/Classes/EidRequestHandler.php
@@ -46,6 +46,19 @@ class EidRequestHandler implements RequestHandlerInterface {
 	 * @return void
 	 */
 	public function handleRequest() {
+		// Timetracking started
+		$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
+		if (empty($configuredCookieName)) {
+			$configuredCookieName = 'be_typo_user';
+		}
+		if ($_COOKIE[$configuredCookieName]) {
+			$GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
+		} else {
+			$GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
+		}
+
+		$GLOBALS['TT']->start();
+
 		// Hook to preprocess the current request
 		if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
 			foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
diff --git a/typo3/sysext/frontend/Classes/RequestHandler.php b/typo3/sysext/frontend/Classes/RequestHandler.php
index 85d2ea109054..ac01b3a4fe7f 100644
--- a/typo3/sysext/frontend/Classes/RequestHandler.php
+++ b/typo3/sysext/frontend/Classes/RequestHandler.php
@@ -50,16 +50,6 @@ class RequestHandler implements RequestHandlerInterface {
 	 * @return void
 	 */
 	public function handleRequest() {
-		// Hook to preprocess the current request:
-		if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
-			foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
-				$hookParameters = array();
-				GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
-			}
-			unset($hookFunction);
-			unset($hookParameters);
-		}
-
 		// Timetracking started
 		$configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
 		if (empty($configuredCookieName)) {
@@ -73,6 +63,16 @@ class RequestHandler implements RequestHandlerInterface {
 
 		$GLOBALS['TT']->start();
 
+		// Hook to preprocess the current request:
+		if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
+			foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
+				$hookParameters = array();
+				GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
+			}
+			unset($hookFunction);
+			unset($hookParameters);
+		}
+
 		/** @var $GLOBALS['TSFE'] \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
 		$GLOBALS['TSFE'] = GeneralUtility::makeInstance(
 			\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
-- 
GitLab