User tests: Successful: Unsuccessful:
Use specified application instead of current application in Joomla\CMS\Router\Route::link()
.
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();
Error: Failed to start application
No.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Here is still the live_site setting:
joomla-cms/libraries/src/Uri/Uri.php
Line 141 in fe597ef
Or do you mean something different?
Yes, I saw that. But the option is not present in configuration form. It can only be set by manually editing configuration.php
?
yes. IIRC this was always the case right?
No idea. I guess it make sense not to expose it because setting it to incorrect value would cause sites to break.
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.
No idea how to proceed here then
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.
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.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-08-08 20:08:56 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
?
Removed: ? |
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.
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?