Issue Bug Closed

#103669Backend Preview of "planned" pages throw 503 on PHP 8.2

Johannes Rebhan 04/18/24, 17:39 updated 04/19/24, 05:46

Description

It seems like this piece of code in the PreviewSimulator is not “precise” enough for PHP 8.2 and throws a 503 if you try to preview a page from the backend, that has a start date in the future:

    protected function simulateDate(ServerRequestInterface $request): bool
    {
        $queryTime = $request->getQueryParams()['ADMCMD_simTime'] ?? false;
        if (!$queryTime) {
            return false;
        }

        $GLOBALS['SIM_EXEC_TIME'] = $queryTime;
        $GLOBALS['SIM_ACCESS_TIME'] = $queryTime - $queryTime % 60;
        $this->context->setAspect(
            'date',
            GeneralUtility::makeInstance(
                DateTimeAspect::class,
                (new \DateTimeImmutable())->setTimestamp($queryTime)
            )
        );
        return true;
    }
DateTimeImmutable::setTimestamp(): Argument #1 ($timestamp) must be of type int, string given

Suggest to add a typecast early on to convert $queryTime string to the int it actually is.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 3

  1. Johannes Rebhan commented 04/18/24, 18:12

    Something like that maybe?

        protected function simulateDate(ServerRequestInterface $request): bool
        {
            $params = $request->getQueryParams();
            if(!isset($params['ADMCMD_simTime'])){
                return false;
            }
    
            $queryTime = (int)$params['ADMCMD_simTime'];
    
            $simulatedDate = new \DateTimeImmutable('@' . $queryTime);
            if (!$simulatedDate) {
                return false;
            }
    
            $GLOBALS['SIM_EXEC_TIME'] = $queryTime;
            $GLOBALS['SIM_ACCESS_TIME'] = $queryTime - $queryTime % 60;
            $this->context->setAspect(
                'date',
                GeneralUtility::makeInstance(
                    DateTimeAspect::class,
                    $simulatedDate
                )
            );
            return true;
        }
  2. Georg Ringer changed Duplicates #103588 04/19/24, 05:46

  3. Georg Ringer commented and changed status New Closed Tags type 04/19/24, 05:46

    thanks for creating the issue. this has been solved with #103588 – therefore closing this issue as duplicate