No Code Attached Yet bug
avatar GeraintEdwards
GeraintEdwards
5 Sep 2022

Steps to reproduce the issue

  1. Unzip and upload this file to your cli folder - https://www.yoursites.net/actionlogsproblem.zip
  2. Run the script with the FULL path to the cli script e.g. php /var/www/clients/j41/cli/actionlogsproblem.php

Expected result

No errors

Actual result

RuntimeException {#233
#message: "Could not parse the requested URI http:///var/www/clients/j41/cli/actionlogsproblem.php"
#code: 0
#file: "/var/www/clients/j41/libraries/vendor/joomla/uri/src/AbstractUri.php"
#line: 373
trace: {
/var/www/clients/j41/libraries/vendor/joomla/uri/src/AbstractUri.php:373 { …}
/var/www/clients/j41/libraries/src/Uri/Uri.php:290 {
Joomla\CMS\Uri\Uri->parse($uri)^
› {
› return parent::parse($uri);
› }
}
/var/www/clients/j41/libraries/vendor/joomla/uri/src/AbstractUri.php:111 { …}
...

System information (as much as possible)

Joomla 4.2

Additional comments

The test script is attempting to load the ActionLogs model using
$model = \Joomla\CMS\Factory::getApplication()->bootComponent('com_actionlogs') ->getMVCFactory()->createModel('Actionlog', 'Administrator', ['ignore_request' => true]);
BUT libraries/src/Extension/Service/Provider/MVCFactory.php register method in Joomla 4.2 loads the SiteRouter class without checking the fact that its being run in a ConsoleApplication

One fix is to change the register method of libraries/src/Extension/Service/Provider/MVCFactory.php to read to check for a console application e.g.
if (! \Joomla\CMS\Factory::getApplication()->isClient('cli')) { $factory->setSiteRouter($container->get(SiteRouter::class)); }

I don't know why this line was added in Joomla 4.2.

If this looks like a sensible approach I'll pull together a Pull Request.

avatar GeraintEdwards GeraintEdwards - open - 5 Sep 2022
avatar joomla-cms-bot joomla-cms-bot - change - 5 Sep 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Sep 2022
avatar wilsonge
wilsonge - comment - 5 Sep 2022

There was a fix merged into 4.2 for this for cli apps using the joomla console. This PR once merged would make some of that functionality available for CLI Apps too #38544 (although would require support being added)

// cc @laoneo because technically this site router thing is causing a b/c issue (although it's not an incorrect change either)

avatar GeraintEdwards
GeraintEdwards - comment - 5 Sep 2022

@wilsonge Your in ConsoleApplication resolves the issue

$this->set('uri.request', $uri->toString());

As does Nicholas' change to the cli application itself

$app->set('uri.request', 'https://console.invalid');

Personally I don't see why a console application should be responsible for setting a uri.request just in case its used somewhere in the code

avatar wilsonge
wilsonge - comment - 5 Sep 2022

It depends on what you're doing. In some cases you might still be outputting urls or building URLs. In this case the CLI will need such a property. I agree that just getting a component mvc factory shouldn't necessarily require a siterouter object (hence I tagged @laoneo ) - but depending on JFactory isn't really the solution either - for example booting up an admin controller in the CLI is totally valid and it's hard to tell when you might need a site router and when you might not.

avatar GeraintEdwards
GeraintEdwards - comment - 5 Sep 2022

Sorry - I made a mistake. Neither your change to ConsoleApplication nor Nicholas' suggestsions help. I still had by crude fix in libraries/src/Extension/Service/Provider/MVCFactory.php active :(

avatar rdeutz
rdeutz - comment - 13 Sep 2022

So its solved and we can close this? @GeraintEdwards

avatar GeraintEdwards
GeraintEdwards - comment - 13 Sep 2022

No its not solved @rdeutz without George's full fix from #38544

I'm not an expert with the new Container/DI system but at present, as far as I can see, there is now no way to avoid the SiteRouter object being instantiated when we try to boot the actionlogs component - this would be ok if we could set a dummy value for the uri.request ahead of time but this is not possible. The problem is within the loadSystemUris method of WebApplication since it always overwrites uri.request.

From my understanding George's PR at least provides a 'safe' default value for this that stops a crash.

When I get an opportunity I'll run some more tests of George's code and add some more observations.

avatar Hackwar Hackwar - change - 17 Feb 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 17 Feb 2023

Add a Comment

Login with GitHub to post a comment