aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2014-06-06 19:49:30 +0200
committerAndreas Fischer <bantu@phpbb.com>2014-06-06 19:49:30 +0200
commit9e00aef34a02f2446101bcc7d3697d023f58af84 (patch)
tree0719acfac7efd458aba112751a8932e4d8b4af63
parente509f8664b69199963c1bda7e1cb666bf70309c9 (diff)
parentfc4275ab2b414e184007a8791c7ee09537d5a827 (diff)
downloadforums-9e00aef34a02f2446101bcc7d3697d023f58af84.tar
forums-9e00aef34a02f2446101bcc7d3697d023f58af84.tar.gz
forums-9e00aef34a02f2446101bcc7d3697d023f58af84.tar.bz2
forums-9e00aef34a02f2446101bcc7d3697d023f58af84.tar.xz
forums-9e00aef34a02f2446101bcc7d3697d023f58af84.zip
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/12655] Set register_container_commands as public [ticket/12655] Don't try to restore the definition in the help [ticket/12655] Fix coding style [ticket/12655] Make the --shell option available only for phpbbcli.php [ticket/12655] Fix coding style in \phpbb\console\application [ticket/12655] Set the arguments of \phpbb\console\application as required [ticket/12655] Don't require acp/common again in the commands [ticket/12655] Run the shell when --shell is used
-rwxr-xr-xphpBB/bin/phpbbcli.php5
-rw-r--r--phpBB/language/en/acp/common.php2
-rw-r--r--phpBB/phpbb/console/application.php80
-rw-r--r--phpBB/phpbb/console/command/cache/purge.php1
-rw-r--r--phpBB/phpbb/console/command/db/migrate.php2
5 files changed, 86 insertions, 4 deletions
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 12cdc28aa3..6ca1a985a5 100644
--- a/phpBB/language/en/acp/common.php
+++ b/phpBB/language/en/acp/common.php
@@ -227,6 +227,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..b1f0635913 100644
--- a/phpBB/phpbb/console/application.php
+++ b/phpBB/phpbb/console/application.php
@@ -13,15 +13,93 @@
namespace phpbb\console;
+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;
class application extends \Symfony\Component\Console\Application
{
- function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command')
+ /**
+ * @var bool Indicates whether or not we are in a shell
+ */
+ 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
+ * @param \phpbb\user $user The user which runs the application (used for translation)
+ */
+ public function __construct($name, $version, \phpbb\user $user)
+ {
+ 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();
+ }
+
+ $this->getDefinition()->addOption(new InputOption(
+ '--shell',
+ '-s',
+ InputOption::VALUE_NONE,
+ $this->user->lang('CLI_DESCRIPTION_OPTION_SHELL')
+ ));
+
+ return parent::getHelp();
+ }
+
+ /**
+ * Register a set of commands from the container
+ *
+ * @param TaggedContainerInterface $container The container
+ * @param string $tag The tag used to register the commands
+ */
+ public function register_container_commands(TaggedContainerInterface $container, $tag = 'console.command')
{
foreach($container->findTaggedServiceIds($tag) as $id => $void)
{
$this->add($container->get($id));
}
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function doRun(InputInterface $input, OutputInterface $output)
+ {
+ // 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')))
+ {
+ $shell = new Shell($this);
+ $this->in_shell = true;
+ $shell->run();
+
+ return 0;
+ }
+
+ return parent::doRun($input, $output);
+ }
}
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();
}