Skip to content

[4.0] Set the cli as global app#16540

Merged
wilsonge merged 40 commits intojoomla:4.0-devfrom
Digital-Peak:j4/cli-convert
Jun 29, 2017
Merged

[4.0] Set the cli as global app#16540
wilsonge merged 40 commits intojoomla:4.0-devfrom
Digital-Peak:j4/cli-convert

Conversation

@laoneo
Copy link
Copy Markdown
Member

@laoneo laoneo commented Jun 5, 2017

As we introduced the CMSApplicationInterface the cli apps should act as global applications. This is a followup of #16499 and #16516.

Additionally the apps from the controllers are loaded from the container.

DON'T Merge, please!

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Jun 6, 2017

WIll reopen when ready.

@laoneo laoneo closed this Jun 6, 2017
@laoneo laoneo reopened this Jun 14, 2017
*
* @since 11.1
* @since 11.1
* @deprecated 5.0 Load the app trough the container
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

through

includes/app.php Outdated

// Instantiate the application.
$app = JFactory::getApplication('site');
$app = JFactory::getContainer()->get('SiteApplication');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and AdministratorApplication still need to run through JFactory::getApplication otherwise we're going to end up with the JApplicationCms::$instance being empty right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be reverted back otherwise none of the singletons will be populated. JFactory::$application and the JApplicationCms instances container.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not set them manually like I did with the cli scripts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set JFactory::$application manually, but without Reflection, you can't set JApplicationCms::$instances.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will revert that change and do it then in a new pr.


// JSON encode the file and write it to JPATH_ADMINISTRATOR/help/en-GB/toc.json
file_put_contents(JPATH_ADMINISTRATOR . '/help/en-GB/toc.json', json_encode($toc));
file_put_contents(JPATH_ADMINISTRATOR . '/help/toc.json', json_encode($toc));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing en-GB here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this folder doesn't exist, either we remove it or create it. But like it is now it crashes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to exist - https://github.com/joomla/joomla-cms/tree/staging/administrator/help/en-GB - probably something that needs to be worked on from the Mediawiki PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like i accidently deleted it :/ oops. 98cef84#diff-41ac6b5cb48181a44ad59de73a6fc4dd

$dispatcher = $container->get('Joomla\Event\DispatcherInterface');
$dispatcher->addListener('onAfterSessionStart', array(JFactory::getApplication(), 'afterSessionStart'));

if (JFactory::getApplication() instanceof CMSApplication)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If anything this should be a method_exists() check. This needlessly restricts the session service provider.

{
$this->app = $app ?: CMSApplication::getInstance('site');
$this->menu = $menu ?: $this->app->getMenu();
$this->app = $app ?: \JFactory::getApplication();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the typehinting here is for the base CMSApplication, but are we certain that there isn't anything buried in the internals of the site router and menu that could cause a problem if the admin application were used in place of the site application?

if (\JFactory::$document)
if ($isCli)
{
// We're probably in an CLI environment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here is actually very misleading, I don't think it even applies anymore. The comment above the if statement is more accurate, so I think the change you made should be reverted.

The intent was to use the document format type if there is already a JDocument instance in JFactory, and if that isn't set to fall back on the format in the request (obviously this part is web specific).

echo $app->toString();

$app->close(0);
$app->close(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$app->close() should be called regardless of being a CLI or web app. Or it can be removed completely as we'll hit the return line below and whatever PHP does after calling the uncaught exceptions handler would be performed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need to add that function to the CMSApplicationInterface?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to think we can get away with just removing $app->close() completely and just using the return statement a few lines down, regardless of context.

$this->app = $app ?: CMSApplication::getInstance('site');
$this->menu = $menu ?: $this->app->getMenu();
$this->app = $app ?: \JFactory::getApplication();
$this->menu = $menu ?: $this->app->getContainer()->get(MenuFactoryInterface::class)->createMenu('site', ['app' => $this->app]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? This just seems like adding complexity for the sake of it, unless you plan on removing getMenu() from the CMSApplication class that was just fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working actually on the cli scripts. Running the indexer from the command line needs the router which needs the site menu.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typehinting here is still for the web application class chain, not the interface yet. So it's still wouldn't support a CLI app here anyway.

The next issue is the app interface isn't container aware, so you can't rely on getContainer() being available either.

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Jun 15, 2017

I'v changed all the input from Michael. Can you guys please have a second look?

}

$app->setBody($data);
if ($isCli)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if setBody and getBody should be in the interface. Thoughts @mbabker

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't try finangling it to fit. CLI and web apps handle output differently (CLI with output objects, web with response objects, both different APIs). So this is the best option.

@wilsonge
Copy link
Copy Markdown
Contributor

This looks largely good. I want Michael's thoughts on the setBody/getBody thing but once we have that and we've solved conflicts I think this is probably good to merge

laoneo added 2 commits June 29, 2017 07:28
…onvert

# Conflicts:
#	libraries/src/CMS/Factory.php
#	libraries/src/CMS/Router/SiteRouter.php
@wilsonge wilsonge merged commit fdd2644 into joomla:4.0-dev Jun 29, 2017
@wilsonge wilsonge deleted the j4/cli-convert branch June 29, 2017 07:40
@wilsonge wilsonge added this to the Joomla 4.0 milestone Jun 29, 2017
@laoneo laoneo mentioned this pull request Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants