From b95ab440280ca5e5e94fe1f96f4f947734e37da3 Mon Sep 17 00:00:00 2001 From: Carlo Date: Sat, 12 Jul 2014 17:19:43 +0200 Subject: [PATCH 01/13] [ticket/12685] Add console collection and fixing CLI Added a commands service collection and removed CLI container PHPBB3-12685 --- phpBB/config/console.yml | 6 ++++++ phpBB/phpbb/console/application.php | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/phpBB/config/console.yml b/phpBB/config/console.yml index 00b8f9cec0..f4beb1c089 100644 --- a/phpBB/config/console.yml +++ b/phpBB/config/console.yml @@ -1,4 +1,10 @@ services: + console.command_collection: + class: phpbb\di\service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: console.command } console.command.cache.purge: class: phpbb\console\command\cache\purge arguments: diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index b1f0635913..72fcee5cfa 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\TaggedContainerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; class application extends \Symfony\Component\Console\Application { @@ -73,14 +73,13 @@ class application extends \Symfony\Component\Console\Application /** * Register a set of commands from the container * - * @param TaggedContainerInterface $container The container - * @param string $tag The tag used to register the commands + * @param ContainerInterface $container The container */ - public function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') + public function register_container_commands(ContainerInterface $container) { - foreach($container->findTaggedServiceIds($tag) as $id => $void) + foreach($container->get('console.command_collection') as $service_command) { - $this->add($container->get($id)); + $this->add($service_command); } } From 1125fb3cabf7a69dc4cac852efd655ce2afcd7a0 Mon Sep 17 00:00:00 2001 From: Carlo Date: Fri, 20 Jun 2014 09:58:51 +0000 Subject: [PATCH 02/13] [ticket/12685] Add space after foreach PHPBB3-12685 --- phpBB/phpbb/console/application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 72fcee5cfa..2aef48c93b 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -77,7 +77,7 @@ class application extends \Symfony\Component\Console\Application */ public function register_container_commands(ContainerInterface $container) { - foreach($container->get('console.command_collection') as $service_command) + foreach ($container->get('console.command_collection') as $service_command) { $this->add($service_command); } From 6082b5e3d3942b330d7bb2aa822d97b9038babe5 Mon Sep 17 00:00:00 2001 From: Carlo Date: Sat, 12 Jul 2014 17:48:53 +0200 Subject: [PATCH 03/13] [ticket/12685] We need extensions enabled PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index c8098094a2..4c4367b31c 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -39,7 +39,6 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/" $phpbb_class_loader_ext->register(); $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); -$phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); $phpbb_container = $phpbb_container_builder->get_container(); From 2ec50c0ff15837489f36b014a2e36470b1672508 Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 00:38:07 +0200 Subject: [PATCH 04/13] [ticket/12685] Add --safe-mode PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 14 ++++++++++++-- phpBB/language/en/acp/common.php | 1 + phpBB/phpbb/console/application.php | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 4c4367b31c..21940d8a51 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -12,6 +12,8 @@ * */ +use Symfony\Component\Console\Input\ArgvInput; + if (php_sapi_name() != 'cli') { echo 'This program must be run from the command line.' . PHP_EOL; @@ -39,7 +41,15 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/" $phpbb_class_loader_ext->register(); $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); -$phpbb_container_builder->set_dump_container(false); +$phpbb_container_builder->set_dump_container(true); + +$input = new ArgvInput(); + +if ($input->hasParameterOption(array('--safe-mode'))) +{ + $phpbb_container_builder->set_use_extensions(false); + $phpbb_container_builder->set_dump_container(false); +} $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->get('request')->enable_super_globals(); @@ -50,4 +60,4 @@ $user->add_lang('acp/common'); $application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $user); $application->register_container_commands($phpbb_container); -$application->run(); +$application->run($input); diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 61c718195e..0c3df5862e 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -230,6 +230,7 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run', 'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.', + 'CLI_DESCRIPTION_OPTION_SAFE_MODE' => 'Run in Safe Mode (without extensions).', 'COLOUR_SWATCH' => 'Web-safe colour swatch', 'CONFIG_UPDATED' => 'Configuration updated successfully.', diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 2aef48c93b..eac8dbea2d 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -67,6 +67,13 @@ class application extends \Symfony\Component\Console\Application $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); + $this->getDefinition()->addOption(new InputOption( + '--safe-mode', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE') + )); + return parent::getHelp(); } From 0f41a8fc31ba6af38fc90f47b742ffe35815fd3b Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 10:21:23 +0200 Subject: [PATCH 05/13] [ticket/12685] Removed spaces PHPBB3-12685 --- phpBB/phpbb/console/application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index eac8dbea2d..5cda90208a 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -72,7 +72,7 @@ class application extends \Symfony\Component\Console\Application null, InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE') - )); + )); return parent::getHelp(); } From 7e6215fb7f01eeaa4798d45a1f366685693bfdcc Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 10:22:39 +0200 Subject: [PATCH 06/13] [ticket/12685] Container is dumped by default PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 21940d8a51..5fac2cf8b3 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -41,7 +41,6 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/" $phpbb_class_loader_ext->register(); $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); -$phpbb_container_builder->set_dump_container(true); $input = new ArgvInput(); From a54f1275d03b4fcccfa1005cce5cae2f344e567e Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 11:27:58 +0200 Subject: [PATCH 07/13] [ticket/12685] Add a new line PHPBB3-12685 --- phpBB/config/console.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/config/console.yml b/phpBB/config/console.yml index f4beb1c089..06ea0e317f 100644 --- a/phpBB/config/console.yml +++ b/phpBB/config/console.yml @@ -5,6 +5,7 @@ services: - @service_container tags: - { name: service_collection, tag: console.command } + console.command.cache.purge: class: phpbb\console\command\cache\purge arguments: From 15136e4f8e36ca972f6b1b0bb7a4867967698335 Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 11:36:51 +0200 Subject: [PATCH 08/13] [ticket/12685] Inject console.command_collection instead of the container PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 2 +- phpBB/phpbb/console/application.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 5fac2cf8b3..d181a63f68 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -58,5 +58,5 @@ $user = $phpbb_container->get('user'); $user->add_lang('acp/common'); $application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION, $user); -$application->register_container_commands($phpbb_container); +$application->register_container_commands($phpbb_container->get('console.command_collection')); $application->run($input); diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 5cda90208a..5202a1fbaf 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -80,11 +80,11 @@ class application extends \Symfony\Component\Console\Application /** * Register a set of commands from the container * - * @param ContainerInterface $container The container + * @param \phpbb\di\service_collection $command_collection The console service collection */ - public function register_container_commands(ContainerInterface $container) + public function register_container_commands(\phpbb\di\service_collection $command_collection) { - foreach ($container->get('console.command_collection') as $service_command) + foreach ($command_collection as $service_command) { $this->add($service_command); } From 3eafeeb88d173bc4f2b082ee5f09f85bef931ec9 Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 13:31:34 +0200 Subject: [PATCH 09/13] [ticket/12685] Removed unused USE statement PHPBB3-12685 --- phpBB/phpbb/console/application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 5202a1fbaf..b08346b8fa 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -17,7 +17,6 @@ use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; class application extends \Symfony\Component\Console\Application { From 7cffedf5e310e0cde9bfd541ca835a4fedf26ef3 Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 16:07:52 +0200 Subject: [PATCH 10/13] [ticket/12685] Override getDefaultInputDefinition() PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 2 +- phpBB/phpbb/console/application.php | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index d181a63f68..baaa22e67b 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -44,7 +44,7 @@ $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_fil $input = new ArgvInput(); -if ($input->hasParameterOption(array('--safe-mode'))) +if ($input->getParameterOption(array('--safe-mode'))) { $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index b08346b8fa..bc4897af18 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -37,9 +37,26 @@ class application extends \Symfony\Component\Console\Application */ public function __construct($name, $version, \phpbb\user $user) { - parent::__construct($name, $version); - $this->user = $user; + + parent::__construct($name, $version); + } + + /** + * {@inheritdoc} + */ + protected function getDefaultInputDefinition() + { + $input_definition = parent::getDefaultInputDefinition(); + + $input_definition->addOption(new InputOption( + 'safe-mode', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE') + )); + + return $input_definition; } /** @@ -66,13 +83,6 @@ class application extends \Symfony\Component\Console\Application $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); - $this->getDefinition()->addOption(new InputOption( - '--safe-mode', - null, - InputOption::VALUE_NONE, - $this->user->lang('CLI_DESCRIPTION_OPTION_SAFE_MODE') - )); - return parent::getHelp(); } From d95d6720bca4591208d34aeed3787db387ec7ebb Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 17:51:23 +0200 Subject: [PATCH 11/13] [ticket/12685] Do not dump container PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index baaa22e67b..511eca9082 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -41,6 +41,7 @@ $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/" $phpbb_class_loader_ext->register(); $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); +$phpbb_container_builder->set_dump_container(false); $input = new ArgvInput(); From a4972bb338f06c6b7fbeea22869b3c3b106becf7 Mon Sep 17 00:00:00 2001 From: Carlo Date: Tue, 15 Jul 2014 19:21:41 +0200 Subject: [PATCH 12/13] [ticket/12685] Replace getParameterOption with hasParameterOption PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 511eca9082..d86ec6d8f8 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -45,7 +45,7 @@ $phpbb_container_builder->set_dump_container(false); $input = new ArgvInput(); -if ($input->getParameterOption(array('--safe-mode'))) +if ($input->hasParameterOption(array('--safe-mode'))) { $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); From 7f4d4250066eadb6badd43c4ce1b8f2f84e083cf Mon Sep 17 00:00:00 2001 From: Carlo Date: Thu, 17 Jul 2014 00:05:33 +0200 Subject: [PATCH 13/13] [ticket/12685] Setup class loader for extensions only if not in safe mode PHPBB3-12685 --- phpBB/bin/phpbbcli.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index d86ec6d8f8..89bad94184 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -37,9 +37,6 @@ require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); -$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); -$phpbb_class_loader_ext->register(); - $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_dump_container(false); @@ -50,6 +47,12 @@ if ($input->hasParameterOption(array('--safe-mode'))) $phpbb_container_builder->set_use_extensions(false); $phpbb_container_builder->set_dump_container(false); } +else +{ + $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); + $phpbb_class_loader_ext->register(); + phpbb_load_extensions_autoloaders($phpbb_root_path); +} $phpbb_container = $phpbb_container_builder->get_container(); $phpbb_container->get('request')->enable_super_globals();