Bug #81174
closedAdmin panel: Simulate time doesn't recognize accessTimeStamp
100%
Description
It is not possible to simulate a time in admin panel currently. Tested it in two instances of the same project, development (local) and production.
#1462820645: accessTimeStamp needs to be set to an integer value, but is empty! Maybe $GLOBALS['SIM_ACCESS_TIME'] has been overridden somewhere? (More information) RuntimeException thrown in file […]/typo3_src-8.7.1/typo3/sysext/core/Classes/Database/Query/Restriction/StartTimeRestriction.php in line 55.
PHP version 7.0 and 7.1 tested. Also different datetimes tested. Input field filled with e.g. '0:00 19-5-2017'. I don't think that any extension or configuration file is overriding SIM_ACCESS_TIME like mentioned in the error message.
Is anyone able to confirm this issue?
Updated by Steve Weise over 7 years ago
Is anyone able to confirm this issue?
Hi Arne-Kolja,
I can confirm this issue. We use php 7.0 and TYPO3 8.7.1.
I've searched every extension and configuration and none of these override the SIM_ACCESS_TIME.
Updated by Arne-Kolja Bachstein over 7 years ago
- Priority changed from Should have to Must have
Updated by Steve Weise over 7 years ago
I've debugged the core.
Just a little information for myself:
The var $GLOBALS['SIM_ACCESS_TIME'] is first set in class TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::initializeGlobalTimeTrackingVariables():
protected static function initializeGlobalTimeTrackingVariables()
{
// Set PARSETIME_START to the system time in milliseconds.
$GLOBALS['PARSETIME_START'] = GeneralUtility::milliseconds();
// Microtime of (nearly) script start
$GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(true);
// EXEC_TIME is set so that the rest of the script has a common value for the script execution time
$GLOBALS['EXEC_TIME'] = time();
// $ACCESS_TIME is a common time in minutes for access control
$GLOBALS['ACCESS_TIME'] = $GLOBALS['EXEC_TIME'] - $GLOBALS['EXEC_TIME'] % 60;
// $SIM_EXEC_TIME is set to $EXEC_TIME but can be altered later in the script if we want to
// simulate another execution-time when selecting from eg. a database
$GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
// If $SIM_EXEC_TIME is changed this value must be set accordingly
$GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
}
After that the class \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController overrides the var in the method clear_preview():
public function clear_preview()
{
$this->showHiddenPage = false;
$this->showHiddenRecords = false;
$GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
$GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
$this->fePreview = 0;
}
In the method clear_preview() the vars $GLOBALS['EXEC_TIME'] and $GLOBALS['ACCESS_TIME'] are correct.
After that, in method TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->determineId() the time is overriden in here:
public function determineId() {
//...
$simTime = $backendUser->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
if ($simTime) {
$GLOBALS['SIM_EXEC_TIME'] = $simTime;
$GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
}
//...
}
The accessTimeStamp is now set to 0 in \TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction and the SIM_EXEC_TIME is "14:59 1-2-2017".
The problem:
After the $GLOBALS['EXEC_TIME'] and $GLOBALS['ACCESS_TIME'] has been set, the SIM_EXEC_TIME is "14:59 1-2-2017" in the class EndTimeRestriction. But it must be an timestamp (f.e. 1496145720)!
Updated by Steve Weise over 7 years ago
The solution:
In the method determineId() the var $simTime should be ignored, if it's not an unix timestamp OR it must be parsed to unix timestamp, if it's an string.
For example:
public function determineId() {
//...
$simTime = $backendUser->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
if ($simTime) {
// convert String to unix timestamp
if(preg_match("/^\d+\:\d+\s\d+\-\d+\-\d+$/",$simTime)) {
$dtime = \DateTime::createFromFormat("G:i j-n-Y", $simTime);
$simTime = $dtime->getTimestamp();
}
$GLOBALS['SIM_EXEC_TIME'] = $simTime;
$GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
}
//...
}
Updated by Thorben Nissen over 7 years ago
I took a look into this, because one of our clients reported that to us. I compared the behaviour with CMS 7.6. The problem is not the processing in the FrontendController. The problem ist, that both parameters (TSFE_ADMIN_PANEL[preview_simulateDate]_hr and TSFE_ADMIN_PANEL[preview_simulateDate]) are submitted. In 7.6 the "_hr" field comes first. In 8.7 the "_hr" field comes after the hidden field, which leads to overriding the timestamp with the human readable date string.
You can just move the hidden field for the timestamp after the _hr field in the admin panel and it works again. I'll get in touch with the core team to ask how this should be solved.
Updated by Gerrit Code Review over 7 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/53230
Updated by Gerrit Code Review over 7 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/53230
Updated by Gerrit Code Review over 7 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/53238
Updated by Thorben Nissen over 7 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 05a10ff61dbe789cb0fe5f5f342af46201dd823a.