From 5efd55a34883acad2971117d3a7faf20ecd7e08b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 14:26:40 +0200 Subject: [PATCH 1/8] [ticket/12655] Run the shell when --shell is used PHPBB3-12655 --- phpBB/bin/phpbbcli.php | 5 +++- phpBB/language/en/acp/common.php | 2 ++ phpBB/phpbb/console/application.php | 38 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/phpBB/bin/phpbbcli.php b/phpBB/bin/phpbbcli.php index 63c8f2230b..8b8d8e43fd 100755 --- a/phpBB/bin/phpbbcli.php +++ b/phpBB/bin/phpbbcli.php @@ -39,6 +39,9 @@ $phpbb_container = phpbb_create_update_container($phpbb_root_path, $phpEx, "$php $phpbb_container->get('request')->enable_super_globals(); require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx); -$application = new \phpbb\console\application('phpBB Console', PHPBB_VERSION); +$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->run(); diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 838a73caed..0b82b447ef 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -226,6 +226,8 @@ $lang = array_merge($lang, array( 'CLI_DESCRIPTION_CRON_RUN' => 'Runs all ready cron tasks.', 'CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1' => 'Name of the task to be run', + 'CLI_DESCRIPTION_OPTION_SHELL' => 'Launch the shell.', + 'COLOUR_SWATCH' => 'Web-safe colour swatch', 'CONFIG_UPDATED' => 'Configuration updated successfully.', 'CRON_LOCK_ERROR' => 'Could not obtain cron lock.', diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index da2bfbb49a..00477ee7d7 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,10 +13,33 @@ namespace phpbb\console; +use Symfony\Component\Console\Shell; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\TaggedContainerInterface; class application extends \Symfony\Component\Console\Application { + /** + * @param string $name The name of the application + * @param string $version The version of the application + * @param \phpbb\user $user The user which runs the application (used for translation) + */ + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', \phpbb\user $user) + { + parent::__construct($name, $version); + + $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, $user->lang('CLI_DESCRIPTION_OPTION_SHELL'))); + } + + /** + * Register a set of commands from the container + * + * @param TaggedContainerInterface $container The container + * @param string $tag The tag used to register the commands + */ function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') { foreach($container->findTaggedServiceIds($tag) as $id => $void) @@ -24,4 +47,19 @@ class application extends \Symfony\Component\Console\Application $this->add($container->get($id)); } } + + /** + * {@inheritdoc} + */ + public function doRun(InputInterface $input, OutputInterface $output) + { + if ($input->hasParameterOption(array('--shell', '-s')) === true) { + $shell = new Shell($this); + $shell->run(); + + return 0; + } + + parent::doRun($input, $output); + } } From 6c9518ea3232d02605ea4bd57e1bf56a91d05855 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 14:47:00 +0200 Subject: [PATCH 2/8] [ticket/12655] Don't require acp/common again in the commands PHPBB3-12655 --- phpBB/phpbb/console/command/cache/purge.php | 1 - phpBB/phpbb/console/command/db/migrate.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/phpbb/console/command/cache/purge.php b/phpBB/phpbb/console/command/cache/purge.php index 1e2adaeb4d..50953185a4 100644 --- a/phpBB/phpbb/console/command/cache/purge.php +++ b/phpBB/phpbb/console/command/cache/purge.php @@ -43,7 +43,6 @@ class purge extends \phpbb\console\command\command $this->log = $log; $this->user = $user; $this->config = $config; - $this->user->add_lang(array('acp/common')); parent::__construct(); } diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index 0f74664095..2abeaf5268 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -43,7 +43,7 @@ class migrate extends \phpbb\console\command\command $this->cache = $cache; $this->log = $log; $this->user = $user; - $this->user->add_lang(array('common', 'acp/common', 'install', 'migrator')); + $this->user->add_lang(array('common', 'install', 'migrator')); parent::__construct(); } From a14d16172c26fd8f849be4d3afcaac93b6dc4086 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 15:34:11 +0200 Subject: [PATCH 3/8] [ticket/12655] Set the arguments of \phpbb\console\application as required PHPBB3-12655 --- 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 00477ee7d7..eb8094e65f 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -27,7 +27,7 @@ class application extends \Symfony\Component\Console\Application * @param string $version The version of the application * @param \phpbb\user $user The user which runs the application (used for translation) */ - public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', \phpbb\user $user) + public function __construct($name, $version, \phpbb\user $user) { parent::__construct($name, $version); From 99ebf4b8ddb53c796247fda7993f8999ceb16816 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 21:08:11 +0200 Subject: [PATCH 4/8] [ticket/12655] Fix coding style in \phpbb\console\application PHPBB3-12655 --- phpBB/phpbb/console/application.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index eb8094e65f..99fb5fbe97 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -31,7 +31,12 @@ class application extends \Symfony\Component\Console\Application { parent::__construct($name, $version); - $this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, $user->lang('CLI_DESCRIPTION_OPTION_SHELL'))); + $this->getDefinition()->addOption(new InputOption( + '--shell', + '-s', + InputOption::VALUE_NONE, + $user->lang('CLI_DESCRIPTION_OPTION_SHELL') + )); } /** @@ -53,7 +58,8 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - if ($input->hasParameterOption(array('--shell', '-s')) === true) { + if ($input->hasParameterOption(array('--shell', '-s')) === true) + { $shell = new Shell($this); $shell->run(); From ce104e2c72a00c58d19691f6af6ee5a3935a5fbd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 4 Jun 2014 22:33:05 +0200 Subject: [PATCH 5/8] [ticket/12655] Make the --shell option available only for phpbbcli.php PHPBB3-12655 --- phpBB/phpbb/console/application.php | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 99fb5fbe97..9750367df0 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,6 +13,9 @@ namespace phpbb\console; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -22,6 +25,11 @@ use Symfony\Component\DependencyInjection\TaggedContainerInterface; class application extends \Symfony\Component\Console\Application { + /** + * @var bool Indicates whether or not we are in a shell + */ + protected $in_shell = false; + /** * @param string $name The name of the application * @param string $version The version of the application @@ -31,12 +39,42 @@ class application extends \Symfony\Component\Console\Application { parent::__construct($name, $version); + $this->user = $user; + } + + /** + * Gets the help message. + * + * It's a hack of the default help message to display the --shell + * option only for the application and not for all the commands. + * + * @return string A help message. + */ + public function getHelp() + { + // If we are already in a shell + // we do not want to have the --shell option available + if($this->in_shell) + { + return parent::getHelp(); + } + + // We store the definition to restore it later. + // Otherwise, in the shell mode the --shell option + // will be available for all command. + $definition_backup = $this->getDefinition(); + $this->getDefinition()->addOption(new InputOption( '--shell', '-s', InputOption::VALUE_NONE, - $user->lang('CLI_DESCRIPTION_OPTION_SHELL') + $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); + + $help_message = parent::getHelp(); + $this->setDefinition($definition_backup); + + return $help_message; } /** @@ -58,14 +96,17 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - if ($input->hasParameterOption(array('--shell', '-s')) === true) + // Run a shell if the --shell (or -s) option is set and if any command name is specified + // Also, we do not want to have the --shell option available if we are already in a shell + if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')) === true) { $shell = new Shell($this); + $this->in_shell = true; $shell->run(); return 0; } - parent::doRun($input, $output); + return parent::doRun($input, $output); } } From 012702307b1503005f1b5b6c20e654dc8d23e8a0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 00:21:53 +0200 Subject: [PATCH 6/8] [ticket/12655] Fix coding style PHPBB3-12655 --- phpBB/phpbb/console/application.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 9750367df0..ff90a76a92 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,11 +13,7 @@ namespace phpbb\console; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -30,6 +26,11 @@ class application extends \Symfony\Component\Console\Application */ protected $in_shell = false; + /** + * @var \phpbb\user User object + */ + protected $user; + /** * @param string $name The name of the application * @param string $version The version of the application @@ -54,7 +55,7 @@ class application extends \Symfony\Component\Console\Application { // If we are already in a shell // we do not want to have the --shell option available - if($this->in_shell) + if ($this->in_shell) { return parent::getHelp(); } @@ -96,9 +97,9 @@ class application extends \Symfony\Component\Console\Application */ public function doRun(InputInterface $input, OutputInterface $output) { - // Run a shell if the --shell (or -s) option is set and if any command name is specified + // Run a shell if the --shell (or -s) option is set and if no command name is specified // Also, we do not want to have the --shell option available if we are already in a shell - if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s')) === true) + if (!$this->in_shell && $this->getCommandName($input) === null && $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $this->in_shell = true; From 5e9c8a0ceaabb84a679bd56e7165a9e29fc3da71 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 01:00:33 +0200 Subject: [PATCH 7/8] [ticket/12655] Don't try to restore the definition in the help PHPBB3-12655 --- phpBB/phpbb/console/application.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index ff90a76a92..91d95b9a7b 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,6 +13,9 @@ namespace phpbb\console; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -60,11 +63,6 @@ class application extends \Symfony\Component\Console\Application return parent::getHelp(); } - // We store the definition to restore it later. - // Otherwise, in the shell mode the --shell option - // will be available for all command. - $definition_backup = $this->getDefinition(); - $this->getDefinition()->addOption(new InputOption( '--shell', '-s', @@ -72,10 +70,7 @@ class application extends \Symfony\Component\Console\Application $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL') )); - $help_message = parent::getHelp(); - $this->setDefinition($definition_backup); - - return $help_message; + return parent::getHelp(); } /** From 5b51acf245fc1fbd454d394e8b44bf73d6439248 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 5 Jun 2014 01:03:16 +0200 Subject: [PATCH 8/8] [ticket/12655] Set register_container_commands as public PHPBB3-12655 --- phpBB/phpbb/console/application.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/phpbb/console/application.php b/phpBB/phpbb/console/application.php index 91d95b9a7b..b1f0635913 100644 --- a/phpBB/phpbb/console/application.php +++ b/phpBB/phpbb/console/application.php @@ -13,9 +13,6 @@ namespace phpbb\console; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Output\ConsoleOutput; -use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Shell; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -79,7 +76,7 @@ class application extends \Symfony\Component\Console\Application * @param TaggedContainerInterface $container The container * @param string $tag The tag used to register the commands */ - function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') + public function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command') { foreach($container->findTaggedServiceIds($tag) as $id => $void) {