Fixed getThreadFromUrl fails when executed from CLI

Xon

Well-known member
Affected version
2.2.14
The failure of \XF\Repository\Thread::getThreadFromUrl function when executed from the CLI is due to the \XF\Request not being in the expected state.

getThreadFromUrl eventually calls \XF\Request::getHost which returns false, which results in the routeToController method not getting the data it expects and thus failing to match
PHP:
	public function getThreadFromUrl($url, $type = null, &$error = null)
	{
		$routePath = $this->app()->request()->getRoutePathFromUrl($url, true);
...
	public function getHost()
	{
		$host = $this->getServer('HTTP_HOST');
		if (!$host)
		{
			$host = $this->getServer('SERVER_NAME');
			$port = intval($this->getServer('SERVER_PORT'));
			if ($port && $port != 80 && $port != 443)
			{
				$host .= ":$port";
			}
		}

		return $host;
	}

From the CLI context, both HTTP_HOST and SERVER_NAME aren't set.

A workaround would be something $host = parse_url($app->options()->boardUrl, PHP_URL_HOST) and storing it into $_SERVER['HTTP_HOST'] (well \XF\Request::$server) when the server variables that are expected don't exist.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.8).

Change log:
Pull protocol and host from board URL in CLI contexts
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom