Skip to content

Commit b17fa7d

Browse files
committed
[ticket/14895] Use SymfonyStyle in all CLI
PHPBB3-14895
1 parent d275fef commit b17fa7d

15 files changed

Lines changed: 100 additions & 83 deletions

File tree

phpBB/phpbb/console/command/cache/purge.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Style\SymfonyStyle;
1718

1819
class purge extends \phpbb\console\command\command
1920
{
@@ -84,6 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8485

8586
$this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array());
8687

87-
$output->writeln($this->user->lang('PURGE_CACHE_SUCCESS'));
88+
$io = new SymfonyStyle($input, $output);
89+
$io->success($this->user->lang('PURGE_CACHE_SUCCESS'));
8890
}
8991
}

phpBB/phpbb/console/command/config/delete.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
1819

1920
class delete extends command
2021
{
@@ -47,17 +48,19 @@ protected function configure()
4748
*/
4849
protected function execute(InputInterface $input, OutputInterface $output)
4950
{
51+
$io = new SymfonyStyle($input, $output);
52+
5053
$key = $input->getArgument('key');
5154

5255
if (isset($this->config[$key]))
5356
{
5457
$this->config->delete($key);
5558

56-
$output->writeln('<info>' . $this->user->lang('CLI_CONFIG_DELETE_SUCCESS', $key) . '</info>');
59+
$io->success($this->user->lang('CLI_CONFIG_DELETE_SUCCESS', $key));
5760
}
5861
else
5962
{
60-
$output->writeln('<error>' . $this->user->lang('CLI_CONFIG_NOT_EXISTS', $key) . '</error>');
63+
$io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key));
6164
}
6265
}
6366
}

phpBB/phpbb/console/command/config/get.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class get extends command
2122
{
@@ -54,6 +55,8 @@ protected function configure()
5455
*/
5556
protected function execute(InputInterface $input, OutputInterface $output)
5657
{
58+
$io = new SymfonyStyle($input, $output);
59+
5760
$key = $input->getArgument('key');
5861

5962
if (isset($this->config[$key]) && $input->getOption('no-newline'))
@@ -66,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6669
}
6770
else
6871
{
69-
$output->writeln('<error>' . $this->user->lang('CLI_CONFIG_NOT_EXISTS', $key) . '</error>');
72+
$io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key));
7073
}
7174
}
7275
}

phpBB/phpbb/console/command/config/increment.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class increment extends command
2122
{
@@ -59,12 +60,14 @@ protected function configure()
5960
*/
6061
protected function execute(InputInterface $input, OutputInterface $output)
6162
{
63+
$io = new SymfonyStyle($input, $output);
64+
6265
$key = $input->getArgument('key');
6366
$increment = $input->getArgument('increment');
6467
$use_cache = !$input->getOption('dynamic');
6568

6669
$this->config->increment($key, $increment, $use_cache);
6770

68-
$output->writeln('<info>' . $this->user->lang('CLI_CONFIG_INCREMENT_SUCCESS', $key) . '</info>');
71+
$io->success($this->user->lang('CLI_CONFIG_INCREMENT_SUCCESS', $key));
6972
}
7073
}

phpBB/phpbb/console/command/config/set.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class set extends command
2122
{
@@ -59,12 +60,14 @@ protected function configure()
5960
*/
6061
protected function execute(InputInterface $input, OutputInterface $output)
6162
{
63+
$io = new SymfonyStyle($input, $output);
64+
6265
$key = $input->getArgument('key');
6366
$value = $input->getArgument('value');
6467
$use_cache = !$input->getOption('dynamic');
6568

6669
$this->config->set($key, $value, $use_cache);
6770

68-
$output->writeln('<info>' . $this->user->lang('CLI_CONFIG_SET_SUCCESS', $key) . '</info>');
71+
$io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key));
6972
}
7073
}

phpBB/phpbb/console/command/config/set_atomic.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class set_atomic extends command
2122
{
@@ -65,19 +66,21 @@ protected function configure()
6566
*/
6667
protected function execute(InputInterface $input, OutputInterface $output)
6768
{
69+
$io = new SymfonyStyle($input, $output);
70+
6871
$key = $input->getArgument('key');
6972
$old_value = $input->getArgument('old');
7073
$new_value = $input->getArgument('new');
7174
$use_cache = !$input->getOption('dynamic');
7275

7376
if ($this->config->set_atomic($key, $old_value, $new_value, $use_cache))
7477
{
75-
$output->writeln('<info>' . $this->user->lang('CLI_CONFIG_SET_SUCCESS', $key) . '</info>');
78+
$io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key));
7679
return 0;
7780
}
7881
else
7982
{
80-
$output->writeln('<error>' . $this->user->lang('CLI_CONFIG_SET_FAILURE', $key) . '</error>');
83+
$io->error($this->user->lang('CLI_CONFIG_SET_FAILURE', $key));
8184
return 1;
8285
}
8386
}

phpBB/phpbb/console/command/cron/cron_list.php

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Style\SymfonyStyle;
1718

1819
class cron_list extends \phpbb\console\command\command
1920
{
@@ -55,57 +56,39 @@ protected function configure()
5556
*/
5657
protected function execute(InputInterface $input, OutputInterface $output)
5758
{
59+
$io = new SymfonyStyle($input, $output);
60+
5861
$tasks = $this->cron_manager->get_tasks();
5962

6063
if (empty($tasks))
6164
{
62-
$output->writeln($this->user->lang('CRON_NO_TASKS'));
65+
$io->error($this->user->lang('CRON_NO_TASKS'));
6366
return;
6467
}
6568

66-
$ready_tasks = array();
67-
$not_ready_tasks = array();
69+
$ready_tasks = $not_ready_tasks = array();
6870
foreach ($tasks as $task)
6971
{
7072
if ($task->is_ready())
7173
{
72-
$ready_tasks[] = $task;
74+
$ready_tasks[] = $task->get_name();
7375
}
7476
else
7577
{
76-
$not_ready_tasks[] = $task;
78+
$not_ready_tasks[] = $task->get_name();
7779
}
7880
}
7981

8082
if (!empty($ready_tasks))
8183
{
82-
$output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>');
83-
$this->print_tasks_names($ready_tasks, $output);
84-
}
85-
86-
if (!empty($ready_tasks) && !empty($not_ready_tasks))
87-
{
88-
$output->writeln('');
84+
$io->section($this->user->lang('TASKS_READY'));
85+
$io->listing($ready_tasks);
8986
}
9087

9188
if (!empty($not_ready_tasks))
9289
{
93-
$output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>');
94-
$this->print_tasks_names($not_ready_tasks, $output);
95-
}
96-
}
97-
98-
/**
99-
* Print a list of cron jobs
100-
*
101-
* @param array $tasks A list of task to display
102-
* @param OutputInterface $output An OutputInterface instance
103-
*/
104-
protected function print_tasks_names(array $tasks, OutputInterface $output)
105-
{
106-
foreach ($tasks as $task)
107-
{
108-
$output->writeln($task->get_name());
90+
$io->section($this->user->lang('TASKS_NOT_READY'));
91+
$io->listing($not_ready_tasks);
10992
}
11093
}
11194
}

phpBB/phpbb/console/command/db/list_command.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Input\InputInterface;
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
1819

1920
class list_command extends \phpbb\console\command\db\migration_command
2021
{
@@ -34,6 +35,8 @@ protected function configure()
3435

3536
protected function execute(InputInterface $input, OutputInterface $output)
3637
{
38+
$io = new SymfonyStyle($input, $output);
39+
3740
$show_installed = !$input->getOption('available');
3841
$installed = $available = array();
3942

@@ -51,23 +54,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
5154

5255
if ($show_installed)
5356
{
54-
$output->writeln('<info>' . $this->user->lang('CLI_MIGRATIONS_INSTALLED') . $this->user->lang('COLON') . '</info>');
55-
$output->writeln($installed);
57+
$io->section($this->user->lang('CLI_MIGRATIONS_INSTALLED'));
5658

57-
if (empty($installed))
59+
if (!empty($installed))
5860
{
59-
$output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY'));
61+
$io->listing($installed);
62+
}
63+
else
64+
{
65+
$io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
66+
$io->newLine();
6067
}
61-
62-
$output->writeln('');
6368
}
6469

65-
$output->writeln('<info>' . $this->user->lang('CLI_MIGRATIONS_AVAILABLE') . $this->user->lang('COLON') . '</info>');
66-
$output->writeln($available);
67-
68-
if (empty($available))
70+
$io->section($this->user->lang('CLI_MIGRATIONS_AVAILABLE'));
71+
if (!empty($available))
72+
{
73+
$io->listing($available);
74+
}
75+
else
6976
{
70-
$output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY'));
77+
$io->text($this->user->lang('CLI_MIGRATIONS_EMPTY'));
78+
$io->newLine();
7179
}
7280
}
7381
}

phpBB/phpbb/console/command/db/migrate.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpbb\db\output_handler\log_wrapper_migrator_output_handler;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Style\SymfonyStyle;
1819

1920
class migrate extends \phpbb\console\command\db\migration_command
2021
{
@@ -50,6 +51,8 @@ protected function configure()
5051

5152
protected function execute(InputInterface $input, OutputInterface $output)
5253
{
54+
$io = new SymfonyStyle($input, $output);
55+
5356
$this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));
5457

5558
$this->migrator->create_migrations_table();
@@ -66,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6669
}
6770
catch (\phpbb\db\migration\exception $e)
6871
{
69-
$output->writeln('<error>' . $e->getLocalisedMessage($this->user) . '</error>');
72+
$io->error($e->getLocalisedMessage($this->user));
7073
$this->finalise_update();
7174
return 1;
7275
}
@@ -78,6 +81,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
7881
}
7982

8083
$this->finalise_update();
81-
$output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']);
84+
$io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL'));
8285
}
8386
}

phpBB/phpbb/console/command/db/revert.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1920

2021
class revert extends \phpbb\console\command\db\migration_command
2122
{
@@ -52,6 +53,8 @@ protected function configure()
5253

5354
protected function execute(InputInterface $input, OutputInterface $output)
5455
{
56+
$io = new SymfonyStyle($input, $output);
57+
5558
$name = str_replace('/', '\\', $input->getArgument('name'));
5659

5760
$this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem));
@@ -60,12 +63,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
6063

6164
if (!in_array($name, $this->load_migrations()))
6265
{
63-
$output->writeln('<error>' . $this->user->lang('MIGRATION_NOT_VALID', $name) . '</error>');
66+
$io->error($this->language->lang('MIGRATION_NOT_VALID', $name));
6467
return 1;
6568
}
6669
else if ($this->migrator->migration_state($name) === false)
6770
{
68-
$output->writeln('<error>' . $this->user->lang('MIGRATION_NOT_INSTALLED', $name) . '</error>');
71+
$io->error($this->language->lang('MIGRATION_NOT_INSTALLED', $name));
6972
return 1;
7073
}
7174

@@ -78,11 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
7881
}
7982
catch (\phpbb\db\migration\exception $e)
8083
{
81-
$output->writeln('<error>' . $e->getLocalisedMessage($this->user) . '</error>');
84+
$io->error($e->getLocalisedMessage($this->user));
8285
$this->finalise_update();
8386
return 1;
8487
}
8588

8689
$this->finalise_update();
90+
$io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL'));
8791
}
8892
}

0 commit comments

Comments
 (0)