? Success

User tests: Successful: Unsuccessful:

avatar SharkyKZ
SharkyKZ
6 Sep 2019

Summary of Changes

Use specified application instead of current application in Joomla\CMS\Router\Route::link().

Testing Instructions

  1. Run this CLI application:
const _JEXEC = 1;

if (file_exists(dirname(__DIR__) . '/defines.php'))
{
	require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
	define('JPATH_BASE', dirname(__DIR__));
	require_once JPATH_BASE . '/includes/defines.php';
}

require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
require_once JPATH_CONFIGURATION . '/configuration.php';

class Test extends JApplicationCli
{
	public function doExecute()
	{
		JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
		$url = JRoute::link('site', ContentHelperRoute::getCategoryRoute('8'));
		
		$this->out($url);
	}
}

JApplicationCli::getInstance('Test')->execute();
  1. Check that links in frontend and backend work like before.

Expected result

  1. SEF URL is displayed.
  2. Works like before.

Actual result

  1. Error: Failed to start application

Documentation Changes Required

No.

avatar SharkyKZ SharkyKZ - open - 6 Sep 2019
avatar SharkyKZ SharkyKZ - change - 6 Sep 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 Sep 2019
Category Libraries
avatar SharkyKZ SharkyKZ - change - 6 Sep 2019
The description was changed
avatar SharkyKZ SharkyKZ - edited - 6 Sep 2019
avatar SharkyKZ SharkyKZ - change - 6 Sep 2019
The description was changed
avatar SharkyKZ SharkyKZ - edited - 6 Sep 2019
avatar SharkyKZ
SharkyKZ - comment - 6 Sep 2019

Looks like there are more issues. Can't generate absolute site URLs in CLI. In the past there was $live_site global config option which solved this. Why was it removed?

avatar zero-24
zero-24 - comment - 6 Sep 2019

Here is still the live_site setting:

$live_site = ($uri->isSsl()) ? str_replace('http://', 'https://', $config->get('live_site')) : $config->get('live_site');

Or do you mean something different?

avatar SharkyKZ
SharkyKZ - comment - 6 Sep 2019

Yes, I saw that. But the option is not present in configuration form. It can only be set by manually editing configuration.php?

avatar zero-24
zero-24 - comment - 6 Sep 2019

yes. IIRC this was always the case right?

avatar SharkyKZ
SharkyKZ - comment - 7 Sep 2019

No idea. I guess it make sense not to expose it because setting it to incorrect value would cause sites to break.

avatar mbabker
mbabker - comment - 7 Sep 2019

That variable has never been exposed in the UI. So you're right in that manual edits are the only way to get it in there.

avatar SharkyKZ
SharkyKZ - comment - 9 Sep 2019

No idea how to proceed here then ? .

avatar HLeithner
HLeithner - comment - 9 Sep 2019

First thought would be to add a "primary url" which is used if no url can be provided by the system.
Changing the live_site changes the behavior for the normal website too and maybe make multi domain sites harder.

Also it should be easily possible to override the used url on cli call (Environment variable or url parameter). A warning on bootstrapping the cli application if no url is set would make sense.

Any comment is welcome.

avatar gaelicwinter
gaelicwinter - comment - 5 Oct 2019

I have the same issue. My cli script uses a third party component to do some work so I don't have easy access to the way it operates. Ultimately it gets links from the component which emails them out. I've worked around JUri by using this at the start of my loop. The params are from a plugin where I can get the user to specify the site url, similar to $config's $live_site:

$site_root = $this->params->get('site_root', '');
$uriHelper = new \Joomla\Uri\UriHelper();
$uri = $uriHelper::parse_url($site_root);

// This probably works because http would be rewritten to https in .htaccess or by J, or else we don't care
$_SERVER['HTTPS'] = isset($uri['scheme']) ? ($uri['scheme'] === 'https' ? 'on' : 'off') : (JFactory::getConfig()->get('force_ssl') ? 'on' : 'off');
$_SERVER['HTTP_HOST'] = isset($uri['host']) ? $uri['host'] : '';
$_SERVER['REQUEST_URI'] =  (isset($uri['path']) ? $uri['path'] : '') . '/' . str_replace('\\', '/', $_SERVER['PHP_SELF']);
$_SERVER['SCRIPT_NAME'] = (isset($uri['path']) ? $uri['path'] : '') . '/index.php';

Then when I need to get a site link I use:

$router = \Joomla\CMS\Factory::getApplication('site')->getRouter('site');
$uri = $router->build($link);
$link = $uri->toString();

// ToDo: HACK remove /base from link as its added again from JUri in caller
$base = \Joomla\CMS\Uri\Uri::base(true);
$link = substr($link, strlen($base) + 1);

This is not guaranteed to work on all servers or in all circumstances. If it fails, then it just fails to produce valid links.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/26180.

avatar zero-24 zero-24 - change - 8 Aug 2021
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2021-08-08 20:08:56
Closed_By zero-24
Labels Added: ?
Removed: ?
avatar zero-24 zero-24 - close - 8 Aug 2021
avatar zero-24
zero-24 - comment - 8 Aug 2021

Dear @SharkyKZ

in preperation of the upcomming release of Joomla 3.10 we have used GitHubs rename feature to rename the staging branch into 3.10-dev. Usually GitHub moves all existing PRs towards the new branch just fine, but here it didnt work. The reason seems to be that the fork of the CMS that was used as base for this PR has been deleted so GitHub does no longer have a base to rebase the PR against the new branch and we are also not able to reopen the PR. For that reason GitHub closed this PR in my name, when this issue is still valid It would require a new PR against the new 3.10-dev or 4.0-dev branch.

Add a Comment

Login with GitHub to post a comment