[PHPBB3-12685] CLI doesn't load extension commands Created: 10/Jun/14  Updated: 22/Jan/17  Resolved: 17/Jul/14

Status: Closed
Project: phpBB3
Component/s: CLI, Extensions
Affects Version/s: 3.1.0-b4
Fix Version/s: 3.1.0-RC3

Type: Bug Priority: Major
Reporter: carlino1994 Assignee: nicofuma
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
is duplicated by PHPBB3-12686 CLI cron:run doesn't load extensions Closed
GitHub Pull Request URL: https://github.com/phpbb/phpbb/pull/2576


Currently, phpBB Console doesn't load extension commands.

Comment by Andreas Fischer [ 10/Jun/14 ]

You need to register your command at the container using the command tag. Are you doing that?

Comment by rfdy [X] (Inactive) [ 10/Jun/14 ]

This issue was probably created after this topic: https://area51.phpbb.com/phpBB/viewtopic.php?p=265837

The task was defined correctly within the extension's config.yml file, yet the service collection never picked up on it (using the specified tag). This isn't for creating a custom CLI command, it is for executing a cron task through the CLI cron command (ie. cron:run).

Comment by carlino1994 [ 10/Jun/14 ]

Yes, this is the services.yml of my extension:

        class: carlo94it\myextensionname\command\install
            - %core.root_path%
            - %core.php_ext%
            - { name: console.command }

And the my class extends \phpbb\console\command\command.

I created this ticket after this topic: https://www.phpbb.com/community/viewtopic.php?f=461&t=2246641

Comment by nicofuma [ 10/Jun/14 ]

bantu: phpbbcli uses phpbb_create_update_container() which does not load the extension's services

Comment by carlino1994 [ 10/Jun/14 ]

I can work for resolve this issue.

Comment by nicofuma [ 10/Jun/14 ]

basically, we only have to replace the line 38 with

$phpbb_container = phpbb_create_default_container($phpbb_root_path, $php_ext)

but this point as to be discussed because in some command it could be undesirable to load the extensions.

Comment by carlino1994 [ 10/Jun/14 ]

Yes, for example phpBB Console will be a emergency tool to disable extensions that don't allow the execution of phpBB.

Comment by carlino1994 [ 10/Jun/14 ]

And if we define a new constant in the config.php file to determine whether to load extensions in the console?

Comment by rfdy [X] (Inactive) [ 10/Jun/14 ]

By default the console should load all enabled extensions, if something breaks (which is very likely to happen during development), then a "safe mode" parameter can be added to the console which will not load extensions. IMHO that would be ideal. Thanks.

Comment by carlino1994 [ 10/Jun/14 ]

There is a problem with default container.

I did a test. If we use the default container for phpBB Console commands are loaded only the first time (when the cache is generated). Once the cache was generated, are no longer loaded.

To test this, change line 38 of bin/phpbbcli.php to:

$phpbb_container = phpbb_create_default_container($phpbb_root_path, $phpEx);

We can't use a "safe mode" parameter because container is created before the console application start.

Comment by carlino1994 [ 11/Jun/14 ]

For resolve the problem with the default container of which I have mentioned in my previous post, we can create a new CLI container that won't be cached, as currently do the update container (but add extensions loading).

We have 2 options:

  • create a CLI container
  • force DEBUG into CLI and use default container (this will use a compiled container instead of dumped container)
Generated at Tue Jan 22 11:00:43 UTC 2019 using Jira 7.12.3#712004-sha1:5ef91d760d7124da5ebec5c16a948a4a807698df.