ext-solr
ext-solr copied to clipboard
[BUG] CliEnvironment->initialize - Consecutive tasks will create absolute links using CLI
Ext Solr Version: 7.5.2 TYPO3 Version: 8.7.18
Scheduler is started using CLI dispatcher with an absolute path on the server.
Problem: Consecutive tasks will use wrong $_SERVER variables which causes typolink to create wrong urls like: /path/to/my/project/news/my-news.html instead of /news/my-news.html
Explanation: Running the scheduler using CLI will run multiple tasks consecutive. Following lines will now create an issue:
$cliEnvironment = GeneralUtility::makeInstance(CliEnvironment::class);
$cliEnvironment->backup();
$cliEnvironment->initialize($this->getWebRoot());
With the first task everything will run fine because initialize is called an vars like $_SERVER['SCRIPT_NAME'] will be filled. In the next task however initialize will never run again because CliEnvironment->initialize checks if it's already initialized, which it is because it's a singleton. Because initialize is never called again and the backup before the first task will be applied $_SERVER vars will be the initial ones for every task after the first one.
First Task: $_SERVER['SCRIPT_NAME'] = /index.php Second Task: $_SERVER['SCRIPT_NAME'] = /path/to/my/project/typo3/cli_dispatch.phpsh
Maybe I overlooked something but I think there is something wrong. Is this behavior intended?
Thought it's an mistake myself, so still an issue.
I can confirm this issue. We were also running multiple SOLR-Tasks at once and the later ones generated urls with the document root and path to typo3 binary prepended "/path/to/my/project//typo3/sysext/core/bin/###correctURL###".
I believe this must be a LTS 8 TYPO3 CORE issue. I am running into the exact same problem with aimeos and the links generated to log in.
anyone ever found a solution for this? I'm going crazy with this, can't find a solution
In my case I can fix it by just calling $this->backup();
at the end of CliEnvironment::initialize()
/**
* Initializes the frontend related server variables for the cli context.
*
* @param string $webRoot
* @param string $scriptFileName
* @param string $phpSelf
* @param string $scriptName
* @throws WebRootAllReadyDefinedException
* @return bool
*/
public function initialize($webRoot, $scriptFileName = PATH_site, $phpSelf = '/index.php', $scriptName = '/index.php')
{
// if the environment has be initialized once, we do not need to initialize it twice.
if ($this->isInitialized) {
return false;
}
if (defined('TYPO3_PATH_WEB')) {
throw new WebRootAllReadyDefinedException('TYPO3_PATH_WEB is already defined');
}
define('TYPO3_PATH_WEB', $webRoot);
$_SERVER['SCRIPT_FILENAME'] = $scriptFileName;
$_SERVER['PHP_SELF'] = $phpSelf;
$_SERVER['SCRIPT_NAME'] = $scriptName;
// 2021-09-23 - dirty fix for broken news index
$this->backup();
$this->isInitialized = true;
return true;
}