From 4bdef6fd21a5dcab455b0cd1ee2652de606929c3 Mon Sep 17 00:00:00 2001 From: MateBartus Date: Thu, 12 Mar 2015 00:25:00 +0100 Subject: [ticket/13697] Moving filesystem related functions to filesystem service * Moving filesystem service to \phpbb\filesystem namespace * Wraping Symfony's Filesystem component * Moving filesystem related functions from includes/functions.php into \phpbb\filesystem\filesystem Functions moved (and deprecated): - phpbb_chmod - phpbb_is_writable - phpbb_is_absolute - phpbb_own_realpath - phpbb_realpath * Adding interface for filesystem service PHPBB3-13697 --- phpBB/phpbb/console/command/db/migrate.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index 87c2a057d1..2490bf1310 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -35,13 +35,17 @@ class migrate extends \phpbb\console\command\command /** @var string phpBB root path */ protected $phpbb_root_path; - function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, $phpbb_root_path) + /** @var \phpbb\filesystem\filesystem_interface */ + protected $filesystem; + + function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) { $this->migrator = $migrator; $this->extension_manager = $extension_manager; $this->config = $config; $this->cache = $cache; $this->log = $log; + $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; parent::__construct($user); $this->user->add_lang(array('common', 'install', 'migrator')); @@ -57,7 +61,7 @@ class migrate extends \phpbb\console\command\command protected function execute(InputInterface $input, OutputInterface $output) { - $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log')); + $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); -- cgit v1.2.1 From 615ab099e228f2d7a35a76557095a65321425963 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 29 May 2015 19:33:17 +0200 Subject: [ticket/13891] Added reparser:list and reparser:reparse to CLI PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/list_all.php | 70 ++++++++++++++ phpBB/phpbb/console/command/reparser/reparse.php | 106 ++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 phpBB/phpbb/console/command/reparser/list_all.php create mode 100644 phpBB/phpbb/console/command/reparser/reparse.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php new file mode 100644 index 0000000000..10db568386 --- /dev/null +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -0,0 +1,70 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\console\command\reparser; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class list_all extends \phpbb\console\command\command +{ + /** + * @var string[] Names of the reparser services + */ + protected $reparser_names; + + /** + * Constructor + * + * @param \phpbb\user $user + * @param ContainerBuilder $container Container used to locate the reparsers + */ + public function __construct(\phpbb\user $user, ContainerBuilder $container) + { + parent::__construct($user); + $this->reparser_names = array(); + foreach (array_keys($container->findTaggedServiceIds('text_reparser.plugin')) as $name) + { + // Store the names without the "text_reparser." prefix + $this->reparser_names[] = str_replace('text_reparser.', '', $name); + } + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('reparser:list') + ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_LIST')) + ; + } + + /** + * Executes the command reparser:reparse + * + * @param InputInterface $input + * @param OutputInterface $output + * @return integer + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln('' . implode(', ', $this->reparser_names) . ''); + + return 0; + } +} diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php new file mode 100644 index 0000000000..f2bbe9c7d1 --- /dev/null +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -0,0 +1,106 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\console\command\reparser; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; + +class reparse extends \phpbb\console\command\command +{ + /** + * @var \phpbb\textreparser\reparser_collection + */ + protected $reparser_collection; + + /** + * Constructor + * + * @param \phpbb\user $user + * @param \phpbb\textreparser\reparser_collection $reparser_collection + */ + public function __construct(\phpbb\user $user, \phpbb\textreparser\reparser_collection $reparser_collection) + { + require_once __DIR__ . '/../../../../includes/functions_content.php'; + + $this->reparser_collection = $reparser_collection; + parent::__construct($user); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('reparser:reparse') + ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) + ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) + ; + } + + /** + * Executes the command reparser:reparse + * + * @param InputInterface $input + * @param OutputInterface $output + * @return integer + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = $input->getArgument('reparser-name'); + if (isset($name)) + { + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparser_collection[$name])) + { + $name = 'text_reparser.' . $name; + } + $this->reparse($output, $name); + } + else + { + foreach ($this->reparser_collection as $name => $service) + { + $this->reparse($output, $name); + } + } + + return 0; + } + + /** + * Reparse all text handled by given reparser + * + * @param OutputInterface $output + * @param string $name Reparser name + * @return null + */ + protected function reparse(OutputInterface $output, $name) + { + $reparser = $this->reparser_collection[$name]; + $id = $reparser->get_max_id(); + $n = 100; + while ($id > 0) + { + $start = max(0, $id + 1 - $n); + $end = $id; + $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); + $reparser->reparse_range($start, $end); + $id -= $n; + } + } +} -- cgit v1.2.1 From 119f90e36301463ffd01005a9390d3346be7774f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 22:15:08 +0200 Subject: [ticket/13891] Replaced ContainerBuilder with service_collection PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/list_all.php | 7 +++---- phpBB/phpbb/console/command/reparser/reparse.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 10db568386..1589836ddd 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -15,7 +15,6 @@ namespace phpbb\console\command\reparser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; class list_all extends \phpbb\console\command\command { @@ -28,13 +27,13 @@ class list_all extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param ContainerBuilder $container Container used to locate the reparsers + * @param \phpbb\di\service_collection $reparsers */ - public function __construct(\phpbb\user $user, ContainerBuilder $container) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { parent::__construct($user); $this->reparser_names = array(); - foreach (array_keys($container->findTaggedServiceIds('text_reparser.plugin')) as $name) + foreach ($reparsers as $name => $reparser) { // Store the names without the "text_reparser." prefix $this->reparser_names[] = str_replace('text_reparser.', '', $name); diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index f2bbe9c7d1..8cefee837f 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -20,21 +20,21 @@ use Symfony\Component\Console\Output\OutputInterface; class reparse extends \phpbb\console\command\command { /** - * @var \phpbb\textreparser\reparser_collection + * @var \phpbb\di\service_collection */ - protected $reparser_collection; + protected $reparsers; /** * Constructor * * @param \phpbb\user $user - * @param \phpbb\textreparser\reparser_collection $reparser_collection + * @param \phpbb\di\service_collection $reparser_collection */ - public function __construct(\phpbb\user $user, \phpbb\textreparser\reparser_collection $reparser_collection) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { require_once __DIR__ . '/../../../../includes/functions_content.php'; - $this->reparser_collection = $reparser_collection; + $this->reparsers = $reparsers; parent::__construct($user); } @@ -65,7 +65,7 @@ class reparse extends \phpbb\console\command\command if (isset($name)) { // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparser_collection[$name])) + if (!isset($this->reparsers[$name])) { $name = 'text_reparser.' . $name; } @@ -73,7 +73,7 @@ class reparse extends \phpbb\console\command\command } else { - foreach ($this->reparser_collection as $name => $service) + foreach ($this->reparsers as $name => $service) { $this->reparse($output, $name); } @@ -91,7 +91,7 @@ class reparse extends \phpbb\console\command\command */ protected function reparse(OutputInterface $output, $name) { - $reparser = $this->reparser_collection[$name]; + $reparser = $this->reparsers[$name]; $id = $reparser->get_max_id(); $n = 100; while ($id > 0) -- cgit v1.2.1 From fadb192c570db25fe4b36b1b3803fb923e6f9d4e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 29 Jun 2015 23:05:52 +0200 Subject: [ticket/13891] Added command-line options PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 43 +++++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 8cefee837f..5e1993d44c 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\reparser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class reparse extends \phpbb\console\command\command @@ -49,6 +50,26 @@ class reparse extends \phpbb\console\command\command ->setName('reparser:reparse') ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) + ->addOption( + 'range-min', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'), + 0 + ) + ->addOption( + 'range-max', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX') + ) + ->addOption( + 'range-size', + null, + InputOption::VALUE_REQUIRED, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'), + 100 + ); ; } @@ -69,13 +90,13 @@ class reparse extends \phpbb\console\command\command { $name = 'text_reparser.' . $name; } - $this->reparse($output, $name); + $this->reparse($input, $output, $name); } else { foreach ($this->reparsers as $name => $service) { - $this->reparse($output, $name); + $this->reparse($input, $output, $name); } } @@ -83,24 +104,28 @@ class reparse extends \phpbb\console\command\command } /** - * Reparse all text handled by given reparser + * Reparse all text handled by given reparser within given range * + * @param InputInterface $input * @param OutputInterface $output * @param string $name Reparser name * @return null */ - protected function reparse(OutputInterface $output, $name) + protected function reparse(InputInterface $input, OutputInterface $output, $name) { $reparser = $this->reparsers[$name]; - $id = $reparser->get_max_id(); - $n = 100; - while ($id > 0) + + // Start at range-max if specified or at the highest ID otherwise + $id = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $min = $input->getOption('range-min'); + $size = $input->getOption('range-size'); + while ($id > $min) { - $start = max(0, $id + 1 - $n); + $start = max($min, $id + 1 - $size); $end = $id; $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); $reparser->reparse_range($start, $end); - $id -= $n; + $id -= $size; } } } -- cgit v1.2.1 From 6de5e5cc36d4b934cfa4043faf12adb279f8a2c6 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 00:28:02 +0200 Subject: [ticket/13891] Added a progress bar PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 5e1993d44c..a2b8b71818 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\reparser; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -116,16 +117,29 @@ class reparse extends \phpbb\console\command\command $reparser = $this->reparsers[$name]; // Start at range-max if specified or at the highest ID otherwise - $id = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); $min = $input->getOption('range-min'); $size = $input->getOption('range-size'); - while ($id > $min) + + $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); + + $progress = new ProgressBar($output, $max - $min); + $progress->start(); + + // Start from $max and decrement $current by $size until we reach $min + $current = $max; + while ($current > $min) { - $start = max($min, $id + 1 - $size); - $end = $id; - $output->writeln('' . $this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $name, $start, $end) . ''); + $start = max($min, $current + 1 - $size); + $end = $current; $reparser->reparse_range($start, $end); - $id -= $size; + + $current = max($min, $start - 1); + $progress->setProgress($max - $current); } + $progress->finish(); + + // The progress bar does not seem to end with a newline so we add one manually + $output->writeLn(''); } } -- cgit v1.2.1 From c7f10ec4d455877b8df96c00f28ada0bcb84f17b Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 30 Jun 2015 09:55:23 +0200 Subject: [ticket/13891] Updated range description Does not count #0 as a potential record PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index a2b8b71818..e922ea90e3 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -56,7 +56,7 @@ class reparse extends \phpbb\console\command\command null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'), - 0 + 1 ) ->addOption( 'range-max', @@ -123,19 +123,19 @@ class reparse extends \phpbb\console\command\command $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); - $progress = new ProgressBar($output, $max - $min); + $progress = new ProgressBar($output, $max + 1 - $min); $progress->start(); // Start from $max and decrement $current by $size until we reach $min $current = $max; - while ($current > $min) + while ($current >= $min) { $start = max($min, $current + 1 - $size); - $end = $current; + $end = max($min, $current); $reparser->reparse_range($start, $end); - $current = max($min, $start - 1); - $progress->setProgress($max - $current); + $current = $start - 1; + $progress->setProgress($max + 1 - $start); } $progress->finish(); -- cgit v1.2.1 From 6b68544483fb8674949e1d3a69eae997cef6afbe Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 1 Jul 2015 15:49:32 +0200 Subject: [ticket/13891] Use the SymfonyStyle in the reparse command PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 39 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index e922ea90e3..2220e53193 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,11 +13,11 @@ namespace phpbb\console\command\reparser; -use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { @@ -26,6 +26,11 @@ class reparse extends \phpbb\console\command\command */ protected $reparsers; + /** + * @var SymfonyStyle + */ + protected $io; + /** * Constructor * @@ -83,6 +88,8 @@ class reparse extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->io = new SymfonyStyle($input, $output); + $name = $input->getArgument('reparser-name'); if (isset($name)) { @@ -101,6 +108,8 @@ class reparse extends \phpbb\console\command\command } } + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + return 0; } @@ -121,9 +130,28 @@ class reparse extends \phpbb\console\command\command $min = $input->getOption('range-min'); $size = $input->getOption('range-size'); - $output->writeLn($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max) . ''); + if ($max === 0) + { + return; + } + + $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max)); + $this->io->newLine(2); + + $progress = $this->io->createProgressBar($max); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %message%\n"); + $progress->setBarWidth(60); + $progress->setMessage(''); + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } - $progress = new ProgressBar($output, $max + 1 - $min); $progress->start(); // Start from $max and decrement $current by $size until we reach $min @@ -132,6 +160,8 @@ class reparse extends \phpbb\console\command\command { $start = max($min, $current + 1 - $size); $end = max($min, $current); + + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end)); $reparser->reparse_range($start, $end); $current = $start - 1; @@ -139,7 +169,6 @@ class reparse extends \phpbb\console\command\command } $progress->finish(); - // The progress bar does not seem to end with a newline so we add one manually - $output->writeLn(''); + $this->io->newLine(2); } } -- cgit v1.2.1 From dd131d74390a8c8766c28734efebede681e3b794 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Thu, 2 Jul 2015 12:22:51 +0200 Subject: [ticket/13891] Added elapsed/estimated time and memory to the progress bar Also fixed some extra whitespace. PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 2220e53193..3aac0e3e93 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -27,8 +27,8 @@ class reparse extends \phpbb\console\command\command protected $reparsers; /** - * @var SymfonyStyle - */ + * @var SymfonyStyle + */ protected $io; /** @@ -141,7 +141,7 @@ class reparse extends \phpbb\console\command\command $progress = $this->io->createProgressBar($max); $progress->setFormat( " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message%\n"); + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); $progress->setBarWidth(60); $progress->setMessage(''); -- cgit v1.2.1 From 5970d0360c5b60a5af7bbaef37ffb8bb9932f8a8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 2 Jul 2015 13:40:02 +0200 Subject: [ticket/13891] Handle verbosity PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 3aac0e3e93..c261507a57 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -136,14 +136,28 @@ class reparse extends \phpbb\console\command\command } $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max)); - $this->io->newLine(2); $progress = $this->io->createProgressBar($max); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - $progress->setMessage(''); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $this->io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name))); if (!defined('PHP_WINDOWS_VERSION_BUILD')) { -- cgit v1.2.1 From b251d9831476754d6db4f0314cbc7607c57d7128 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 2 Jul 2015 15:26:49 +0200 Subject: [ticket/13891] Fix CS PHPBB3-13891 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index c261507a57..52075dd0ac 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -143,7 +143,7 @@ class reparse extends \phpbb\console\command\command $progress->setFormat('[%percent:3s%%] %message%'); $progress->setOverwrite(false); } - elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); $progress->setOverwrite(false); -- cgit v1.2.1 From 7ccb6389124c5e990abaa917a6684fc3f4d072db Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:43:43 +0200 Subject: [ticket/13987] Add --dry-run option to reparser CLI PHPBB3-13987 --- phpBB/phpbb/console/command/reparser/reparse.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 52075dd0ac..8352c523de 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -56,6 +56,12 @@ class reparse extends \phpbb\console\command\command ->setName('reparser:reparse') ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE')) ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1')) + ->addOption( + 'dry-run', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN') + ) ->addOption( 'range-min', null, @@ -126,9 +132,10 @@ class reparse extends \phpbb\console\command\command $reparser = $this->reparsers[$name]; // Start at range-max if specified or at the highest ID otherwise - $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); - $min = $input->getOption('range-min'); - $size = $input->getOption('range-size'); + $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $min = $input->getOption('range-min'); + $size = $input->getOption('range-size'); + $dry_run = $input->getOption('dry-run'); if ($max === 0) { @@ -176,7 +183,7 @@ class reparse extends \phpbb\console\command\command $end = max($min, $current); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end)); - $reparser->reparse_range($start, $end); + $reparser->reparse_range($start, $end, $dry_run); $current = $start - 1; $progress->setProgress($max + 1 - $start); -- cgit v1.2.1 From cf4cdcda586a2371aa92ae452951f9660737ae09 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Mon, 6 Jul 2015 01:57:54 +0200 Subject: [ticket/13987] Replaced optional parameter with explicit API Added disable_save() and enable_save() to toggle a dry run PHPBB3-13987 --- phpBB/phpbb/console/command/reparser/reparse.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 8352c523de..151e196358 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -130,12 +130,19 @@ class reparse extends \phpbb\console\command\command protected function reparse(InputInterface $input, OutputInterface $output, $name) { $reparser = $this->reparsers[$name]; + if ($input->getOption('dry-run')) + { + $reparser->disable_save(); + } + else + { + $reparser->enable_save(); + } // Start at range-max if specified or at the highest ID otherwise - $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); - $min = $input->getOption('range-min'); - $size = $input->getOption('range-size'); - $dry_run = $input->getOption('dry-run'); + $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); + $min = $input->getOption('range-min'); + $size = $input->getOption('range-size'); if ($max === 0) { @@ -183,7 +190,7 @@ class reparse extends \phpbb\console\command\command $end = max($min, $current); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end)); - $reparser->reparse_range($start, $end, $dry_run); + $reparser->reparse_range($start, $end); $current = $start - 1; $progress->setProgress($max + 1 - $start); -- cgit v1.2.1 From 98ab5478e6a74b4325f002c1a5daae9d6dbe80e1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 12 Jun 2014 14:20:58 +0200 Subject: [ticket/12692] Add a console command to manage the thumbnails PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 111 +++++++++++++++++ phpBB/phpbb/console/command/thumbnail/generate.php | 133 +++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/recreate.php | 84 +++++++++++++ 3 files changed, 328 insertions(+) create mode 100644 phpBB/phpbb/console/command/thumbnail/delete.php create mode 100644 phpBB/phpbb/console/command/thumbnail/generate.php create mode 100644 phpBB/phpbb/console/command/thumbnail/recreate.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php new file mode 100644 index 0000000000..81f1baf1db --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -0,0 +1,111 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\thumbnail; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\OutputInterface; + +class delete extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\user */ + protected $user; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param \phpbb\user $user The user object (used to get language information) + * @param string $phpbb_root_path Root path + */ + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path) + { + $this->db = $db; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('thumbnail:delete') + ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE')) + ; + } + + /** + * Executes the command thumbnail:delete. + * + * @param InputInterface $input The input stream used to get the argument and verboe option. + * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. + * + * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted. + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 1'; + $result = $this->db->sql_query($sql); + + $thumbnail_deleted = array(); + $return = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $thumbnail_path = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename']; + + if (@unlink($thumbnail_path)) + { + $thumbnail_deleted[] = $row['attach_id']; + if ($input->getOption('verbose')) + { + $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); + } + } + else + { + if ($input->getOption('verbose')) + { + $return = 1; + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + } + } + } + $this->db->sql_freeresult($result); + + if (sizeof($thumbnail_deleted)) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 0 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted); + $this->db->sql_query($sql); + } + + return $return; + } +} diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php new file mode 100644 index 0000000000..dcf60e4fe2 --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -0,0 +1,133 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\thumbnail; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class generate extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\user */ + protected $user; + + /** @var \phpbb\cache\service */ + protected $cache; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP extension. + * + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param \phpbb\user $user The user object (used to get language information) + * @param \phpbb\cache\service $cache The cache service + * @param string $phpbb_root_path Root path + * @param string $php_ext PHP extension + */ + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->user = $user; + $this->cache = $cache; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('thumbnail:generate') + ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE')) + ; + } + + /** + * Executes the command thumbnail:generate. + * + * @param InputInterface $input The input stream used to get the argument and verboe option. + * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. + * + * @return int 0. + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $extensions = $this->cache->obtain_attach_extensions(true); + + $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 0'; + $result = $this->db->sql_query($sql); + + if (!function_exists('create_thumbnail')) + { + require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); + } + + $thumbnail_created = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) + { + $source = $this->phpbb_root_path . 'files/' . $row['physical_filename']; + $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename']; + + if (!create_thumbnail($source, $destination, $row['mimetype'])) + { + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + } + } + else + { + $thumbnail_created[] = $row['attach_id']; + if ($input->getOption('verbose')) + { + $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + } + } + } + } + $this->db->sql_freeresult($result); + + if (sizeof($thumbnail_created)) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 1 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); + $this->db->sql_query($sql); + } + + return 0; + } +} diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php new file mode 100644 index 0000000000..569642f2a4 --- /dev/null +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -0,0 +1,84 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\thumbnail; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\OutputInterface; + +class recreate extends \phpbb\console\command\command +{ + /** @var \phpbb\user */ + protected $user; + + /** + * Constructor + * + * @param \phpbb\user $user The user object (used to get language information) + */ + public function __construct(\phpbb\user $user) + { + $this->user = $user; + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('thumbnail:recreate') + ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_RECREATE')) + ; + } + + /** + * Executes the command thumbnail:recreate. + * + * @param InputInterface $input The input stream used to get the argument and verboe option. + * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. + * + * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted. + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $parameters = array( + 'command' => 'thumbnail:delete' + ); + + if ($input->getOption('verbose')) + { + $parameters['-v'] = true; + } + + $this->getApplication()->setAutoExit(false); + + $input_delete = new ArrayInput($parameters); + $return = $this->getApplication()->run($input_delete, $output); + + if ($return == 0) + { + $parameters['command'] = 'thumbnail:generate'; + + $input_create = new ArrayInput($parameters); + $return = $this->getApplication()->run($input_create, $output); + } + + $this->getApplication()->setAutoExit(true); + + return $return; + } +} -- cgit v1.2.1 From 074dfdbdfea364cc2796d69c4d27535ab19fdac7 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 15:46:09 +0200 Subject: [ticket/12692] Update doc blocks PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 4 +++- phpBB/phpbb/console/command/thumbnail/generate.php | 2 ++ phpBB/phpbb/console/command/thumbnail/recreate.php | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 81f1baf1db..707c05ffea 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -61,7 +61,9 @@ class delete extends \phpbb\console\command\command /** * Executes the command thumbnail:delete. * - * @param InputInterface $input The input stream used to get the argument and verboe option. + * Delete all the existing thumbnails (and update the database in consequences). + * + * @param InputInterface $input The input stream used to get the argument and verbose option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * * @return int 0 if all is ok, 1 if a thumbnail couldn't be deleted. diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index dcf60e4fe2..bbe6677650 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -74,6 +74,8 @@ class generate extends \phpbb\console\command\command /** * Executes the command thumbnail:generate. * + * Generate a thumbnail for all attachments which need one and don't have it yet. + * * @param InputInterface $input The input stream used to get the argument and verboe option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 569642f2a4..71c5d90654 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -48,6 +48,8 @@ class recreate extends \phpbb\console\command\command /** * Executes the command thumbnail:recreate. * + * This command is a "macro" to execute thumbnail:delete and then thumbnail:generate. + * * @param InputInterface $input The input stream used to get the argument and verboe option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * -- cgit v1.2.1 From 3a0883e93ebd542c1cf67203b4c17456d8308426 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 21:43:44 +0200 Subject: [ticket/12692] Use !empty() instead of sizeof() PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- phpBB/phpbb/console/command/thumbnail/generate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 707c05ffea..ba6fdf7ce6 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -100,7 +100,7 @@ class delete extends \phpbb\console\command\command } $this->db->sql_freeresult($result); - if (sizeof($thumbnail_deleted)) + if (!empty($thumbnail_deleted)) { $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET thumbnail = 0 diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index bbe6677650..ac9d18d933 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -122,7 +122,7 @@ class generate extends \phpbb\console\command\command } $this->db->sql_freeresult($result); - if (sizeof($thumbnail_created)) + if (!empty($thumbnail_created)) { $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET thumbnail = 1 -- cgit v1.2.1 From 3924428050d4225c073876bd0e22cf4e9f54138e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 13 Jun 2014 21:47:35 +0200 Subject: [ticket/12692] Use strict comparison in thumbnail:recreate PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/recreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 71c5d90654..69ea67e410 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -71,7 +71,7 @@ class recreate extends \phpbb\console\command\command $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); - if ($return == 0) + if ($return === 0) { $parameters['command'] = 'thumbnail:generate'; -- cgit v1.2.1 From ed0e1590800e00b19115ad1712e75f33d3080a5e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:13:34 +0200 Subject: [ticket/12692] Fix coding style PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- phpBB/phpbb/console/command/thumbnail/recreate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index ba6fdf7ce6..52a6c424e6 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; -class delete extends \phpbb\console\command\command +class delete extends \phpbb\console\command\command { /** @var \phpbb\db\driver\driver_interface */ protected $db; diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 69ea67e410..dd10da9106 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; -class recreate extends \phpbb\console\command\command +class recreate extends \phpbb\console\command\command { /** @var \phpbb\user */ protected $user; -- cgit v1.2.1 From 3f0fa70e3afb0ce2dbca72bd74b17c93a2756e02 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:14:26 +0200 Subject: [ticket/12692] Update comments PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 52a6c424e6..82a53727ab 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -61,7 +61,7 @@ class delete extends \phpbb\console\command\command /** * Executes the command thumbnail:delete. * - * Delete all the existing thumbnails (and update the database in consequences). + * Deletes all existing thumbnails and updates the database accordingly. * * @param InputInterface $input The input stream used to get the argument and verbose option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. -- cgit v1.2.1 From 6b5fdc730fe1b73bab9ecfe748009bc90d1950f3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:16:28 +0200 Subject: [ticket/12692] Remove a not and swap the blocks in the corresponding if PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/generate.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index ac9d18d933..1cfb2159d9 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -103,19 +103,19 @@ class generate extends \phpbb\console\command\command $source = $this->phpbb_root_path . 'files/' . $row['physical_filename']; $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename']; - if (!create_thumbnail($source, $destination, $row['mimetype'])) + if (create_thumbnail($source, $destination, $row['mimetype'])) { + $thumbnail_created[] = $row['attach_id']; if ($input->getOption('verbose')) { - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } } else { - $thumbnail_created[] = $row['attach_id']; if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } } -- cgit v1.2.1 From c96cc2cb05de05c9599ca27241e903ea6fada3a3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:17:26 +0200 Subject: [ticket/12692] Cast the ids to int PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/generate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 1cfb2159d9..1070b7b37a 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -105,7 +105,7 @@ class generate extends \phpbb\console\command\command if (create_thumbnail($source, $destination, $row['mimetype'])) { - $thumbnail_created[] = $row['attach_id']; + $thumbnail_created[] = (int) $row['attach_id']; if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); -- cgit v1.2.1 From 54be6b1f622cf394f3cb2c7eb5f2c27072018baa Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 17 Jun 2014 22:24:45 +0200 Subject: [ticket/12692] Update the database regularly PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 25 ++++++++++++++++++---- phpBB/phpbb/console/command/thumbnail/generate.php | 25 ++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 82a53727ab..7c66011d5c 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -84,6 +84,13 @@ class delete extends \phpbb\console\command\command if (@unlink($thumbnail_path)) { $thumbnail_deleted[] = $row['attach_id']; + + if (sizeof($thumbnail_deleted) === 250) + { + $this->commit_changes($thumbnail_deleted); + $thumbnail_deleted = array(); + } + if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); @@ -102,12 +109,22 @@ class delete extends \phpbb\console\command\command if (!empty($thumbnail_deleted)) { - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET thumbnail = 0 - WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted); - $this->db->sql_query($sql); + $this->commit_changes($thumbnail_deleted); } return $return; } + + /** + * Commits the changes to the database + * + * @param array $thumbnail_deleted + */ + protected function commit_changes(array $thumbnail_deleted) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 0 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted); + $this->db->sql_query($sql); + } } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 1070b7b37a..c27d91d4d5 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -106,6 +106,13 @@ class generate extends \phpbb\console\command\command if (create_thumbnail($source, $destination, $row['mimetype'])) { $thumbnail_created[] = (int) $row['attach_id']; + + if (sizeof($thumbnail_created) === 250) + { + $this->commit_changes($thumbnail_created); + $thumbnail_created = array(); + } + if ($input->getOption('verbose')) { $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); @@ -124,12 +131,22 @@ class generate extends \phpbb\console\command\command if (!empty($thumbnail_created)) { - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET thumbnail = 1 - WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); - $this->db->sql_query($sql); + $this->commit_changes($thumbnail_created); } return 0; } + + /** + * Commits the changes to the database + * + * @param array $thumbnail_created + */ + protected function commit_changes(array $thumbnail_created) + { + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET thumbnail = 1 + WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created); + $this->db->sql_query($sql); + } } -- cgit v1.2.1 From 487fea8cfffe872e888ebcc3e1f5538b72bcaec1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 22 Jul 2014 16:24:40 +0200 Subject: [ticket/12692] Move the language strings to cli.php PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 16 +++++++--------- phpBB/phpbb/console/command/thumbnail/generate.php | 19 ++++++++++--------- phpBB/phpbb/console/command/thumbnail/recreate.php | 14 -------------- 3 files changed, 17 insertions(+), 32 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 7c66011d5c..b60ea5238f 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -13,17 +13,15 @@ namespace phpbb\console\command\thumbnail; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; class delete extends \phpbb\console\command\command { - /** @var \phpbb\db\driver\driver_interface */ + /** + * @var \phpbb\db\driver\driver_interface + */ protected $db; - /** @var \phpbb\user */ - protected $user; - /** * phpBB root path * @var string @@ -33,16 +31,16 @@ class delete extends \phpbb\console\command\command /** * Constructor * - * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\user $user The user object (used to get language information) + * @param \phpbb\db\driver\driver_interface $db Database connection * @param string $phpbb_root_path Root path */ - public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $phpbb_root_path) + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path) { $this->db = $db; - $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; - parent::__construct(); + + parent::__construct($user); } /** diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index c27d91d4d5..640d971b5d 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -17,13 +17,14 @@ use Symfony\Component\Console\Output\OutputInterface; class generate extends \phpbb\console\command\command { - /** @var \phpbb\db\driver\driver_interface */ + /** + * @var \phpbb\db\driver\driver_interface + */ protected $db; - /** @var \phpbb\user */ - protected $user; - - /** @var \phpbb\cache\service */ + /** + * @var \phpbb\cache\service + */ protected $cache; /** @@ -42,20 +43,20 @@ class generate extends \phpbb\console\command\command /** * Constructor * - * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\user $user The user object (used to get language information) + * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\cache\service $cache The cache service * @param string $phpbb_root_path Root path * @param string $php_ext PHP extension */ - public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext) { $this->db = $db; - $this->user = $user; $this->cache = $cache; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - parent::__construct(); + + parent::__construct($user); } /** diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index dd10da9106..624e4e507f 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -18,20 +18,6 @@ use Symfony\Component\Console\Output\OutputInterface; class recreate extends \phpbb\console\command\command { - /** @var \phpbb\user */ - protected $user; - - /** - * Constructor - * - * @param \phpbb\user $user The user object (used to get language information) - */ - public function __construct(\phpbb\user $user) - { - $this->user = $user; - parent::__construct(); - } - /** * Sets the command name and description * -- cgit v1.2.1 From 24e39545ae77a78fb1f5350b4fe5658c924ad75c Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 15:18:08 +0200 Subject: [ticket/12692] Add output PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 30 ++++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/generate.php | 30 ++++++++++++++++++++++ phpBB/phpbb/console/command/thumbnail/recreate.php | 3 +++ 3 files changed, 63 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index b60ea5238f..b57fcc681f 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -68,11 +68,31 @@ class delete extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 1'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; + if ($nb_missing_thumbnails === 0) + { + $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_DELETE') . ''); + return 0; + } + $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); + if (!$input->getOption('verbose')) + { + $progress = $this->getHelper('progress'); + $progress->start($output, $nb_missing_thumbnails); + } + $thumbnail_deleted = array(); $return = 0; while ($row = $this->db->sql_fetchrow($result)) @@ -102,6 +122,11 @@ class delete extends \phpbb\console\command\command $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } + + if (!$input->getOption('verbose')) + { + $progress->advance(); + } } $this->db->sql_freeresult($result); @@ -110,6 +135,11 @@ class delete extends \phpbb\console\command\command $this->commit_changes($thumbnail_deleted); } + if (!$input->getOption('verbose')) + { + $progress->finish(); + } + return $return; } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 640d971b5d..068bd0ff94 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -84,6 +84,20 @@ class generate extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails + FROM ' . ATTACHMENTS_TABLE . ' + WHERE thumbnail = 0'; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; + if ($nb_missing_thumbnails === 0) + { + $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); + return 0; + } + $extensions = $this->cache->obtain_attach_extensions(true); $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype @@ -96,6 +110,12 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } + if (!$input->getOption('verbose')) + { + $progress = $this->getHelper('progress'); + $progress->start($output, $nb_missing_thumbnails); + } + $thumbnail_created = array(); while ($row = $this->db->sql_fetchrow($result)) { @@ -127,6 +147,11 @@ class generate extends \phpbb\console\command\command } } } + + if (!$input->getOption('verbose')) + { + $progress->advance(); + } } $this->db->sql_freeresult($result); @@ -135,6 +160,11 @@ class generate extends \phpbb\console\command\command $this->commit_changes($thumbnail_created); } + if (!$input->getOption('verbose')) + { + $progress->finish(); + } + return 0; } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 624e4e507f..ec093161af 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -54,6 +54,7 @@ class recreate extends \phpbb\console\command\command $this->getApplication()->setAutoExit(false); + $output->writeln('' . $this->user->lang('THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -61,6 +62,8 @@ class recreate extends \phpbb\console\command\command { $parameters['command'] = 'thumbnail:generate'; + $output->writeln(''); + $output->writeln('' . $this->user->lang('THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From 0f789f4d5ac39f056569544eb1fad3545d80e9d3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 18 Aug 2014 16:23:12 +0200 Subject: [ticket/12692] Fix languages files PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 3 +-- phpBB/phpbb/console/command/thumbnail/generate.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index b57fcc681f..3a60271fc2 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -72,10 +72,9 @@ class delete extends \phpbb\console\command\command FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails'); $this->db->sql_freeresult($result); - $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; if ($nb_missing_thumbnails === 0) { $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_DELETE') . ''); diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 068bd0ff94..d7530881f1 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -88,10 +88,9 @@ class generate extends \phpbb\console\command\command FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 0'; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails'); $this->db->sql_freeresult($result); - $nb_missing_thumbnails = (int) $row['nb_missing_thumbnails']; if ($nb_missing_thumbnails === 0) { $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); -- cgit v1.2.1 From e3e293f5a6b38bb85f57841756a362e26b09088b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 30 Aug 2014 18:17:23 +0200 Subject: [ticket/12692] Cleanup language file PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 6 +++--- phpBB/phpbb/console/command/thumbnail/generate.php | 6 +++--- phpBB/phpbb/console/command/thumbnail/recreate.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index 3a60271fc2..fb63f7c510 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -77,7 +77,7 @@ class delete extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_DELETE') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE') . ''); return 0; } @@ -110,7 +110,7 @@ class delete extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); + $output->writeln($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); } } else @@ -118,7 +118,7 @@ class delete extends \phpbb\console\command\command if ($input->getOption('verbose')) { $return = 1; - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index d7530881f1..0f4a40bd9f 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -93,7 +93,7 @@ class generate extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('NO_THUMBNAIL_TO_GENERATE') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE') . ''); return 0; } @@ -135,14 +135,14 @@ class generate extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); + $output->writeln($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } } else { if ($input->getOption('verbose')) { - $output->writeln('' . $this->user->lang('THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index ec093161af..5d3edbd699 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -54,7 +54,7 @@ class recreate extends \phpbb\console\command\command $this->getApplication()->setAutoExit(false); - $output->writeln('' . $this->user->lang('THUMBNAIL_DELETING') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -63,7 +63,7 @@ class recreate extends \phpbb\console\command\command $parameters['command'] = 'thumbnail:generate'; $output->writeln(''); - $output->writeln('' . $this->user->lang('THUMBNAIL_GENERATING') . ''); + $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From af7872473d41b4fd82a850e87f9e74a72a5b3230 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 16 Jul 2015 22:52:25 -0700 Subject: [ticket/14033] Fix errors in docblocks PHPBB3-14033 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 151e196358..a58bf20193 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -35,7 +35,7 @@ class reparse extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param \phpbb\di\service_collection $reparser_collection + * @param \phpbb\di\service_collection $reparsers */ public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) { -- cgit v1.2.1 From e7763cd273a88e4b99c67e2a74b83ed3ef86727f Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 08:26:14 +0200 Subject: [ticket/14034] Fix reparser names that contain "text_reparser" in the middle PHPBB3-14034 --- phpBB/phpbb/console/command/reparser/list_all.php | 2 +- phpBB/phpbb/console/command/reparser/reparse.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 1589836ddd..e42c3ac782 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -36,7 +36,7 @@ class list_all extends \phpbb\console\command\command foreach ($reparsers as $name => $reparser) { // Store the names without the "text_reparser." prefix - $this->reparser_names[] = str_replace('text_reparser.', '', $name); + $this->reparser_names[] = preg_replace('(^text_reparser\\.)', '', $name); } } diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 151e196358..81d1aa0421 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -149,7 +149,7 @@ class reparse extends \phpbb\console\command\command return; } - $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $min, $max)); + $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); $progress = $this->io->createProgressBar($max); if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) @@ -171,7 +171,7 @@ class reparse extends \phpbb\console\command\command $progress->setBarWidth(60); } - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', str_replace('text_reparser.', '', $name))); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); if (!defined('PHP_WINDOWS_VERSION_BUILD')) { @@ -189,7 +189,7 @@ class reparse extends \phpbb\console\command\command $start = max($min, $current + 1 - $size); $end = max($min, $current); - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', str_replace('text_reparser.', '', $name), $start, $end)); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $start, $end)); $reparser->reparse_range($start, $end); $current = $start - 1; -- cgit v1.2.1 From 903f100c5120ad516e248ee30b18dd9a64468656 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 11:53:28 +0200 Subject: [ticket/13986] Add --resume option to reparser CLI PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 185 ++++++++++++++++++----- 1 file changed, 144 insertions(+), 41 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 50d4bd01d6..44a4691981 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -22,25 +22,47 @@ use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { /** - * @var \phpbb\di\service_collection + * @var \phpbb\config\db_text */ - protected $reparsers; + protected $config_text; + + /** + * @var InputInterface + */ + protected $input; /** * @var SymfonyStyle */ protected $io; + /** + * @var OutputInterface + */ + protected $output; + + /** + * @var \phpbb\di\service_collection + */ + protected $reparsers; + + /** + * @var array Reparser names as keys, and their last $current ID as values + */ + protected $resume_data; + /** * Constructor * * @param \phpbb\user $user * @param \phpbb\di\service_collection $reparsers + * @param \phpbb\config\db_text $config_text */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text) { require_once __DIR__ . '/../../../../includes/functions_content.php'; + $this->config_text = $config_text; $this->reparsers = $reparsers; parent::__construct($user); } @@ -62,6 +84,12 @@ class reparse extends \phpbb\console\command\command InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN') ) + ->addOption( + 'resume', + null, + InputOption::VALUE_NONE, + $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME') + ) ->addOption( 'range-min', null, @@ -85,6 +113,44 @@ class reparse extends \phpbb\console\command\command ; } + /** + * Create a styled progress bar + * + * @param integer $max Max value for the progress bar + * @return \Symfony\Component\Console\Helper\ProgressBar + */ + protected function create_progress_bar($max) + { + $progress = $this->io->createProgressBar($max); + if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $this->io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } + + return $progress; + } + /** * Executes the command reparser:reparse * @@ -94,7 +160,10 @@ class reparse extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->input = $input; + $this->output = $output; $this->io = new SymfonyStyle($input, $output); + $this->load_resume_data(); $name = $input->getArgument('reparser-name'); if (isset($name)) @@ -104,13 +173,13 @@ class reparse extends \phpbb\console\command\command { $name = 'text_reparser.' . $name; } - $this->reparse($input, $output, $name); + $this->reparse($name); } else { foreach ($this->reparsers as $name => $service) { - $this->reparse($input, $output, $name); + $this->reparse($name); } } @@ -119,18 +188,53 @@ class reparse extends \phpbb\console\command\command return 0; } + /** + * Get an option value, adjusted for given reparser + * + * Will use the last saved value if --resume is set and the option was not specified + * on the command line + * + * @param string $reparser_name Reparser name + * @param string $option_name Option name + * @return integer + */ + protected function get_option($reparser_name, $option_name) + { + // Return the option from the resume_data if applicable + if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) + { + return $this->resume_data[$reparser_name][$option_name]; + } + + $value = $this->input->getOption($option_name); + + // range-max has no default value, it must be computed for each reparser + if ($option_name === 'range-max' && $value === null) + { + $value = $this->reparsers[$reparser_name]->get_max_id(); + } + + return $value; + } + + /** + * Load the resume data from the database + */ + protected function load_resume_data() + { + $resume_data = $this->config_text->get('reparser_resume'); + $this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data); + } + /** * Reparse all text handled by given reparser within given range * - * @param InputInterface $input - * @param OutputInterface $output * @param string $name Reparser name - * @return null */ - protected function reparse(InputInterface $input, OutputInterface $output, $name) + protected function reparse($name) { $reparser = $this->reparsers[$name]; - if ($input->getOption('dry-run')) + if ($this->input->getOption('dry-run')) { $reparser->disable_save(); } @@ -140,9 +244,9 @@ class reparse extends \phpbb\console\command\command } // Start at range-max if specified or at the highest ID otherwise - $max = (is_null($input->getOption('range-max'))) ? $reparser->get_max_id() : $input->getOption('range-max'); - $min = $input->getOption('range-min'); - $size = $input->getOption('range-size'); + $max = $this->get_option($name, 'range-max'); + $min = $this->get_option($name, 'range-min'); + $size = $this->get_option($name, 'range-size'); if ($max === 0) { @@ -151,35 +255,8 @@ class reparse extends \phpbb\console\command\command $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); - $progress = $this->io->createProgressBar($max); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $this->io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - } - + $progress = $this->create_progress_bar($max); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } - $progress->start(); // Start from $max and decrement $current by $size until we reach $min @@ -194,9 +271,35 @@ class reparse extends \phpbb\console\command\command $current = $start - 1; $progress->setProgress($max + 1 - $start); + + $this->update_resume_data($name, $current); } $progress->finish(); $this->io->newLine(2); } + + /** + * Save the resume data to the database + */ + protected function save_resume_data() + { + $this->config_text->set('reparser_resume', serialize($this->resume_data)); + } + + /** + * Save the resume data to the database + * + * @param string $name Reparser name + * @param string $current Current ID + */ + protected function update_resume_data($name, $current) + { + $this->resume_data[$name] = array( + 'range-min' => $this->input->getOption('range-min'), + 'range-max' => $current, + 'range-size' => $this->input->getOption('range-size'), + ); + $this->save_resume_data(); + } } -- cgit v1.2.1 From 9274bc4e3263b4aa9e278009fbc17f10985c439e Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 14:00:47 +0200 Subject: [ticket/13986] Fixed resume data to carry through multiple runs Options restored from a previous execution should carry to the next resumed execution PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 44a4691981..f81ebfa8ca 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -296,9 +296,9 @@ class reparse extends \phpbb\console\command\command protected function update_resume_data($name, $current) { $this->resume_data[$name] = array( - 'range-min' => $this->input->getOption('range-min'), + 'range-min' => $this->get_option($name, 'range-min'), 'range-max' => $current, - 'range-size' => $this->input->getOption('range-size'), + 'range-size' => $this->get_option($name, 'range-size'), ); $this->save_resume_data(); } -- cgit v1.2.1 From c8e209a2dee7548031b4d2b5137c2ef064d6f588 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 17 Jul 2015 16:52:52 +0200 Subject: [ticket/13986] Replaced hardcoded value PHPBB3-13986 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index f81ebfa8ca..63124b4b8c 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -248,7 +248,7 @@ class reparse extends \phpbb\console\command\command $min = $this->get_option($name, 'range-min'); $size = $this->get_option($name, 'range-size'); - if ($max === 0) + if ($max < $min) { return; } -- cgit v1.2.1 From 618065ec16030f1d142667473ee2ff42cd80e72b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 8 Jul 2015 16:58:45 +0200 Subject: [ticket/12692] Fix tests and update style PHPBB3-12692 --- phpBB/phpbb/console/command/thumbnail/delete.php | 63 ++++++++++++++------- phpBB/phpbb/console/command/thumbnail/generate.php | 64 +++++++++++++++------- phpBB/phpbb/console/command/thumbnail/recreate.php | 5 +- 3 files changed, 86 insertions(+), 46 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index fb63f7c510..e8e4cf568e 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -14,6 +14,7 @@ namespace phpbb\console\command\thumbnail; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class delete extends \phpbb\console\command\command { @@ -68,6 +69,10 @@ class delete extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + + $io->section($this->user->lang('CLI_THUMBNAIL_DELETING')); + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 1'; @@ -77,7 +82,7 @@ class delete extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE') . ''); + $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE')); return 0; } @@ -86,12 +91,37 @@ class delete extends \phpbb\console\command\command WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - if (!$input->getOption('verbose')) + $progress = $io->createProgressBar($nb_missing_thumbnails); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) { - $progress = $this->getHelper('progress'); - $progress->start($output, $nb_missing_thumbnails); + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING')); + + $progress->start(); + $thumbnail_deleted = array(); $return = 0; while ($row = $this->db->sql_fetchrow($result)) @@ -108,24 +138,15 @@ class delete extends \phpbb\console\command\command $thumbnail_deleted = array(); } - if ($input->getOption('verbose')) - { - $output->writeln($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); - } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); } else { - if ($input->getOption('verbose')) - { - $return = 1; - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); - } + $return = 1; + $progress->setMessage('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } - if (!$input->getOption('verbose')) - { - $progress->advance(); - } + $progress->advance(); } $this->db->sql_freeresult($result); @@ -134,10 +155,10 @@ class delete extends \phpbb\console\command\command $this->commit_changes($thumbnail_deleted); } - if (!$input->getOption('verbose')) - { - $progress->finish(); - } + $progress->finish(); + + $io->newLine(2); + $io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE')); return $return; } diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index 0f4a40bd9f..e677db3a97 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -10,10 +10,12 @@ * the docs/CREDITS.txt file. * */ + namespace phpbb\console\command\thumbnail; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class generate extends \phpbb\console\command\command { @@ -84,6 +86,10 @@ class generate extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + + $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING')); + $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails FROM ' . ATTACHMENTS_TABLE . ' WHERE thumbnail = 0'; @@ -93,7 +99,7 @@ class generate extends \phpbb\console\command\command if ($nb_missing_thumbnails === 0) { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE') . ''); + $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE')); return 0; } @@ -109,11 +115,36 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } - if (!$input->getOption('verbose')) + $progress = $io->createProgressBar($nb_missing_thumbnails); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { - $progress = $this->getHelper('progress'); - $progress->start($output, $nb_missing_thumbnails); + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } + + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING')); + + $progress->start(); $thumbnail_created = array(); while ($row = $this->db->sql_fetchrow($result)) @@ -127,30 +158,21 @@ class generate extends \phpbb\console\command\command { $thumbnail_created[] = (int) $row['attach_id']; - if (sizeof($thumbnail_created) === 250) + if (count($thumbnail_created) === 250) { $this->commit_changes($thumbnail_created); $thumbnail_created = array(); } - if ($input->getOption('verbose')) - { - $output->writeln($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); - } + $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); } else { - if ($input->getOption('verbose')) - { - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); - } + $progress->setMessage('' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . ''); } } - if (!$input->getOption('verbose')) - { - $progress->advance(); - } + $progress->advance(); } $this->db->sql_freeresult($result); @@ -159,10 +181,10 @@ class generate extends \phpbb\console\command\command $this->commit_changes($thumbnail_created); } - if (!$input->getOption('verbose')) - { - $progress->finish(); - } + $progress->finish(); + + $io->newLine(2); + $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE')); return 0; } diff --git a/phpBB/phpbb/console/command/thumbnail/recreate.php b/phpBB/phpbb/console/command/thumbnail/recreate.php index 5d3edbd699..382da290bf 100644 --- a/phpBB/phpbb/console/command/thumbnail/recreate.php +++ b/phpBB/phpbb/console/command/thumbnail/recreate.php @@ -49,12 +49,11 @@ class recreate extends \phpbb\console\command\command if ($input->getOption('verbose')) { - $parameters['-v'] = true; + $parameters['-' . str_repeat('v', $output->getVerbosity() - 1)] = true; } $this->getApplication()->setAutoExit(false); - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_DELETING') . ''); $input_delete = new ArrayInput($parameters); $return = $this->getApplication()->run($input_delete, $output); @@ -62,8 +61,6 @@ class recreate extends \phpbb\console\command\command { $parameters['command'] = 'thumbnail:generate'; - $output->writeln(''); - $output->writeln('' . $this->user->lang('CLI_THUMBNAIL_GENERATING') . ''); $input_create = new ArrayInput($parameters); $return = $this->getApplication()->run($input_create, $output); } -- cgit v1.2.1 From 2a07de70c2decb9669990286391cef1d427244bc Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 25 Aug 2015 22:24:37 +0200 Subject: [ticket/14124] Migrate cron:run exceptions PHPBB3-14124 --- phpBB/phpbb/console/command/cron/run.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/cron/run.php b/phpBB/phpbb/console/command/cron/run.php index 72ad1205ef..da185b81b3 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\cron; +use phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; @@ -92,8 +93,7 @@ class run extends \phpbb\console\command\command } else { - $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); - return 1; + throw new runtime_exception('CRON_LOCK_ERROR', array(), null, 1); } } @@ -164,8 +164,7 @@ class run extends \phpbb\console\command\command } else { - $output->writeln('' . $this->user->lang('CRON_NO_SUCH_TASK', $task_name) . ''); - return 2; + throw new runtime_exception('CRON_NO_SUCH_TASK', array( $task_name), null, 2); } } } -- cgit v1.2.1 From 2596fba487a067cba36b5ebe50e1c73e4dc954d3 Mon Sep 17 00:00:00 2001 From: Zoddo Date: Sun, 13 Sep 2015 16:08:22 +0200 Subject: [ticket/14162] Add CLI command db:revert This command allow to revert a migration from the CLI PHPBB3-14162 --- phpBB/phpbb/console/command/db/migrate.php | 37 +--------- .../phpbb/console/command/db/migration_command.php | 56 +++++++++++++++ phpBB/phpbb/console/command/db/revert.php | 83 ++++++++++++++++++++++ 3 files changed, 141 insertions(+), 35 deletions(-) create mode 100644 phpBB/phpbb/console/command/db/migration_command.php create mode 100644 phpBB/phpbb/console/command/db/revert.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index 2490bf1310..43029b7458 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -15,20 +15,8 @@ namespace phpbb\console\command\db; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class migrate extends \phpbb\console\command\command +class migrate extends \phpbb\console\command\db\migration_command { - /** @var \phpbb\db\migrator */ - protected $migrator; - - /** @var \phpbb\extension\manager */ - protected $extension_manager; - - /** @var \phpbb\config\config */ - protected $config; - - /** @var \phpbb\cache\service */ - protected $cache; - /** @var \phpbb\log\log */ protected $log; @@ -40,14 +28,10 @@ class migrate extends \phpbb\console\command\command function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) { - $this->migrator = $migrator; - $this->extension_manager = $extension_manager; - $this->config = $config; - $this->cache = $cache; $this->log = $log; $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; - parent::__construct($user); + parent::__construct($user, $migrator, $extension_manager, $config, $cache); $this->user->add_lang(array('common', 'install', 'migrator')); } @@ -91,21 +75,4 @@ class migrate extends \phpbb\console\command\command $this->finalise_update(); $output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']); } - - protected function load_migrations() - { - $migrations = $this->extension_manager - ->get_finder() - ->core_path('phpbb/db/migration/data/') - ->extension_directory('/migrations') - ->get_classes(); - - $this->migrator->set_migrations($migrations); - } - - protected function finalise_update() - { - $this->cache->purge(); - $this->config->increment('assets_version', 1); - } } diff --git a/phpBB/phpbb/console/command/db/migration_command.php b/phpBB/phpbb/console/command/db/migration_command.php new file mode 100644 index 0000000000..d44ef8c5cb --- /dev/null +++ b/phpBB/phpbb/console/command/db/migration_command.php @@ -0,0 +1,56 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\db; + +abstract class migration_command extends \phpbb\console\command\command +{ + /** @var \phpbb\db\migrator */ + protected $migrator; + + /** @var \phpbb\extension\manager */ + protected $extension_manager; + + /** @var \phpbb\config\config */ + protected $config; + + /** @var \phpbb\cache\service */ + protected $cache; + + function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache) + { + $this->migrator = $migrator; + $this->extension_manager = $extension_manager; + $this->config = $config; + $this->cache = $cache; + parent::__construct($user); + } + + protected function load_migrations() + { + $migrations = $this->extension_manager + ->get_finder() + ->core_path('phpbb/db/migration/data/') + ->extension_directory('/migrations') + ->get_classes(); + + $this->migrator->set_migrations($migrations); + + return $migrations; + } + + protected function finalise_update() + { + $this->cache->purge(); + $this->config->increment('assets_version', 1); + } +} diff --git a/phpBB/phpbb/console/command/db/revert.php b/phpBB/phpbb/console/command/db/revert.php new file mode 100644 index 0000000000..838640968e --- /dev/null +++ b/phpBB/phpbb/console/command/db/revert.php @@ -0,0 +1,83 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\db; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class revert extends \phpbb\console\command\db\migration_command +{ + /** @var string phpBB root path */ + protected $phpbb_root_path; + + /** @var \phpbb\filesystem\filesystem_interface */ + protected $filesystem; + + function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) + { + $this->filesystem = $filesystem; + $this->phpbb_root_path = $phpbb_root_path; + parent::__construct($user, $migrator, $extension_manager, $config, $cache); + $this->user->add_lang(array('common', 'migrator')); + } + + protected function configure() + { + $this + ->setName('db:revert') + ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_REVERT')) + ->addArgument( + 'name', + InputArgument::REQUIRED, + $this->user->lang('CLI_MIGRATION_NAME') + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = str_replace('/', '\\', $input->getArgument('name')); + + $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); + + $this->cache->purge(); + + if (!in_array($name, $this->load_migrations())) + { + $output->writeln('' . $this->user->lang('MIGRATION_NOT_VALID', $name) . ''); + return 1; + } + else if ($this->migrator->migration_state($name) === false) + { + $output->writeln('' . $this->user->lang('MIGRATION_NOT_INSTALLED', $name) . ''); + return 1; + } + + try + { + while ($this->migrator->migration_state($name) !== false) + { + $this->migrator->revert($name); + } + } + catch (\phpbb\db\migration\exception $e) + { + $output->writeln('' . $e->getLocalisedMessage($this->user) . ''); + $this->finalise_update(); + return 1; + } + + $this->finalise_update(); + } +} -- cgit v1.2.1 From 60099cf97c13106b741ab779883a89a0dbc4b6fa Mon Sep 17 00:00:00 2001 From: Zoddo Date: Sun, 13 Sep 2015 17:15:35 +0200 Subject: [ticket/14162] Add CLI command db:list This command lists all installed and uninstalled migrations. Note: The class is named `list_command`, because `list` is a reserved word and can't be used as class name in PHP. PHPBB3-14162 --- phpBB/phpbb/console/command/db/list_command.php | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 phpBB/phpbb/console/command/db/list_command.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/list_command.php b/phpBB/phpbb/console/command/db/list_command.php new file mode 100644 index 0000000000..708107b592 --- /dev/null +++ b/phpBB/phpbb/console/command/db/list_command.php @@ -0,0 +1,73 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\db; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class list_command extends \phpbb\console\command\db\migration_command +{ + protected function configure() + { + $this + ->setName('db:list') + ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_LIST')) + ->addOption( + 'available', + 'u', + InputOption::VALUE_NONE, + $this->user->lang('CLI_MIGRATIONS_ONLY_AVAILABLE') + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $show_installed = !$input->getOption('available'); + $installed = $available = array(); + + foreach ($this->load_migrations() as $name) + { + if ($this->migrator->migration_state($name) !== false) + { + $installed[] = $name; + } + else + { + $available[] = $name; + } + } + + if ($show_installed) + { + $output->writeln('' . $this->user->lang('CLI_MIGRATIONS_INSTALLED') . $this->user->lang('COLON') . ''); + $output->writeln($installed); + + if (empty($installed)) + { + $output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY')); + } + + $output->writeln(''); + } + + $output->writeln('' . $this->user->lang('CLI_MIGRATIONS_AVAILABLE') . $this->user->lang('COLON') . ''); + $output->writeln($available); + + if (empty($available)) + { + $output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY')); + } + } +} -- cgit v1.2.1 From 8f5a0ad6f73e7b7757b02c827436384c96069b5a Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 24 Jul 2015 09:20:50 +0200 Subject: [ticket/14039] Revamp updater PHPBB3-14039 --- .../phpbb/console/command/db/console_migrator_output_handler.php | 2 +- phpBB/phpbb/console/command/db/migrate.php | 9 +++++++-- phpBB/phpbb/console/command/db/revert.php | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/console_migrator_output_handler.php b/phpBB/phpbb/console/command/db/console_migrator_output_handler.php index b9741a3838..568b2646d4 100644 --- a/phpBB/phpbb/console/command/db/console_migrator_output_handler.php +++ b/phpBB/phpbb/console/command/db/console_migrator_output_handler.php @@ -13,8 +13,8 @@ namespace phpbb\console\command\db; +use phpbb\db\output_handler\migrator_output_handler_interface; use phpbb\user; -use phpbb\db\migrator_output_handler_interface; use Symfony\Component\Console\Output\OutputInterface; class console_migrator_output_handler implements migrator_output_handler_interface diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index 43029b7458..ae4211f7be 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -12,6 +12,7 @@ */ namespace phpbb\console\command\db; +use phpbb\db\output_handler\log_wrapper_migrator_output_handler; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -26,8 +27,12 @@ class migrate extends \phpbb\console\command\db\migration_command /** @var \phpbb\filesystem\filesystem_interface */ protected $filesystem; - function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) + /** @var \phpbb\language\language */ + protected $language; + + function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) { + $this->language = $language; $this->log = $log; $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; @@ -45,7 +50,7 @@ class migrate extends \phpbb\console\command\db\migration_command protected function execute(InputInterface $input, OutputInterface $output) { - $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); + $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)); $this->migrator->create_migrations_table(); diff --git a/phpBB/phpbb/console/command/db/revert.php b/phpBB/phpbb/console/command/db/revert.php index 838640968e..3fa2e17515 100644 --- a/phpBB/phpbb/console/command/db/revert.php +++ b/phpBB/phpbb/console/command/db/revert.php @@ -12,6 +12,7 @@ */ namespace phpbb\console\command\db; +use phpbb\db\output_handler\log_wrapper_migrator_output_handler; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -24,9 +25,13 @@ class revert extends \phpbb\console\command\db\migration_command /** @var \phpbb\filesystem\filesystem_interface */ protected $filesystem; - function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) + /** @var \phpbb\language\language */ + protected $language; + + function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) { $this->filesystem = $filesystem; + $this->language = $language; $this->phpbb_root_path = $phpbb_root_path; parent::__construct($user, $migrator, $extension_manager, $config, $cache); $this->user->add_lang(array('common', 'migrator')); @@ -49,7 +54,7 @@ class revert extends \phpbb\console\command\db\migration_command { $name = str_replace('/', '\\', $input->getArgument('name')); - $this->migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($this->user, new console_migrator_output_handler($this->user, $output), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); + $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)); $this->cache->purge(); -- cgit v1.2.1 From c7ecb1310f7663e5fdaafb655381663b9410c31a Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 24 Oct 2015 20:10:16 +0200 Subject: [ticket/14257] Add reparse_lock to CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 50 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 63124b4b8c..e77b384d8e 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\reparser; +use phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -41,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $output; + /** + * @var \phpbb\lock\db + */ + protected $reparse_lock; + /** * @var \phpbb\di\service_collection */ @@ -57,13 +63,15 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\user $user * @param \phpbb\di\service_collection $reparsers * @param \phpbb\config\db_text $config_text + * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text) + public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) { require_once __DIR__ . '/../../../../includes/functions_content.php'; $this->config_text = $config_text; $this->reparsers = $reparsers; + $this->reparse_lock = $reparse_lock; parent::__construct($user); } @@ -163,29 +171,39 @@ class reparse extends \phpbb\console\command\command $this->input = $input; $this->output = $output; $this->io = new SymfonyStyle($input, $output); - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); - if (isset($name)) + if (!$this->reparse_lock->acquire()) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) { - $name = 'text_reparser.' . $name; + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) + { + $name = 'text_reparser.' . $name; + } + $this->reparse($name); } - $this->reparse($name); - } - else - { - foreach ($this->reparsers as $name => $service) + else { - $this->reparse($name); + foreach ($this->reparsers as $name => $service) + { + $this->reparse($name); + } } - } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - return 0; + $this->reparse_lock->release(); + + return 0; + } + else + { + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } } /** -- cgit v1.2.1 From 8b0f8d7b3cf7e7687f11c2fc0a15d4919c91b6c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 25 Oct 2015 02:31:22 +0200 Subject: [ticket/14257] Fix lock acquire in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 42 +++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index e77b384d8e..6fac3db854 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -174,36 +174,34 @@ class reparse extends \phpbb\console\command\command if (!$this->reparse_lock->acquire()) { - $this->load_resume_data(); + throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); + } - $name = $input->getArgument('reparser-name'); - if (isset($name)) + $this->load_resume_data(); + + $name = $input->getArgument('reparser-name'); + if (isset($name)) + { + // Allow "post_text" to be an alias for "text_reparser.post_text" + if (!isset($this->reparsers[$name])) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) - { - $name = 'text_reparser.' . $name; - } - $this->reparse($name); + $name = 'text_reparser.' . $name; } - else + $this->reparse($name); + } + else + { + foreach ($this->reparsers as $name => $service) { - foreach ($this->reparsers as $name => $service) - { - $this->reparse($name); - } + $this->reparse($name); } + } - $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); + $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS')); - $this->reparse_lock->release(); + $this->reparse_lock->release(); - return 0; - } - else - { - throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); - } + return 0; } /** -- cgit v1.2.1 From 25e2b17837f5b1c2330d07a86f88b25bb55d96c1 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:39:52 +0100 Subject: [ticket/14257] Add text_reparser manager PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 54 +++++------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 6fac3db854..575e447a78 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -22,11 +22,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; class reparse extends \phpbb\console\command\command { - /** - * @var \phpbb\config\db_text - */ - protected $config_text; - /** * @var InputInterface */ @@ -47,6 +42,11 @@ class reparse extends \phpbb\console\command\command */ protected $reparse_lock; + /** + * @var \phpbb\textreparser\manager + */ + protected $reparser_manager; + /** * @var \phpbb\di\service_collection */ @@ -65,13 +65,13 @@ class reparse extends \phpbb\console\command\command * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock */ - public function __construct(\phpbb\user $user, \phpbb\di\service_collection $reparsers, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock) + public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { require_once __DIR__ . '/../../../../includes/functions_content.php'; - $this->config_text = $config_text; - $this->reparsers = $reparsers; $this->reparse_lock = $reparse_lock; + $this->reparser_manager = $reparser_manager; + $this->reparsers = $reparsers; parent::__construct($user); } @@ -177,8 +177,6 @@ class reparse extends \phpbb\console\command\command throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1); } - $this->load_resume_data(); - $name = $input->getArgument('reparser-name'); if (isset($name)) { @@ -233,15 +231,6 @@ class reparse extends \phpbb\console\command\command return $value; } - /** - * Load the resume data from the database - */ - protected function load_resume_data() - { - $resume_data = $this->config_text->get('reparser_resume'); - $this->resume_data = (empty($resume_data)) ? array() : unserialize($resume_data); - } - /** * Reparse all text handled by given reparser within given range * @@ -250,6 +239,7 @@ class reparse extends \phpbb\console\command\command protected function reparse($name) { $reparser = $this->reparsers[$name]; + $this->resume_data = $this->reparser_manager->get_resume_data($name); if ($this->input->getOption('dry-run')) { $reparser->disable_save(); @@ -288,34 +278,10 @@ class reparse extends \phpbb\console\command\command $current = $start - 1; $progress->setProgress($max + 1 - $start); - $this->update_resume_data($name, $current); + $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run')); } $progress->finish(); $this->io->newLine(2); } - - /** - * Save the resume data to the database - */ - protected function save_resume_data() - { - $this->config_text->set('reparser_resume', serialize($this->resume_data)); - } - - /** - * Save the resume data to the database - * - * @param string $name Reparser name - * @param string $current Current ID - */ - protected function update_resume_data($name, $current) - { - $this->resume_data[$name] = array( - 'range-min' => $this->get_option($name, 'range-min'), - 'range-max' => $current, - 'range-size' => $this->get_option($name, 'range-size'), - ); - $this->save_resume_data(); - } } -- cgit v1.2.1 From c805fd2a7378bc431ff11f93efd74fb829f558d9 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Mon, 26 Oct 2015 01:49:11 +0100 Subject: [ticket/14257] Fix phpdoc in CLI command PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 575e447a78..6137a79b89 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -61,9 +61,9 @@ class reparse extends \phpbb\console\command\command * Constructor * * @param \phpbb\user $user - * @param \phpbb\di\service_collection $reparsers - * @param \phpbb\config\db_text $config_text * @param \phpbb\lock\db $reparse_lock + * @param \phpbb\textreparser\manager $reparser_manager + * @param \phpbb\di\service_collection $reparsers */ public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers) { -- cgit v1.2.1 From 900ccd79af816d8d54e6974e9163d9999a823513 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sun, 1 Nov 2015 03:49:01 +0100 Subject: [ticket/14257] Fix CLI reparser and set cron interval PHPBB3-14257 --- phpBB/phpbb/console/command/reparser/reparse.php | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index 6137a79b89..ddc97a1d1d 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -53,7 +53,7 @@ class reparse extends \phpbb\console\command\command protected $reparsers; /** - * @var array Reparser names as keys, and their last $current ID as values + * @var array The reparser's last $current ID as values */ protected $resume_data; @@ -208,27 +208,18 @@ class reparse extends \phpbb\console\command\command * Will use the last saved value if --resume is set and the option was not specified * on the command line * - * @param string $reparser_name Reparser name * @param string $option_name Option name * @return integer */ - protected function get_option($reparser_name, $option_name) + protected function get_option($option_name) { // Return the option from the resume_data if applicable - if ($this->input->getOption('resume') && isset($this->resume_data[$reparser_name][$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) + if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name)) { - return $this->resume_data[$reparser_name][$option_name]; + return $this->resume_data[$option_name]; } - $value = $this->input->getOption($option_name); - - // range-max has no default value, it must be computed for each reparser - if ($option_name === 'range-max' && $value === null) - { - $value = $this->reparsers[$reparser_name]->get_max_id(); - } - - return $value; + return $this->input->getOption($option_name); } /** @@ -250,9 +241,15 @@ class reparse extends \phpbb\console\command\command } // Start at range-max if specified or at the highest ID otherwise - $max = $this->get_option($name, 'range-max'); - $min = $this->get_option($name, 'range-min'); - $size = $this->get_option($name, 'range-size'); + $max = $this->get_option('range-max'); + $min = $this->get_option('range-min'); + $size = $this->get_option('range-size'); + + // range-max has no default value, it must be computed for each reparser + if ($max == null) + { + $max = $reparser->get_max_id(); + } if ($max < $min) { -- cgit v1.2.1 From fc72862ca4bb5c9f9b23867173543efb899de4db Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 27 Jan 2016 12:47:31 -0800 Subject: [ticket/14434] Do not include non-migrations in CLI list PHPBB3-14434 --- phpBB/phpbb/console/command/db/list_command.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/list_command.php b/phpBB/phpbb/console/command/db/list_command.php index 708107b592..dfec5c7da2 100644 --- a/phpBB/phpbb/console/command/db/list_command.php +++ b/phpBB/phpbb/console/command/db/list_command.php @@ -39,6 +39,12 @@ class list_command extends \phpbb\console\command\db\migration_command foreach ($this->load_migrations() as $name) { + // Ignore non-migration files + if (\phpbb\db\migrator::is_migration($name) === false) + { + continue; + } + if ($this->migrator->migration_state($name) !== false) { $installed[] = $name; -- cgit v1.2.1 From 27027deb9ce2076f64dbfdecba494efe1aa523dc Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 28 Jan 2016 11:22:30 -0800 Subject: [ticket/14434] Refactored to check migrations when setting them PHPBB3-14434 --- phpBB/phpbb/console/command/db/list_command.php | 6 ------ phpBB/phpbb/console/command/db/migration_command.php | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/db/list_command.php b/phpBB/phpbb/console/command/db/list_command.php index dfec5c7da2..708107b592 100644 --- a/phpBB/phpbb/console/command/db/list_command.php +++ b/phpBB/phpbb/console/command/db/list_command.php @@ -39,12 +39,6 @@ class list_command extends \phpbb\console\command\db\migration_command foreach ($this->load_migrations() as $name) { - // Ignore non-migration files - if (\phpbb\db\migrator::is_migration($name) === false) - { - continue; - } - if ($this->migrator->migration_state($name) !== false) { $installed[] = $name; diff --git a/phpBB/phpbb/console/command/db/migration_command.php b/phpBB/phpbb/console/command/db/migration_command.php index d44ef8c5cb..b951560588 100644 --- a/phpBB/phpbb/console/command/db/migration_command.php +++ b/phpBB/phpbb/console/command/db/migration_command.php @@ -45,7 +45,7 @@ abstract class migration_command extends \phpbb\console\command\command $this->migrator->set_migrations($migrations); - return $migrations; + return $this->migrator->get_migrations(); } protected function finalise_update() -- cgit v1.2.1 From 0102fa3f2d051173762736b6a1a1ba15be466b15 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Tue, 10 Jun 2014 11:07:46 +0200 Subject: [ticket/12684] Add command user:add PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 167 +++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 phpBB/phpbb/console/command/user/add.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php new file mode 100644 index 0000000000..e7a94a74da --- /dev/null +++ b/phpBB/phpbb/console/command/user/add.php @@ -0,0 +1,167 @@ +user = $user; + $this->db = $db; + $this->config = $config; + $this->password_manager = $password_manager; + + $this->user->add_lang('ucp'); + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('user:add') + ->setDescription($this->user->lang('CLI_DESCRIPTION_USER_ADD')) + ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) + ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) + ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $dialog = $this->getHelperSet()->get('dialog'); + + $username = $input->getOption('username'); + if (!$username) { + $username = $dialog->ask( + $output, + $this->user->lang('USERNAME') . $this->user->lang('COLON') . ' ', + null + ); + } + + $password = $input->getOption('password'); + if (!$password) + { + $password = $this->get_password($output, $dialog); + } + + $email = $input->getOption('email'); + if (!$email) + { + $email = $dialog->ask( + $output, + $this->user->lang('EMAIL_ADDRESS') . $this->user->lang('COLON') . ' ', + null + ); + } + + try + { + $group_id = $this->get_group_id(); + } + catch (\RunTimeException $e) + { + $output->writeln($e->getMessage()); + return 1; + } + + $user_row = array( + 'username' => $username, + 'user_password' => $this->password_manager->hash($password), + 'user_email' => $email, + 'group_id' => $group_id, + 'user_timezone' => $config['board_timezone'], + 'user_lang' => $config['default_lang'], + 'user_type' => USER_NORMAL, + 'user_regdate' => time(), + ); + + if (!function_exists(user_add)) + { + require_once dirname(__FILE__) . '/../../../../includes/functions_user.php'; + } + user_add($user_row); + + $output->writeln('' . $this->user->lang('SUCCESS_ADD_USER', $username) . ''); + return 0; + } + + protected function get_password($output, $dialog) + { + $current_user = $this->user; + return $dialog->askHiddenResponseAndValidate( + $output, + $current_user->lang('PASSWORD') . $current_user->lang('COLON') . ' ', + function ($answer) use ($dialog, $output, $current_user) + { + $confirm = $dialog->askHiddenResponse( + $output, + $current_user->lang('CONFIRM_PASSWORD') . $current_user->lang('COLON') . ' ', + null + ); + if ($confirm != $answer) + { + throw new \RunTimeException($current_user->lang('NEW_PASSWORD_ERROR')); + } + return $answer; + }, + false, + null + ); + } + + protected function get_group_id() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "' + AND group_type = " . GROUP_SPECIAL; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + throw new \RunTimeException($this->user->lang('NO_GROUP')); + } + + return $row['group_id']; + } +} -- cgit v1.2.1 From 50761104ba6590de86ec651b5679983eaf2ff600 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Fri, 13 Jun 2014 11:38:02 +0200 Subject: [ticket/12684] Add doc blocks and test file for user:add PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index e7a94a74da..e3f8243c02 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -35,6 +35,9 @@ class add extends \phpbb\console\command\command * Construct method * * @param \phpbb\user $user The user object used for language information + * @param \phpbb\db\driver\driver_interface $db The database in wich will be inserted the user + * @param \phpbb\config\config $config The config object used to get default language and timezone + * @param \phpbb\passwords\manager $password_manager The password manager used to store the user's password */ public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\passwords\manager $password_manager) { @@ -63,6 +66,17 @@ class add extends \phpbb\console\command\command ; } + /** + * Executes the command user:add + * + * If not given in option, asks the username, password and email. + * Then a new user is added in the database, with language and timezone found in the $config passed to the constructor, and the group_id found in the database. + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return int 0 if all is well, 1 if a database error occured while trying to get the group_id + */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getHelperSet()->get('dialog'); @@ -123,6 +137,17 @@ class add extends \phpbb\console\command\command return 0; } + /** + * Get the password + * + * Asks a password to the user and asks for confirmation. + * This is repeted while the two are not the same + * + * @param OutputInterface $output The output stream, where messages are printed + * @param Symfony\Component\Console\Helper\DialogHelper $dialog The dialog helper used to get answers to questions asked to the user + * + * @return null + */ protected function get_password($output, $dialog) { $current_user = $this->user; @@ -147,6 +172,14 @@ class add extends \phpbb\console\command\command ); } + /** + * Get the group id + * + * Go and find in the database the group_id corresponding to 'REGISTERED' + * + * @throws RunTimeException if the group id does not exist in database. + * @return null + */ protected function get_group_id() { $sql = 'SELECT group_id @@ -157,7 +190,7 @@ class add extends \phpbb\console\command\command $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - if (!$row) + if (!$row || !$row['group_id']) { throw new \RunTimeException($this->user->lang('NO_GROUP')); } -- cgit v1.2.1 From df4a620ba146d895be4910761bc030045abbae93 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 27 Aug 2014 16:56:46 +0200 Subject: [ticket/12684] Fix tests PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index e3f8243c02..fab69738e3 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -19,9 +19,6 @@ use Symfony\Component\Console\Output\OutputInterface; class add extends \phpbb\console\command\command { - /** @var \phpbb\user */ - protected $user; - /** @var \phpbb\db\driver\driver_interface */ protected $db; @@ -41,13 +38,12 @@ class add extends \phpbb\console\command\command */ public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\passwords\manager $password_manager) { - $this->user = $user; $this->db = $db; $this->config = $config; $this->password_manager = $password_manager; - $this->user->add_lang('ucp'); - parent::__construct(); + $user->add_lang('ucp'); + parent::__construct($user); } /** @@ -121,13 +117,13 @@ class add extends \phpbb\console\command\command 'user_password' => $this->password_manager->hash($password), 'user_email' => $email, 'group_id' => $group_id, - 'user_timezone' => $config['board_timezone'], - 'user_lang' => $config['default_lang'], + 'user_timezone' => $this->config['board_timezone'], + 'user_lang' => $this->config['default_lang'], 'user_type' => USER_NORMAL, 'user_regdate' => time(), ); - if (!function_exists(user_add)) + if (!function_exists('user_add')) { require_once dirname(__FILE__) . '/../../../../includes/functions_user.php'; } @@ -144,7 +140,7 @@ class add extends \phpbb\console\command\command * This is repeted while the two are not the same * * @param OutputInterface $output The output stream, where messages are printed - * @param Symfony\Component\Console\Helper\DialogHelper $dialog The dialog helper used to get answers to questions asked to the user + * @param \Symfony\Component\Console\Helper\DialogHelper $dialog The dialog helper used to get answers to questions asked to the user * * @return null */ @@ -177,7 +173,7 @@ class add extends \phpbb\console\command\command * * Go and find in the database the group_id corresponding to 'REGISTERED' * - * @throws RunTimeException if the group id does not exist in database. + * @throws \RunTimeException if the group id does not exist in database. * @return null */ protected function get_group_id() -- cgit v1.2.1 From 8f7aba6582c3fb748ed67720292f1d236d4e1270 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 15 Sep 2014 00:13:57 +0200 Subject: [ticket/12684] Fix header file PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index fab69738e3..10b0d0f727 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -3,7 +3,7 @@ * * This file is part of the phpBB Forum Software package. * -* @copyright (c) phpBB Limited +* @copyright (c) phpBB Limited * @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see -- cgit v1.2.1 From 6fe084a2fd967c188bdca827a46647120a5ea58d Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 11:38:49 -0800 Subject: [ticket/12684] Updates for 3.2 API PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 42 ++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 10b0d0f727..f3b52349b7 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -13,9 +13,11 @@ namespace phpbb\console\command\user; +use phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class add extends \phpbb\console\command\command { @@ -28,6 +30,19 @@ class add extends \phpbb\console\command\command /** @var \phpbb\passwords\manager */ protected $password_manager; + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP extension. + * + * @var string + */ + protected $php_ext; + /** * Construct method * @@ -35,12 +50,16 @@ class add extends \phpbb\console\command\command * @param \phpbb\db\driver\driver_interface $db The database in wich will be inserted the user * @param \phpbb\config\config $config The config object used to get default language and timezone * @param \phpbb\passwords\manager $password_manager The password manager used to store the user's password + * @param string $phpbb_root_path Root path + * @param string $php_ext PHP extension */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\passwords\manager $password_manager) + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\passwords\manager $password_manager, $phpbb_root_path, $php_ext) { $this->db = $db; $this->config = $config; $this->password_manager = $password_manager; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; $user->add_lang('ucp'); parent::__construct($user); @@ -75,6 +94,8 @@ class add extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $dialog = $this->getHelperSet()->get('dialog'); $username = $input->getOption('username'); @@ -106,9 +127,9 @@ class add extends \phpbb\console\command\command { $group_id = $this->get_group_id(); } - catch (\RunTimeException $e) + catch (runtime_exception $e) { - $output->writeln($e->getMessage()); + $io->error($e->getMessage()); return 1; } @@ -125,11 +146,12 @@ class add extends \phpbb\console\command\command if (!function_exists('user_add')) { - require_once dirname(__FILE__) . '/../../../../includes/functions_user.php'; + require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } - user_add($user_row); - $output->writeln('' . $this->user->lang('SUCCESS_ADD_USER', $username) . ''); + $user_id = user_add($user_row); + $io->success($this->user->lang('SUCCESS_ADD_USER', $username)); + return 0; } @@ -137,7 +159,7 @@ class add extends \phpbb\console\command\command * Get the password * * Asks a password to the user and asks for confirmation. - * This is repeted while the two are not the same + * This is repeated until the password match is confirmed. * * @param OutputInterface $output The output stream, where messages are printed * @param \Symfony\Component\Console\Helper\DialogHelper $dialog The dialog helper used to get answers to questions asked to the user @@ -159,7 +181,7 @@ class add extends \phpbb\console\command\command ); if ($confirm != $answer) { - throw new \RunTimeException($current_user->lang('NEW_PASSWORD_ERROR')); + throw new runtime_exception($current_user->lang('NEW_PASSWORD_ERROR')); } return $answer; }, @@ -173,7 +195,7 @@ class add extends \phpbb\console\command\command * * Go and find in the database the group_id corresponding to 'REGISTERED' * - * @throws \RunTimeException if the group id does not exist in database. + * @throws runtime_exception if the group id does not exist in database. * @return null */ protected function get_group_id() @@ -188,7 +210,7 @@ class add extends \phpbb\console\command\command if (!$row || !$row['group_id']) { - throw new \RunTimeException($this->user->lang('NO_GROUP')); + throw new runtime_exception($this->user->lang('NO_GROUP')); } return $row['group_id']; -- cgit v1.2.1 From d373428180e884f03a830aa69fe8ff2cd6a5140a Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 11:41:47 -0800 Subject: [ticket/12684] Add input validation PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index f3b52349b7..db06037947 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -123,6 +123,22 @@ class add extends \phpbb\console\command\command ); } + $data = array( + 'username' => $username, + 'new_password' => $password, + 'email' => $email, + ); + + try + { + $this->validate_user_data($data); + } + catch (runtime_exception $e) + { + $io->error($e->getMessage()); + return 1; + } + try { $group_id = $this->get_group_id(); @@ -190,6 +206,38 @@ class add extends \phpbb\console\command\command ); } + /** + * Validate the submitted user data + * + * @param array $data The user data array + * @throws runtime_exception if any data fails validation + * @return null + */ + protected function validate_user_data($data) + { + if (!function_exists('validate_data')) + { + require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $error = validate_data($data, array( + 'username' => array( + array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']), + array('username', '')), + 'new_password' => array( + array('string', false, $this->config['min_pass_chars'], $this->config['max_pass_chars']), + array('password')), + 'email' => array( + array('string', false, 6, 60), + array('user_email')), + )); + + if ($error) + { + throw new runtime_exception(implode("\n", array_map(array($this->user, 'lang'), $error))); + } + } + /** * Get the group id * -- cgit v1.2.1 From f32b4c0547a596fcdd935560b23ed660f3d3f87c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 11:42:23 -0800 Subject: [ticket/12684] Add send email option PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index db06037947..57100a773c 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -78,6 +78,7 @@ class add extends \phpbb\console\command\command ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) + ->addOption('send-email', null, InputOption::VALUE_NONE, $this->user->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')) ; } @@ -166,6 +167,12 @@ class add extends \phpbb\console\command\command } $user_id = user_add($user_row); + + if ($input->getOption('send-email') && $this->config['email_enable']) + { + $this->send_activation_email($user_id, $data); + } + $io->success($this->user->lang('SUCCESS_ADD_USER', $username)); return 0; @@ -263,4 +270,52 @@ class add extends \phpbb\console\command\command return $row['group_id']; } + + /** + * Send account activation email + * + * @param int $user_id The new user's id + * @param array $data The user data array + * @return null + */ + protected function send_activation_email($user_id, $data) + { + if ($this->config['require_activation'] == USER_ACTIVATION_SELF) + { + $email_template = 'user_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + } + else if ($this->config['require_activation'] == USER_ACTIVATION_ADMIN) + { + $email_template = 'admin_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + } + else + { + $email_template = 'user_welcome'; + $user_actkey = ''; + } + + if (!class_exists('messenger')) + { + require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + + $messenger = new \messenger(false); + + $messenger->template($email_template, $this->user->lang_name); + + $messenger->to($data['email'], $data['username']); + + $messenger->anti_abuse_headers($this->config, $this->user); + + $messenger->assign_vars(array( + 'WELCOME_MSG' => htmlspecialchars_decode($this->user->lang('WELCOME_SUBJECT', $this->config['sitename'])), + 'USERNAME' => htmlspecialchars_decode($data['username']), + 'PASSWORD' => htmlspecialchars_decode($data['new_password']), + 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") + ); + + $messenger->send(NOTIFY_EMAIL); + } } -- cgit v1.2.1 From 637b02690db0d3b7af2915c1da4bacc8fa054f6c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 13:28:42 -0800 Subject: [ticket/12684] Update to use non-deprecated methods PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 279 +++++++++++++++---------------- 1 file changed, 136 insertions(+), 143 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 57100a773c..be9f484aeb 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -1,15 +1,15 @@ -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ namespace phpbb\console\command\user; @@ -17,6 +17,7 @@ use phpbb\exception\runtime_exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; class add extends \phpbb\console\command\command @@ -27,108 +28,124 @@ class add extends \phpbb\console\command\command /** @var \phpbb\config\config */ protected $config; + /** @var \phpbb\language\language */ + protected $language; + /** @var \phpbb\passwords\manager */ protected $password_manager; /** - * phpBB root path - * @var string - */ + * phpBB root path + * + * @var string + */ protected $phpbb_root_path; /** - * PHP extension. - * - * @var string - */ + * PHP extension. + * + * @var string + */ protected $php_ext; /** - * Construct method - * - * @param \phpbb\user $user The user object used for language information - * @param \phpbb\db\driver\driver_interface $db The database in wich will be inserted the user - * @param \phpbb\config\config $config The config object used to get default language and timezone - * @param \phpbb\passwords\manager $password_manager The password manager used to store the user's password - * @param string $phpbb_root_path Root path - * @param string $php_ext PHP extension - */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\passwords\manager $password_manager, $phpbb_root_path, $php_ext) + * Construct method + * + * @param \phpbb\user $user + * @param \phpbb\db\driver\driver_interface $db + * @param \phpbb\config\config $config + * @param \phpbb\language\language $language + * @param \phpbb\passwords\manager $password_manager + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\passwords\manager $password_manager, $phpbb_root_path, $php_ext) { $this->db = $db; $this->config = $config; + $this->language = $language; $this->password_manager = $password_manager; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $user->add_lang('ucp'); + $language->add_lang('ucp'); parent::__construct($user); } /** - * Sets the command name and description - * - * @return null - */ + * Sets the command name and description + * + * @return null + */ protected function configure() { $this ->setName('user:add') - ->setDescription($this->user->lang('CLI_DESCRIPTION_USER_ADD')) - ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) - ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) - ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) - ->addOption('send-email', null, InputOption::VALUE_NONE, $this->user->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')) + ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ADD')) + ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) + ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) + ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) + ->addOption('send-email', null, InputOption::VALUE_NONE, $this->language->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')) ; } /** - * Executes the command user:add - * - * If not given in option, asks the username, password and email. - * Then a new user is added in the database, with language and timezone found in the $config passed to the constructor, and the group_id found in the database. - * - * @param InputInterface $input The input stream used to get the options - * @param OutputInterface $output The output stream, used to print messages - * - * @return int 0 if all is well, 1 if a database error occured while trying to get the group_id - */ + * Executes the command user:add + * + * Adds a new user to the database. If options are not provided, it will ask for the username, password and email. + * User is added to the registered user group. Language and timezone default to $config settings. + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return int 0 if all is well, 1 if any errors occurred + */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); - $dialog = $this->getHelperSet()->get('dialog'); + $helper = $this->getHelper('question'); - $username = $input->getOption('username'); - if (!$username) { - $username = $dialog->ask( - $output, - $this->user->lang('USERNAME') . $this->user->lang('COLON') . ' ', - null - ); - } + $data = array( + 'username' => $input->getOption('username'), + 'new_password' => $input->getOption('password'), + 'email' => $input->getOption('email'), + ); - $password = $input->getOption('password'); - if (!$password) + if (!$data['username']) { - $password = $this->get_password($output, $dialog); + $question = new Question($this->ask_user('USERNAME'), null); + $data['username'] = $helper->ask($input, $output, $question); } - $email = $input->getOption('email'); - if (!$email) + if (!$data['new_password']) { - $email = $dialog->ask( - $output, - $this->user->lang('EMAIL_ADDRESS') . $this->user->lang('COLON') . ' ', - null - ); + $self = $this; + $question = new Question($this->ask_user('PASSWORD')); + $question->setValidator(function ($value) use ($self, $helper, $input, $output) { + $question = new Question($self->ask_user('CONFIRM_PASSWORD')); + $question->setHidden(true); + $question->setHiddenFallback(false); + + $confirm = $helper->ask($input, $output, $question); + if ($confirm != $value) + { + throw new runtime_exception($self->language->lang('NEW_PASSWORD_ERROR')); + } + return $value; + }); + $question->setHidden(true); + $question->setHiddenFallback(false); + $question->setMaxAttempts(5); + + $data['new_password'] = $helper->ask($input, $output, $question); } - $data = array( - 'username' => $username, - 'new_password' => $password, - 'email' => $email, - ); + if (!$data['email']) + { + $question = new Question($this->ask_user('EMAIL_ADDRESS'), null); + $data['email'] = $helper->ask($input, $output, $question); + } try { @@ -151,14 +168,14 @@ class add extends \phpbb\console\command\command } $user_row = array( - 'username' => $username, - 'user_password' => $this->password_manager->hash($password), - 'user_email' => $email, - 'group_id' => $group_id, - 'user_timezone' => $this->config['board_timezone'], - 'user_lang' => $this->config['default_lang'], - 'user_type' => USER_NORMAL, - 'user_regdate' => time(), + 'username' => $data['username'], + 'user_password' => $this->password_manager->hash($data['new_password']), + 'user_email' => $data['email'], + 'group_id' => $group_id, + 'user_timezone' => $this->config['board_timezone'], + 'user_lang' => $this->config['default_lang'], + 'user_type' => USER_NORMAL, + 'user_regdate' => time(), ); if (!function_exists('user_add')) @@ -166,60 +183,25 @@ class add extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } - $user_id = user_add($user_row); + $user_id = (int) user_add($user_row); if ($input->getOption('send-email') && $this->config['email_enable']) { $this->send_activation_email($user_id, $data); } - $io->success($this->user->lang('SUCCESS_ADD_USER', $username)); + $io->success($this->language->lang('SUCCESS_ADD_USER', $data['username'])); return 0; } /** - * Get the password - * - * Asks a password to the user and asks for confirmation. - * This is repeated until the password match is confirmed. - * - * @param OutputInterface $output The output stream, where messages are printed - * @param \Symfony\Component\Console\Helper\DialogHelper $dialog The dialog helper used to get answers to questions asked to the user - * - * @return null - */ - protected function get_password($output, $dialog) - { - $current_user = $this->user; - return $dialog->askHiddenResponseAndValidate( - $output, - $current_user->lang('PASSWORD') . $current_user->lang('COLON') . ' ', - function ($answer) use ($dialog, $output, $current_user) - { - $confirm = $dialog->askHiddenResponse( - $output, - $current_user->lang('CONFIRM_PASSWORD') . $current_user->lang('COLON') . ' ', - null - ); - if ($confirm != $answer) - { - throw new runtime_exception($current_user->lang('NEW_PASSWORD_ERROR')); - } - return $answer; - }, - false, - null - ); - } - - /** - * Validate the submitted user data - * - * @param array $data The user data array - * @throws runtime_exception if any data fails validation - * @return null - */ + * Validate the submitted user data + * + * @param array $data The user data array + * @throws runtime_exception if any data fails validation + * @return null + */ protected function validate_user_data($data) { if (!function_exists('validate_data')) @@ -228,13 +210,13 @@ class add extends \phpbb\console\command\command } $error = validate_data($data, array( - 'username' => array( + 'username' => array( array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']), array('username', '')), - 'new_password' => array( + 'new_password' => array( array('string', false, $this->config['min_pass_chars'], $this->config['max_pass_chars']), array('password')), - 'email' => array( + 'email' => array( array('string', false, 6, 60), array('user_email')), )); @@ -246,13 +228,13 @@ class add extends \phpbb\console\command\command } /** - * Get the group id - * - * Go and find in the database the group_id corresponding to 'REGISTERED' - * - * @throws runtime_exception if the group id does not exist in database. - * @return null - */ + * Get the group id + * + * Go and find in the database the group_id corresponding to 'REGISTERED' + * + * @throws runtime_exception if the group id does not exist in database. + * @return null + */ protected function get_group_id() { $sql = 'SELECT group_id @@ -265,19 +247,19 @@ class add extends \phpbb\console\command\command if (!$row || !$row['group_id']) { - throw new runtime_exception($this->user->lang('NO_GROUP')); + throw new runtime_exception($this->language->lang('NO_GROUP')); } return $row['group_id']; } /** - * Send account activation email - * - * @param int $user_id The new user's id - * @param array $data The user data array - * @return null - */ + * Send account activation email + * + * @param int $user_id The new user's id + * @param array $data The user data array + * @return null + */ protected function send_activation_email($user_id, $data) { if ($this->config['require_activation'] == USER_ACTIVATION_SELF) @@ -310,12 +292,23 @@ class add extends \phpbb\console\command\command $messenger->anti_abuse_headers($this->config, $this->user); $messenger->assign_vars(array( - 'WELCOME_MSG' => htmlspecialchars_decode($this->user->lang('WELCOME_SUBJECT', $this->config['sitename'])), - 'USERNAME' => htmlspecialchars_decode($data['username']), - 'PASSWORD' => htmlspecialchars_decode($data['new_password']), - 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") + 'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])), + 'USERNAME' => htmlspecialchars_decode($data['username']), + 'PASSWORD' => htmlspecialchars_decode($data['new_password']), + 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") ); $messenger->send(NOTIFY_EMAIL); } + + /** + * Helper to translate questions to the user + * + * @param string $key The language key + * @return string The language key translated with a colon and space appended + */ + protected function ask_user($key) + { + return $this->language->lang($key) . $this->language->lang('COLON') . ' '; + } } -- cgit v1.2.1 From fe31060fca4a07696029c50af2c74c88ab5d85fe Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 14:23:32 -0800 Subject: [ticket/12684] Fix tests PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index be9f484aeb..46056caffd 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -125,7 +125,6 @@ class add extends \phpbb\console\command\command $question->setValidator(function ($value) use ($self, $helper, $input, $output) { $question = new Question($self->ask_user('CONFIRM_PASSWORD')); $question->setHidden(true); - $question->setHiddenFallback(false); $confirm = $helper->ask($input, $output, $question); if ($confirm != $value) @@ -135,7 +134,6 @@ class add extends \phpbb\console\command\command return $value; }); $question->setHidden(true); - $question->setHiddenFallback(false); $question->setMaxAttempts(5); $data['new_password'] = $helper->ask($input, $output, $question); @@ -223,7 +221,7 @@ class add extends \phpbb\console\command\command if ($error) { - throw new runtime_exception(implode("\n", array_map(array($this->user, 'lang'), $error))); + throw new runtime_exception(implode("\n", array_map(array($this->language, 'lang'), $error))); } } -- cgit v1.2.1 From a84f77bf25c897067f5078ae2139214e5882192b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 14:28:02 -0800 Subject: [ticket/12684] Another little fix PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 46056caffd..647c353dd0 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -68,7 +68,7 @@ class add extends \phpbb\console\command\command $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $language->add_lang('ucp'); + $this->language->add_lang('ucp'); parent::__construct($user); } -- cgit v1.2.1 From 97c6cce687d94071d6f902af272631c21dbacfcb Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 14:50:19 -0800 Subject: [ticket/12684] Some code clean up PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 647c353dd0..d85c9599c5 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -125,9 +125,7 @@ class add extends \phpbb\console\command\command $question->setValidator(function ($value) use ($self, $helper, $input, $output) { $question = new Question($self->ask_user('CONFIRM_PASSWORD')); $question->setHidden(true); - - $confirm = $helper->ask($input, $output, $question); - if ($confirm != $value) + if ($helper->ask($input, $output, $question) != $value) { throw new runtime_exception($self->language->lang('NEW_PASSWORD_ERROR')); } @@ -148,15 +146,6 @@ class add extends \phpbb\console\command\command try { $this->validate_user_data($data); - } - catch (runtime_exception $e) - { - $io->error($e->getMessage()); - return 1; - } - - try - { $group_id = $this->get_group_id(); } catch (runtime_exception $e) -- cgit v1.2.1 From e905c6226db367ab3a04e373bee56a85d8251cc7 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 16:52:17 -0800 Subject: [ticket/12684] Fix a few mistakes and clean it up PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index d85c9599c5..59d9eaa117 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -82,10 +82,30 @@ class add extends \phpbb\console\command\command $this ->setName('user:add') ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ADD')) - ->addOption('username', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME')) - ->addOption('password', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD')) - ->addOption('email', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL')) - ->addOption('send-email', null, InputOption::VALUE_NONE, $this->language->lang('CLI_CONFIG_PRINT_WITHOUT_NEWLINE')) + ->addOption( + 'username', + null, + InputOption::VALUE_REQUIRED, + $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME') + ) + ->addOption( + 'password', + null, + InputOption::VALUE_REQUIRED, + $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD') + ) + ->addOption( + 'email', + null, + InputOption::VALUE_REQUIRED, + $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL') + ) + ->addOption( + 'send-email', + null, + InputOption::VALUE_NONE, + $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY') + ) ; } @@ -271,13 +291,9 @@ class add extends \phpbb\console\command\command } $messenger = new \messenger(false); - $messenger->template($email_template, $this->user->lang_name); - $messenger->to($data['email'], $data['username']); - $messenger->anti_abuse_headers($this->config, $this->user); - $messenger->assign_vars(array( 'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])), 'USERNAME' => htmlspecialchars_decode($data['username']), -- cgit v1.2.1 From 0ca4484525f69ea5e7c5cd28f671364604725e40 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 21:03:32 -0800 Subject: [ticket/12684] Move all lang keys to cli PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 59d9eaa117..6edd214d14 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -197,7 +197,7 @@ class add extends \phpbb\console\command\command $this->send_activation_email($user_id, $data); } - $io->success($this->language->lang('SUCCESS_ADD_USER', $data['username'])); + $io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $data['username'])); return 0; } -- cgit v1.2.1 From b17f9fc81c40a6b7a5a45cc53e378274e1b6922b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 21:04:16 -0800 Subject: [ticket/12684] Allowed to use $this in enclosure PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 6edd214d14..6f0988db5e 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -140,14 +140,13 @@ class add extends \phpbb\console\command\command if (!$data['new_password']) { - $self = $this; $question = new Question($this->ask_user('PASSWORD')); - $question->setValidator(function ($value) use ($self, $helper, $input, $output) { - $question = new Question($self->ask_user('CONFIRM_PASSWORD')); + $question->setValidator(function ($value) use ($helper, $input, $output) { + $question = new Question($this->ask_user('CONFIRM_PASSWORD')); $question->setHidden(true); if ($helper->ask($input, $output, $question) != $value) { - throw new runtime_exception($self->language->lang('NEW_PASSWORD_ERROR')); + throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR')); } return $value; }); -- cgit v1.2.1 From 07b8c0663d17bc891dcb19b7394a24a108316d36 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 21:04:41 -0800 Subject: [ticket/12684] Additional clean up PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 6f0988db5e..3e4fbe994f 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -184,11 +184,6 @@ class add extends \phpbb\console\command\command 'user_regdate' => time(), ); - if (!function_exists('user_add')) - { - require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - $user_id = (int) user_add($user_row); if ($input->getOption('send-email') && $this->config['email_enable']) @@ -294,10 +289,10 @@ class add extends \phpbb\console\command\command $messenger->to($data['email'], $data['username']); $messenger->anti_abuse_headers($this->config, $this->user); $messenger->assign_vars(array( - 'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])), - 'USERNAME' => htmlspecialchars_decode($data['username']), - 'PASSWORD' => htmlspecialchars_decode($data['new_password']), - 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") + 'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])), + 'USERNAME' => htmlspecialchars_decode($data['username']), + 'PASSWORD' => htmlspecialchars_decode($data['new_password']), + 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") ); $messenger->send(NOTIFY_EMAIL); -- cgit v1.2.1 From 7b0452e53aa750761c3042183e5ad7dd2cb3b344 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 29 Feb 2016 23:24:01 -0800 Subject: [ticket/12684] Remove unnecessary null arguments PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 3e4fbe994f..6937cd17d2 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -134,7 +134,7 @@ class add extends \phpbb\console\command\command if (!$data['username']) { - $question = new Question($this->ask_user('USERNAME'), null); + $question = new Question($this->ask_user('USERNAME')); $data['username'] = $helper->ask($input, $output, $question); } @@ -158,7 +158,7 @@ class add extends \phpbb\console\command\command if (!$data['email']) { - $question = new Question($this->ask_user('EMAIL_ADDRESS'), null); + $question = new Question($this->ask_user('EMAIL_ADDRESS')); $data['email'] = $helper->ask($input, $output, $question); } -- cgit v1.2.1 From 8c5d6efad5262417db341491f7c625832b226b22 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 5 Mar 2016 09:20:04 -0800 Subject: [ticket/12684] Add an error on user creation failure PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 6937cd17d2..187062f020 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -185,6 +185,12 @@ class add extends \phpbb\console\command\command ); $user_id = (int) user_add($user_row); + + if (!$user_id) + { + $io->error($this->language->lang('AUTH_NO_PROFILE_CREATED')); + return 1; + } if ($input->getOption('send-email') && $this->config['email_enable']) { -- cgit v1.2.1 From cc941e6e05d3be75ef60d9473dee43cd6320c85b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 5 Mar 2016 10:41:35 -0800 Subject: [ticket/12684] Remove whitespace PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 187062f020..943cdb67a5 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -185,7 +185,7 @@ class add extends \phpbb\console\command\command ); $user_id = (int) user_add($user_row); - + if (!$user_id) { $io->error($this->language->lang('AUTH_NO_PROFILE_CREATED')); -- cgit v1.2.1 From 0c1e7c2f9cf81c1e487a0dcd2fb9e053de14c275 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 8 Mar 2016 00:06:10 -0800 Subject: [ticket/12684] Add shorthand alternates to the options PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 943cdb67a5..42ff000ca4 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -84,19 +84,19 @@ class add extends \phpbb\console\command\command ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ADD')) ->addOption( 'username', - null, + 'U', InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME') ) ->addOption( 'password', - null, + 'P', InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD') ) ->addOption( 'email', - null, + 'E', InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL') ) -- cgit v1.2.1 From 0f8790dd2e804ccbc7d6c1e444c1d31412d7aaa4 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 8 Mar 2016 00:32:59 -0800 Subject: [ticket/12684] Add extended help for the user:add command PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 42ff000ca4..a0da15915d 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -82,6 +82,7 @@ class add extends \phpbb\console\command\command $this ->setName('user:add') ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ADD')) + ->setHelp($this->language->lang('CLI_HELP_USER_ADD')) ->addOption( 'username', 'U', -- cgit v1.2.1 From 693664f278e0d99efef9e81c3848fe3f7edf9e7f Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 9 Mar 2016 15:16:23 -0800 Subject: [ticket/12684] Extract interactivity to a method PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 89 +++++++++++++++++++------------- 1 file changed, 52 insertions(+), 37 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index a0da15915d..8151f3827c 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -125,43 +125,7 @@ class add extends \phpbb\console\command\command { $io = new SymfonyStyle($input, $output); - $helper = $this->getHelper('question'); - - $data = array( - 'username' => $input->getOption('username'), - 'new_password' => $input->getOption('password'), - 'email' => $input->getOption('email'), - ); - - if (!$data['username']) - { - $question = new Question($this->ask_user('USERNAME')); - $data['username'] = $helper->ask($input, $output, $question); - } - - if (!$data['new_password']) - { - $question = new Question($this->ask_user('PASSWORD')); - $question->setValidator(function ($value) use ($helper, $input, $output) { - $question = new Question($this->ask_user('CONFIRM_PASSWORD')); - $question->setHidden(true); - if ($helper->ask($input, $output, $question) != $value) - { - throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR')); - } - return $value; - }); - $question->setHidden(true); - $question->setMaxAttempts(5); - - $data['new_password'] = $helper->ask($input, $output, $question); - } - - if (!$data['email']) - { - $question = new Question($this->ask_user('EMAIL_ADDRESS')); - $data['email'] = $helper->ask($input, $output, $question); - } + $data = $this->interact($input, $output); try { @@ -203,6 +167,57 @@ class add extends \phpbb\console\command\command return 0; } + /** + * Interact with the user to obtain the required options + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return array Array of required user options + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $helper = $this->getHelper('question'); + + $data = array( + 'username' => $input->getOption('username'), + 'new_password' => $input->getOption('password'), + 'email' => $input->getOption('email'), + ); + + if (!$data['username']) + { + $question = new Question($this->ask_user('USERNAME')); + $data['username'] = $helper->ask($input, $output, $question); + } + + if (!$data['new_password']) + { + $question = new Question($this->ask_user('PASSWORD')); + $question->setValidator(function ($value) use ($helper, $input, $output) { + $question = new Question($this->ask_user('CONFIRM_PASSWORD')); + $question->setHidden(true); + if ($helper->ask($input, $output, $question) != $value) + { + throw new runtime_exception($this->language->lang('NEW_PASSWORD_ERROR')); + } + return $value; + }); + $question->setHidden(true); + $question->setMaxAttempts(5); + + $data['new_password'] = $helper->ask($input, $output, $question); + } + + if (!$data['email']) + { + $question = new Question($this->ask_user('EMAIL_ADDRESS')); + $data['email'] = $helper->ask($input, $output, $question); + } + + return $data; + } + /** * Validate the submitted user data * -- cgit v1.2.1 From 5917a8e72ef274b2c7c419abe5349ace9d814d8b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 9 Mar 2016 17:40:58 -0800 Subject: [ticket/12684] Use interactive method correctly PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 55 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 8151f3827c..3df0473acf 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -22,6 +22,9 @@ use Symfony\Component\Console\Style\SymfonyStyle; class add extends \phpbb\console\command\command { + /** @var array Array of interactively acquired options */ + protected $data; + /** @var \phpbb\db\driver\driver_interface */ protected $db; @@ -125,11 +128,9 @@ class add extends \phpbb\console\command\command { $io = new SymfonyStyle($input, $output); - $data = $this->interact($input, $output); - try { - $this->validate_user_data($data); + $this->validate_user_data(); $group_id = $this->get_group_id(); } catch (runtime_exception $e) @@ -139,9 +140,9 @@ class add extends \phpbb\console\command\command } $user_row = array( - 'username' => $data['username'], - 'user_password' => $this->password_manager->hash($data['new_password']), - 'user_email' => $data['email'], + 'username' => $this->data['username'], + 'user_password' => $this->password_manager->hash($this->data['new_password']), + 'user_email' => $this->data['email'], 'group_id' => $group_id, 'user_timezone' => $this->config['board_timezone'], 'user_lang' => $this->config['default_lang'], @@ -159,39 +160,37 @@ class add extends \phpbb\console\command\command if ($input->getOption('send-email') && $this->config['email_enable']) { - $this->send_activation_email($user_id, $data); + $this->send_activation_email($user_id); } - $io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $data['username'])); + $io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $this->data['username'])); return 0; } /** - * Interact with the user to obtain the required options - * - * @param InputInterface $input The input stream used to get the options - * @param OutputInterface $output The output stream, used to print messages + * Interacts with the user. * - * @return array Array of required user options + * @param InputInterface $input An InputInterface instance + * @param OutputInterface $output An OutputInterface instance */ protected function interact(InputInterface $input, OutputInterface $output) { $helper = $this->getHelper('question'); - $data = array( + $this->data = array( 'username' => $input->getOption('username'), 'new_password' => $input->getOption('password'), 'email' => $input->getOption('email'), ); - if (!$data['username']) + if (!$this->data['username']) { $question = new Question($this->ask_user('USERNAME')); - $data['username'] = $helper->ask($input, $output, $question); + $this->data['username'] = $helper->ask($input, $output, $question); } - if (!$data['new_password']) + if (!$this->data['new_password']) { $question = new Question($this->ask_user('PASSWORD')); $question->setValidator(function ($value) use ($helper, $input, $output) { @@ -206,33 +205,30 @@ class add extends \phpbb\console\command\command $question->setHidden(true); $question->setMaxAttempts(5); - $data['new_password'] = $helper->ask($input, $output, $question); + $this->data['new_password'] = $helper->ask($input, $output, $question); } - if (!$data['email']) + if (!$this->data['email']) { $question = new Question($this->ask_user('EMAIL_ADDRESS')); - $data['email'] = $helper->ask($input, $output, $question); + $this->data['email'] = $helper->ask($input, $output, $question); } - - return $data; } /** * Validate the submitted user data * - * @param array $data The user data array * @throws runtime_exception if any data fails validation * @return null */ - protected function validate_user_data($data) + protected function validate_user_data() { if (!function_exists('validate_data')) { require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } - $error = validate_data($data, array( + $error = validate_data($this->data, array( 'username' => array( array('string', false, $this->config['min_name_chars'], $this->config['max_name_chars']), array('username', '')), @@ -280,10 +276,9 @@ class add extends \phpbb\console\command\command * Send account activation email * * @param int $user_id The new user's id - * @param array $data The user data array * @return null */ - protected function send_activation_email($user_id, $data) + protected function send_activation_email($user_id) { if ($this->config['require_activation'] == USER_ACTIVATION_SELF) { @@ -308,12 +303,12 @@ class add extends \phpbb\console\command\command $messenger = new \messenger(false); $messenger->template($email_template, $this->user->lang_name); - $messenger->to($data['email'], $data['username']); + $messenger->to($this->data['email'], $this->data['username']); $messenger->anti_abuse_headers($this->config, $this->user); $messenger->assign_vars(array( 'WELCOME_MSG' => htmlspecialchars_decode($this->language->lang('WELCOME_SUBJECT', $this->config['sitename'])), - 'USERNAME' => htmlspecialchars_decode($data['username']), - 'PASSWORD' => htmlspecialchars_decode($data['new_password']), + 'USERNAME' => htmlspecialchars_decode($this->data['username']), + 'PASSWORD' => htmlspecialchars_decode($this->data['new_password']), 'U_ACTIVATE' => generate_board_url() . "/ucp.{$this->php_ext}?mode=activate&u=$user_id&k=$user_actkey") ); -- cgit v1.2.1 From 5b3b0edd8010ccd4735d4000d284d7717bced897 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 21 Mar 2016 13:54:50 -0700 Subject: [ticket/12684] Use a switch statement for readability PHPBB3-12684 --- phpBB/phpbb/console/command/user/add.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index 3df0473acf..df1f4aa54a 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -280,20 +280,20 @@ class add extends \phpbb\console\command\command */ protected function send_activation_email($user_id) { - if ($this->config['require_activation'] == USER_ACTIVATION_SELF) + switch ($this->config['require_activation']) { - $email_template = 'user_welcome_inactive'; - $user_actkey = gen_rand_string(mt_rand(6, 10)); - } - else if ($this->config['require_activation'] == USER_ACTIVATION_ADMIN) - { - $email_template = 'admin_welcome_inactive'; - $user_actkey = gen_rand_string(mt_rand(6, 10)); - } - else - { - $email_template = 'user_welcome'; - $user_actkey = ''; + case USER_ACTIVATION_SELF: + $email_template = 'user_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + break; + case USER_ACTIVATION_ADMIN: + $email_template = 'admin_welcome_inactive'; + $user_actkey = gen_rand_string(mt_rand(6, 10)); + break; + default: + $email_template = 'user_welcome'; + $user_actkey = ''; + break; } if (!class_exists('messenger')) -- cgit v1.2.1 From 8a9429efa4b0a459a657a44b41a596969878ad65 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 26 Mar 2016 12:35:38 -0700 Subject: [ticket/14561] User delete command PHPBB3-14561 --- phpBB/phpbb/console/command/user/delete.php | 175 ++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 phpBB/phpbb/console/command/user/delete.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/delete.php b/phpBB/phpbb/console/command/user/delete.php new file mode 100644 index 0000000000..360b119e17 --- /dev/null +++ b/phpBB/phpbb/console/command/user/delete.php @@ -0,0 +1,175 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\console\command\user; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Style\SymfonyStyle; + +class delete extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\log\log_interface */ + protected $log; + + /** + * phpBB root path + * + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP extension. + * + * @var string + */ + protected $php_ext; + + /** + * Construct method + * + * @param \phpbb\user $user + * @param \phpbb\db\driver\driver_interface $db + * @param \phpbb\language\language $language + * @param \phpbb\log\log_interface $log + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\log\log_interface $log, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->language = $language; + $this->log = $log; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->language->add_lang('acp/users'); + parent::__construct($user); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('user:delete') + ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_DELETE')) + ->addArgument( + 'username', + InputArgument::REQUIRED, + $this->language->lang('CLI_DESCRIPTION_USER_DELETE_USERNAME') + ) + ->addOption( + 'delete-posts', + null, + InputOption::VALUE_NONE, + $this->language->lang('CLI_DESCRIPTION_USER_DELETE_OPTION_POSTS') + ) + ; + } + + /** + * Executes the command user:delete + * + * Deletes a user from the database. An option to delete the user's posts + * is available, by default posts will be retained. + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return int 0 if all is well, 1 if any errors occurred + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $name = $input->getArgument('username'); + $mode = ($input->getOption('delete-posts')) ? 'remove' : 'retain'; + + if ($name) + { + $io = new SymfonyStyle($input, $output); + + if (!$user_row = $this->get_user_data($name)) + { + $io->error($this->language->lang('NO_USER')); + return 1; + } + + if (!function_exists('user_delete')) + { + require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + user_delete($mode, $user_row['user_id'], $user_row['username']); + + $this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username'])); + + $io->success($this->language->lang('USER_DELETED')); + } + + return 0; + } + + /** + * Interacts with the user. + * Confirm they really want to delete the account...last chance! + * + * @param InputInterface $input An InputInterface instance + * @param OutputInterface $output An OutputInterface instance + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $helper = $this->getHelper('question'); + + $question = new ConfirmationQuestion( + $this->language->lang('CLI_USER_DELETE_CONFIRM', $input->getArgument('username')), + false + ); + + if (!$helper->ask($input, $output, $question)) + { + $input->setArgument('username', false); + } + } + + /** + * Get the user's data from the database + * + * @param string $name A user name + * @return mixed The user's id and username if they exist, false otherwise. + */ + protected function get_user_data($name) + { + $sql = 'SELECT user_id, username + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'"; + $result = $this->db->sql_query_limit($sql, 1); + $user_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return $user_row; + } +} -- cgit v1.2.1 From 91f1116e046818fb49a19ff59652f684c6f5f736 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 26 Mar 2016 12:37:27 -0700 Subject: [ticket/14561] User activate command PHPBB3-14561 --- phpBB/phpbb/console/command/user/activate.php | 223 ++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 phpBB/phpbb/console/command/user/activate.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php new file mode 100644 index 0000000000..890827afb6 --- /dev/null +++ b/phpBB/phpbb/console/command/user/activate.php @@ -0,0 +1,223 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\console\command\user; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Style\SymfonyStyle; + +class activate extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\config\config */ + protected $config; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var \phpbb\log\log_interface */ + protected $log; + + /** @var \phpbb\notification\manager */ + protected $notifications; + + /** + * phpBB root path + * + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP extension. + * + * @var string + */ + protected $php_ext; + + /** + * Construct method + * + * @param \phpbb\user $user + * @param \phpbb\db\driver\driver_interface $db + * @param \phpbb\config\config $config + * @param \phpbb\language\language $language + * @param \phpbb\log\log_interface $log + * @param \phpbb\notification\manager $notifications + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\log\log_interface $log, \phpbb\notification\manager $notifications, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->config = $config; + $this->language = $language; + $this->log = $log; + $this->notifications = $notifications; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->language->add_lang('acp/users'); + parent::__construct($user); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('user:activate') + ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE')) + ->setHelp($this->language->lang('CLI_HELP_USER_ACTIVATE')) + ->addArgument( + 'username', + InputArgument::REQUIRED, + $this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_USERNAME') + ) + ->addOption( + 'deactivate', + 'd', + InputOption::VALUE_NONE, + $this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_DEACTIVATE') + ) + ->addOption( + 'send-email', + null, + InputOption::VALUE_NONE, + $this->language->lang('CLI_DESCRIPTION_USER_ADD_OPTION_NOTIFY') + ) + ; + } + + /** + * Executes the command user:activate + * + * Deletes a user from the database. An option to delete the user's posts + * is available, by default posts will be retained. + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return int 0 if all is well, 1 if any errors occurred + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + $name = $input->getArgument('username'); + $mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate'; + + if (!$user_row = $this->get_user_data($name)) + { + $io->error($this->language->lang('NO_USER')); + return 1; + } + + // Check if the user is already active (or inactive) + if ($mode == 'activate' && $user_row['user_type'] != USER_INACTIVE) + { + $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE')); + return 1; + } + else if ($mode == 'deactivate' && $user_row['user_type'] == USER_INACTIVE) + { + $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE')); + return 1; + } + + // Activate the user account + if (!function_exists('user_active_flip')) + { + require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + user_active_flip($mode, $user_row['user_id']); + + // Notify the user upon activation + if ($mode == 'activate' && $this->config['require_activation'] == USER_ACTIVATION_ADMIN) + { + $this->send_notification($user_row, $input); + } + + // Log and display the result + $msg = ($mode == 'activate') ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED'; + $log = ($mode == 'activate') ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE'; + + $this->log->add('admin', ANONYMOUS, '', $log, false, array($user_row['username'])); + $this->log->add('user', ANONYMOUS, '', $log . '_USER', false, array( + 'reportee_id' => $user_row['user_id'] + )); + + $io->success($this->language->lang($msg)); + + return 0; + } + + /** + * Send account activation notification to user + * + * @param array $user_row The user data array + * @param InputInterface $input The input stream used to get the options + * @return null + */ + protected function send_notification($user_row, InputInterface $input) + { + $this->notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']); + + if ($input->getOption('send-email')) + { + if (!class_exists('messenger')) + { + require($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + + $messenger = new \messenger(false); + $messenger->template('admin_welcome_activated', $user_row['user_lang']); + $messenger->set_addresses($user_row); + $messenger->anti_abuse_headers($this->config, $this->user); + $messenger->assign_vars(array( + 'USERNAME' => htmlspecialchars_decode($user_row['username'])) + ); + + $messenger->send(NOTIFY_EMAIL); + } + } + + /** + * Get the user's data from the database + * + * @param string $name A user name + * @return mixed The user's data array if they exist, false otherwise. + */ + protected function get_user_data($name) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'"; + $result = $this->db->sql_query_limit($sql, 1); + $user_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return $user_row; + } +} -- cgit v1.2.1 From 16f9b4630cfc3c6247894ac82ac6b95577075753 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 26 Mar 2016 12:38:07 -0700 Subject: [ticket/14561] Reclean usernames command PHPBB3-14561 --- phpBB/phpbb/console/command/user/reclean.php | 125 +++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 phpBB/phpbb/console/command/user/reclean.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php new file mode 100644 index 0000000000..c53d766cce --- /dev/null +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -0,0 +1,125 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\console\command\user; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Style\SymfonyStyle; + +class reclean extends \phpbb\console\command\command +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\language\language */ + protected $language; + + /** @var int A count of the number of re-cleaned user names */ + protected $processed; + + /** + * Construct method + * + * @param \phpbb\user $user + * @param \phpbb\db\driver\driver_interface $db + * @param \phpbb\language\language $language + */ + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language) + { + $this->db = $db; + $this->language = $language; + + parent::__construct($user); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('user:reclean') + ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_RECLEAN')) + ; + } + + /** + * Executes the command user:reclean + * + * Cleans user names that are unclean. + * + * @param InputInterface $input The input stream used to get the options + * @param OutputInterface $output The output stream, used to print messages + * + * @return int 0 if all is well, 1 if any errors occurred + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->processed = 0; + + $stage = 0; + while ($stage !== true) + { + $stage = $this->reclean_usernames($stage); + } + + $io = new SymfonyStyle($input, $output); + $io->success($this->language->lang('CLI_USER_RECLEAN_SUCCESS', $this->processed)); + return 0; + } + + /** + * Re-clean user names + * Only user names that are unclean will be re-cleaned + * + * @param int $start An offset index + * @return bool|int Return the next offset index or true if all records have been processed. + */ + protected function reclean_usernames($start = 0) + { + $limit = 500; + $i = 0; + + $this->db->sql_transaction('begin'); + + $sql = 'SELECT user_id, username, username_clean FROM ' . USERS_TABLE; + $result = $this->db->sql_query_limit($sql, $limit, $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + $username_clean = $this->db->sql_escape(utf8_clean_string($row['username'])); + + if ($username_clean != $row['username_clean']) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET username_clean = '$username_clean' + WHERE user_id = {$row['user_id']}"; + $this->db->sql_query($sql); + + $this->processed++; + } + } + $this->db->sql_freeresult($result); + + $this->db->sql_transaction('commit'); + + return ($i < $limit) ? true : $start + $i; + } +} -- cgit v1.2.1 From 13f365916caf9b01312da3717359316faa576521 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 26 Mar 2016 14:50:45 -0700 Subject: [ticket/14561] Remove unused use statements PHPBB3-14561 --- phpBB/phpbb/console/command/user/activate.php | 2 -- phpBB/phpbb/console/command/user/delete.php | 1 - phpBB/phpbb/console/command/user/reclean.php | 4 ---- 3 files changed, 7 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php index 890827afb6..697c1e5abe 100644 --- a/phpBB/phpbb/console/command/user/activate.php +++ b/phpBB/phpbb/console/command/user/activate.php @@ -17,8 +17,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; class activate extends \phpbb\console\command\command diff --git a/phpBB/phpbb/console/command/user/delete.php b/phpBB/phpbb/console/command/user/delete.php index 360b119e17..7251ecb3a5 100644 --- a/phpBB/phpbb/console/command/user/delete.php +++ b/phpBB/phpbb/console/command/user/delete.php @@ -18,7 +18,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; class delete extends \phpbb\console\command\command diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index c53d766cce..cd5fc60a05 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -13,12 +13,8 @@ namespace phpbb\console\command\user; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; class reclean extends \phpbb\console\command\command -- cgit v1.2.1 From aee3eec439b39ac1f8aa79582b302a499a23acc0 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 27 Mar 2016 09:31:47 -0700 Subject: [ticket/14561] Import classes with use statements PHPBB3-14561 --- phpBB/phpbb/console/command/user/activate.php | 37 ++++++++++++++++----------- phpBB/phpbb/console/command/user/add.php | 32 +++++++++++++---------- phpBB/phpbb/console/command/user/delete.php | 27 +++++++++++-------- phpBB/phpbb/console/command/user/reclean.php | 18 ++++++++----- 4 files changed, 68 insertions(+), 46 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php index 697c1e5abe..9eab06847c 100644 --- a/phpBB/phpbb/console/command/user/activate.php +++ b/phpBB/phpbb/console/command/user/activate.php @@ -13,27 +13,34 @@ namespace phpbb\console\command\user; +use phpbb\config\config; +use phpbb\console\command\command; +use phpbb\db\driver\driver_interface; +use phpbb\language\language; +use phpbb\log\log_interface; +use phpbb\notification\manager; +use phpbb\user; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class activate extends \phpbb\console\command\command +class activate extends command { - /** @var \phpbb\db\driver\driver_interface */ + /** @var driver_interface */ protected $db; - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; - /** @var \phpbb\log\log_interface */ + /** @var log_interface */ protected $log; - /** @var \phpbb\notification\manager */ + /** @var manager */ protected $notifications; /** @@ -53,16 +60,16 @@ class activate extends \phpbb\console\command\command /** * Construct method * - * @param \phpbb\user $user - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\config\config $config - * @param \phpbb\language\language $language - * @param \phpbb\log\log_interface $log - * @param \phpbb\notification\manager $notifications - * @param string $phpbb_root_path - * @param string $php_ext + * @param user $user + * @param driver_interface $db + * @param config $config + * @param language $language + * @param log_interface $log + * @param manager $notifications + * @param string $phpbb_root_path + * @param string $php_ext */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\log\log_interface $log, \phpbb\notification\manager $notifications, $phpbb_root_path, $php_ext) + public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, $phpbb_root_path, $php_ext) { $this->db = $db; $this->config = $config; diff --git a/phpBB/phpbb/console/command/user/add.php b/phpBB/phpbb/console/command/user/add.php index df1f4aa54a..c60a059251 100644 --- a/phpBB/phpbb/console/command/user/add.php +++ b/phpBB/phpbb/console/command/user/add.php @@ -13,28 +13,34 @@ namespace phpbb\console\command\user; +use phpbb\config\config; +use phpbb\console\command\command; +use phpbb\db\driver\driver_interface; use phpbb\exception\runtime_exception; +use phpbb\language\language; +use phpbb\passwords\manager; +use phpbb\user; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; -class add extends \phpbb\console\command\command +class add extends command { /** @var array Array of interactively acquired options */ protected $data; - /** @var \phpbb\db\driver\driver_interface */ + /** @var driver_interface */ protected $db; - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; - /** @var \phpbb\passwords\manager */ + /** @var manager */ protected $password_manager; /** @@ -54,15 +60,15 @@ class add extends \phpbb\console\command\command /** * Construct method * - * @param \phpbb\user $user - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\config\config $config - * @param \phpbb\language\language $language - * @param \phpbb\passwords\manager $password_manager - * @param string $phpbb_root_path - * @param string $php_ext + * @param user $user + * @param driver_interface $db + * @param config $config + * @param language $language + * @param manager $password_manager + * @param string $phpbb_root_path + * @param string $php_ext */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\passwords\manager $password_manager, $phpbb_root_path, $php_ext) + public function __construct(user $user, driver_interface $db, config $config, language $language, manager $password_manager, $phpbb_root_path, $php_ext) { $this->db = $db; $this->config = $config; diff --git a/phpBB/phpbb/console/command/user/delete.php b/phpBB/phpbb/console/command/user/delete.php index 7251ecb3a5..93e75d365b 100644 --- a/phpBB/phpbb/console/command/user/delete.php +++ b/phpBB/phpbb/console/command/user/delete.php @@ -13,6 +13,11 @@ namespace phpbb\console\command\user; +use phpbb\console\command\command; +use phpbb\db\driver\driver_interface; +use phpbb\language\language; +use phpbb\log\log_interface; +use phpbb\user; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -20,15 +25,15 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -class delete extends \phpbb\console\command\command +class delete extends command { - /** @var \phpbb\db\driver\driver_interface */ + /** @var driver_interface */ protected $db; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; - /** @var \phpbb\log\log_interface */ + /** @var log_interface */ protected $log; /** @@ -48,14 +53,14 @@ class delete extends \phpbb\console\command\command /** * Construct method * - * @param \phpbb\user $user - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\language\language $language - * @param \phpbb\log\log_interface $log - * @param string $phpbb_root_path - * @param string $php_ext + * @param user $user + * @param driver_interface $db + * @param language $language + * @param log_interface $log + * @param string $phpbb_root_path + * @param string $php_ext */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\log\log_interface $log, $phpbb_root_path, $php_ext) + public function __construct(user $user, driver_interface $db, language $language, log_interface $log, $phpbb_root_path, $php_ext) { $this->db = $db; $this->language = $language; diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index cd5fc60a05..e2f95c16d8 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -13,16 +13,20 @@ namespace phpbb\console\command\user; +use phpbb\console\command\command; +use phpbb\db\driver\driver_interface; +use phpbb\language\language; +use phpbb\user; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class reclean extends \phpbb\console\command\command +class reclean extends command { - /** @var \phpbb\db\driver\driver_interface */ + /** @var driver_interface */ protected $db; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; /** @var int A count of the number of re-cleaned user names */ @@ -31,11 +35,11 @@ class reclean extends \phpbb\console\command\command /** * Construct method * - * @param \phpbb\user $user - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\language\language $language + * @param user $user + * @param driver_interface $db + * @param language $language */ - public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\language\language $language) + public function __construct(user $user, driver_interface $db, language $language) { $this->db = $db; $this->language = $language; -- cgit v1.2.1 From ed0f151d863d7449d73336b3697e37259812215e Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 27 Mar 2016 09:47:45 -0700 Subject: [ticket/14561] Add extra help explaining reclean command PHPBB3-14561 --- phpBB/phpbb/console/command/user/reclean.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index e2f95c16d8..ba8a638e7b 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -57,6 +57,7 @@ class reclean extends command $this ->setName('user:reclean') ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_RECLEAN')) + ->setHelp($this->language->lang('CLI_HELP_USER_RECLEAN')) ; } -- cgit v1.2.1 From 4b789c041844396f3a5e6a51142c45c13d2edd59 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 27 Mar 2016 10:24:12 -0700 Subject: [ticket/14561] Use the user loader where appropriate PHPBB3-14561 --- phpBB/phpbb/console/command/user/activate.php | 31 ++++++++++----------------- phpBB/phpbb/console/command/user/delete.php | 31 ++++++++++----------------- 2 files changed, 22 insertions(+), 40 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php index 9eab06847c..5c36da6891 100644 --- a/phpBB/phpbb/console/command/user/activate.php +++ b/phpBB/phpbb/console/command/user/activate.php @@ -20,6 +20,7 @@ use phpbb\language\language; use phpbb\log\log_interface; use phpbb\notification\manager; use phpbb\user; +use phpbb\user_loader; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -43,6 +44,9 @@ class activate extends command /** @var manager */ protected $notifications; + /** @var user_loader */ + protected $user_loader; + /** * phpBB root path * @@ -66,16 +70,18 @@ class activate extends command * @param language $language * @param log_interface $log * @param manager $notifications + * @param user_loader $user_loader * @param string $phpbb_root_path * @param string $php_ext */ - public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, $phpbb_root_path, $php_ext) + public function __construct(user $user, driver_interface $db, config $config, language $language, log_interface $log, manager $notifications, user_loader $user_loader, $phpbb_root_path, $php_ext) { $this->db = $db; $this->config = $config; $this->language = $language; $this->log = $log; $this->notifications = $notifications; + $this->user_loader = $user_loader; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -132,7 +138,10 @@ class activate extends command $name = $input->getArgument('username'); $mode = ($input->getOption('deactivate')) ? 'deactivate' : 'activate'; - if (!$user_row = $this->get_user_data($name)) + $user_id = $this->user_loader->load_user_by_username($name); + $user_row = $this->user_loader->get_user($user_id); + + if ($user_row['user_id'] == ANONYMOUS) { $io->error($this->language->lang('NO_USER')); return 1; @@ -207,22 +216,4 @@ class activate extends command $messenger->send(NOTIFY_EMAIL); } } - - /** - * Get the user's data from the database - * - * @param string $name A user name - * @return mixed The user's data array if they exist, false otherwise. - */ - protected function get_user_data($name) - { - $sql = 'SELECT * - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'"; - $result = $this->db->sql_query_limit($sql, 1); - $user_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - return $user_row; - } } diff --git a/phpBB/phpbb/console/command/user/delete.php b/phpBB/phpbb/console/command/user/delete.php index 93e75d365b..8593541c1a 100644 --- a/phpBB/phpbb/console/command/user/delete.php +++ b/phpBB/phpbb/console/command/user/delete.php @@ -18,6 +18,7 @@ use phpbb\db\driver\driver_interface; use phpbb\language\language; use phpbb\log\log_interface; use phpbb\user; +use phpbb\user_loader; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -36,6 +37,9 @@ class delete extends command /** @var log_interface */ protected $log; + /** @var user_loader */ + protected $user_loader; + /** * phpBB root path * @@ -57,14 +61,16 @@ class delete extends command * @param driver_interface $db * @param language $language * @param log_interface $log + * @param user_loader $user_loader * @param string $phpbb_root_path * @param string $php_ext */ - public function __construct(user $user, driver_interface $db, language $language, log_interface $log, $phpbb_root_path, $php_ext) + public function __construct(user $user, driver_interface $db, language $language, log_interface $log, user_loader $user_loader, $phpbb_root_path, $php_ext) { $this->db = $db; $this->language = $language; $this->log = $log; + $this->user_loader = $user_loader; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -116,7 +122,10 @@ class delete extends command { $io = new SymfonyStyle($input, $output); - if (!$user_row = $this->get_user_data($name)) + $user_id = $this->user_loader->load_user_by_username($name); + $user_row = $this->user_loader->get_user($user_id); + + if ($user_row['user_id'] == ANONYMOUS) { $io->error($this->language->lang('NO_USER')); return 1; @@ -158,22 +167,4 @@ class delete extends command $input->setArgument('username', false); } } - - /** - * Get the user's data from the database - * - * @param string $name A user name - * @return mixed The user's id and username if they exist, false otherwise. - */ - protected function get_user_data($name) - { - $sql = 'SELECT user_id, username - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($name)) . "'"; - $result = $this->db->sql_query_limit($sql, 1); - $user_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - return $user_row; - } } -- cgit v1.2.1 From afb69d7cd280df65b22b1a338d3023aebf2e3f0c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 27 Mar 2016 11:25:19 -0700 Subject: [ticket/14561] Add a progress bar to reclean command PHPBB3-14561 --- phpBB/phpbb/console/command/user/reclean.php | 76 +++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index ba8a638e7b..20c2816be5 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -17,6 +17,7 @@ use phpbb\console\command\command; use phpbb\db\driver\driver_interface; use phpbb\language\language; use phpbb\user; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -32,6 +33,9 @@ class reclean extends command /** @var int A count of the number of re-cleaned user names */ protected $processed; + /** @var ProgressBar */ + protected $progress; + /** * Construct method * @@ -73,16 +77,27 @@ class reclean extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + + $io->section($this->language->lang('CLI_USER_RECLEAN_START')); + $this->processed = 0; + $this->progress = $this->create_progress_bar($this->get_count(), $io, $output); + $this->progress->setMessage($this->language->lang('CLI_USER_RECLEAN_START')); + $this->progress->start(); + $stage = 0; while ($stage !== true) { $stage = $this->reclean_usernames($stage); } - $io = new SymfonyStyle($input, $output); - $io->success($this->language->lang('CLI_USER_RECLEAN_SUCCESS', $this->processed)); + $this->progress->finish(); + + $io->newLine(2); + $io->success($this->language->lang('CLI_USER_RECLEAN_DONE', $this->processed)); + return 0; } @@ -116,6 +131,8 @@ class reclean extends command $this->processed++; } + + $this->progress->advance(); } $this->db->sql_freeresult($result); @@ -123,4 +140,59 @@ class reclean extends command return ($i < $limit) ? true : $start + $i; } + + /** + * Create a styled progress bar + * + * @param integer $max Max value for the progress bar + * @param SymfonyStyle $io + * @param OutputInterface $output The output stream, used to print messages + * @return ProgressBar + */ + protected function create_progress_bar($max, SymfonyStyle $io, OutputInterface $output) + { + $progress = $io->createProgressBar($max); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } + + return $progress; + } + + /** + * Get the count of users in the database + * + * @return int + */ + protected function get_count() + { + $sql = 'SELECT COUNT(user_id) AS count FROM ' . USERS_TABLE; + $result = $this->db->sql_query($sql); + $count = (int) $this->db->sql_fetchfield('count'); + $this->db->sql_freeresult($result); + + return $count; + } } -- cgit v1.2.1 From e81bf76dea82c4bc98ab7214a656a093c67f25dd Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 27 Mar 2016 11:30:05 -0700 Subject: [ticket/14561] Fix function docblock in activate command PHPBB3-14561 --- phpBB/phpbb/console/command/user/activate.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/activate.php b/phpBB/phpbb/console/command/user/activate.php index 5c36da6891..9c85718b4c 100644 --- a/phpBB/phpbb/console/command/user/activate.php +++ b/phpBB/phpbb/console/command/user/activate.php @@ -123,8 +123,7 @@ class activate extends command /** * Executes the command user:activate * - * Deletes a user from the database. An option to delete the user's posts - * is available, by default posts will be retained. + * Activate (or deactivate) a user account * * @param InputInterface $input The input stream used to get the options * @param OutputInterface $output The output stream, used to print messages -- cgit v1.2.1 From 2b90591a317fd75c7c8c4cf690d7209935f3e810 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 28 Mar 2016 15:26:56 -0700 Subject: [ticket/14561] Small change to progress bar output PHPBB3-14561 --- phpBB/phpbb/console/command/user/reclean.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index 20c2816be5..e298c285be 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -167,7 +167,7 @@ class reclean extends command $io->newLine(2); $progress->setFormat( " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); $progress->setBarWidth(60); } -- cgit v1.2.1 From d713ce94ff218c2464823cb23dae1007354c60f3 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 12 Apr 2016 10:56:23 -0700 Subject: [ticket/14569] Extract CLI progress bar creation to a method PHPBB3-14569 --- phpBB/phpbb/console/command/command.php | 45 ++++++++++++++++++++++ phpBB/phpbb/console/command/reparser/reparse.php | 40 +------------------ phpBB/phpbb/console/command/thumbnail/delete.php | 27 +------------ phpBB/phpbb/console/command/thumbnail/generate.php | 27 +------------ phpBB/phpbb/console/command/user/reclean.php | 40 ------------------- 5 files changed, 48 insertions(+), 131 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/command.php b/phpBB/phpbb/console/command/command.php index 638c989da2..0124c00d22 100644 --- a/phpBB/phpbb/console/command/command.php +++ b/phpBB/phpbb/console/command/command.php @@ -13,6 +13,10 @@ namespace phpbb\console\command; +use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; + abstract class command extends \Symfony\Component\Console\Command\Command { /** @var \phpbb\user */ @@ -28,4 +32,45 @@ abstract class command extends \Symfony\Component\Console\Command\Command $this->user = $user; parent::__construct(); } + + /** + * Create a styled progress bar + * + * @param int $max Max value for the progress bar + * @param SymfonyStyle $io Symfony style output decorator + * @param OutputInterface $output The output stream, used to print messages + * @param bool $message Should we display message output under the progress bar? + * @return ProgressBar + */ + public function create_progress_bar($max, SymfonyStyle $io, OutputInterface $output, $message = false) + { + $progress = $io->createProgressBar($max); + if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) + { + $progress->setFormat('[%percent:3s%%] %message%'); + $progress->setOverwrite(false); + } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); + $progress->setOverwrite(false); + } + else + { + $io->newLine(2); + $progress->setFormat( + " %current:s%/%max:s% %bar% %percent:3s%%\n" . + " " . ($message ? '%message%' : ' ') . " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); + $progress->setBarWidth(60); + } + + if (!defined('PHP_WINDOWS_VERSION_BUILD')) + { + $progress->setEmptyBarCharacter('░'); // light shade character \u2591 + $progress->setProgressCharacter(''); + $progress->setBarCharacter('▓'); // dark shade character \u2593 + } + + return $progress; + } } diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index ddc97a1d1d..b10bd56a58 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -121,44 +121,6 @@ class reparse extends \phpbb\console\command\command ; } - /** - * Create a styled progress bar - * - * @param integer $max Max value for the progress bar - * @return \Symfony\Component\Console\Helper\ProgressBar - */ - protected function create_progress_bar($max) - { - $progress = $this->io->createProgressBar($max); - if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $this->io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %message% %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - } - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } - - return $progress; - } - /** * Executes the command reparser:reparse * @@ -258,7 +220,7 @@ class reparse extends \phpbb\console\command\command $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); - $progress = $this->create_progress_bar($max); + $progress = $this->create_progress_bar($max, $this->io, $this->output, true); $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); $progress->start(); diff --git a/phpBB/phpbb/console/command/thumbnail/delete.php b/phpBB/phpbb/console/command/thumbnail/delete.php index e8e4cf568e..cfa9891fbc 100644 --- a/phpBB/phpbb/console/command/thumbnail/delete.php +++ b/phpBB/phpbb/console/command/thumbnail/delete.php @@ -91,32 +91,7 @@ class delete extends \phpbb\console\command\command WHERE thumbnail = 1'; $result = $this->db->sql_query($sql); - $progress = $io->createProgressBar($nb_missing_thumbnails); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - } - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } + $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output); $progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING')); diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index e677db3a97..64f7555336 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -115,32 +115,7 @@ class generate extends \phpbb\console\command\command require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext); } - $progress = $io->createProgressBar($nb_missing_thumbnails); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - } - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } + $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output); $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING')); diff --git a/phpBB/phpbb/console/command/user/reclean.php b/phpBB/phpbb/console/command/user/reclean.php index e298c285be..1a89f13382 100644 --- a/phpBB/phpbb/console/command/user/reclean.php +++ b/phpBB/phpbb/console/command/user/reclean.php @@ -141,46 +141,6 @@ class reclean extends command return ($i < $limit) ? true : $start + $i; } - /** - * Create a styled progress bar - * - * @param integer $max Max value for the progress bar - * @param SymfonyStyle $io - * @param OutputInterface $output The output stream, used to print messages - * @return ProgressBar - */ - protected function create_progress_bar($max, SymfonyStyle $io, OutputInterface $output) - { - $progress = $io->createProgressBar($max); - if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) - { - $progress->setFormat('[%percent:3s%%] %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('[%current:s%/%max:s%][%elapsed%/%estimated%][%memory%] %message%'); - $progress->setOverwrite(false); - } - else - { - $io->newLine(2); - $progress->setFormat( - " %current:s%/%max:s% %bar% %percent:3s%%\n" . - " %elapsed:6s%/%estimated:-6s% %memory:6s%\n"); - $progress->setBarWidth(60); - } - - if (!defined('PHP_WINDOWS_VERSION_BUILD')) - { - $progress->setEmptyBarCharacter('░'); // light shade character \u2591 - $progress->setProgressCharacter(''); - $progress->setBarCharacter('▓'); // dark shade character \u2593 - } - - return $progress; - } - /** * Get the count of users in the database * -- cgit v1.2.1 From d90afa67d866e1be44d3a69c97497c8412695f8d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 9 Oct 2016 21:37:30 +0200 Subject: [ticket/14814] Fix reparser cron PHPBB3-14814 --- phpBB/phpbb/console/command/reparser/reparse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index b10bd56a58..cebeee0919 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -208,7 +208,7 @@ class reparse extends \phpbb\console\command\command $size = $this->get_option('range-size'); // range-max has no default value, it must be computed for each reparser - if ($max == null) + if ($max === null) { $max = $reparser->get_max_id(); } -- cgit v1.2.1 From 346f31a03156839d1b1931d2fc69cd2ab5656bc0 Mon Sep 17 00:00:00 2001 From: Etienne Baroux Date: Mon, 2 Jun 2014 10:12:18 +0200 Subject: [ticket/12610] Add command to check if the board is up to date. PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 302 +++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 phpBB/phpbb/console/command/update/check.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php new file mode 100644 index 0000000000..0ef3c970ac --- /dev/null +++ b/phpBB/phpbb/console/command/update/check.php @@ -0,0 +1,302 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\console\command\update; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class check extends \phpbb\console\command\command +{ + /** @var \phpbb\config\config */ + protected $config; + + /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ + protected $phpbb_container; + + /** + * Construct method + */ + public function __construct(\phpbb\user $user, \phpbb\config\config $config, \Symfony\Component\DependencyInjection\ContainerInterface $phpbb_container) + { + parent::__construct($user); + + $this->config = $config; + $this->phpbb_container = $phpbb_container; + $this->user->add_lang(array('acp/common', 'acp/extensions')); + } + + /** + * Configures the service. + * + * Sets the name and description of the command. + * + * @return null + */ + protected function configure() + { + $this + ->setName('update:check') + ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) + ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) + ->addOption('stability', null, InputOption::VALUE_REQUIRED, 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY') + ->addOption('cache', 'c', InputOption::VALUE_NONE, 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE') + ; + } + + /** + * Executes the command. + * + * Checks if an update is available. + * If at least one is available, a message is printed and if verbose mode is set the list of possible updates is printed. + * If their is none, nothing is printed unless verbose mode is set. + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @return int 0 if the board is up to date, 1 if it is not and 2 if an error occured. + * @throws \RuntimeException + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $recheck = true; + if ($input->getOption('cache')) + { + $recheck = false; + } + + $stability = null; + if ($input->getOption('stability')) + { + $stability = $input->getOption('stability'); + if (!($stability == 'stable') && !($stability == 'unstable')) + { + throw new \RuntimeException($this->user->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + } + } + + $ext_name = $input->getArgument('ext-name'); + if ($ext_name != null) + { + if ($ext_name == 'all') + { + return $this->check_all_ext($input, $output, $stability, $recheck); + } + else + { + return $this->check_ext($input, $output, $stability, $recheck, $ext_name); + } + } + else + { + return $this->check_core($input, $output, $stability, $recheck); + } + } + + /** + * Check if a given extension is up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name + * @return int + */ + protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) + { + try + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + } + catch (\RuntimeException $e) + { + $output->writeln('' . $e->getMessage() . ''); + + return 2; + } + + $metadata = $md_manager->get_metadata('all'); + if ($input->getOption('verbose')) + { + $output->writeln('' . $md_manager->get_metadata('display-name') . ''); + $output->writeln(''); + + $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $metadata['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; + } + } + + /** + * Check if the core is up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_core(InputInterface $input, OutputInterface $output, $stability, $recheck) + { + $version_helper = $this->phpbb_container->get('version_helper'); + $version_helper->force_stability($stability); + + try + { + $updates_available = $version_helper->get_suggested_updates($recheck); + } + catch (\RuntimeException $e) + { + $output->writeln('' . $this->user->lang('VERSIONCHECK_FAIL') . ''); + + return 2; + } + + if ($input->getOption('verbose')) + { + $output->writeln('phpBB core'); + $output->writeln(''); + + $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $this->config['version']); + } + + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATE_NEEDED') . ''); + + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else + { + if ($input->getOption('verbose')) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; + } + } + + /** + * Check if all the available extensions are up to date + * + * @param InputInterface $input Input stream, used to get the options. + * @param OutputInterface $output Output stream, used to print messages. + * @param OutputInterface $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + + $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); + $current_version_length = max(15, strlen($this->user->lang('CURRENT_VERSION'))); + $latest_version_length = max(15, strlen($this->user->lang('LATEST_VERSION'))); + + $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->user->lang('EXTENSION_NAME'), $this->user->lang('CURRENT_VERSION'), $this->user->lang('LATEST_VERSION'))); + $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); + foreach ($ext_manager->all_available() as $ext_name => $ext_path) + { + $message = sprintf("%-{$ext_name_length}s", $ext_name); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + try + { + $metadata = $md_manager->get_metadata('all'); + $message .= sprintf(" | %-{$current_version_length}s", $metadata['version']); + try + { + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + $message .= sprintf(" | %s", implode(', ', array_keys($updates_available))); + } + catch (\RuntimeException $e) + { + $message .= ' | '; + } + } + catch (\RuntimeException $e) + { + $message .= ('' . $e->getMessage() . ''); + } + + $output->writeln($message); + } + + return 0; + } + + /** + * Display the details of the available updates + * + * @param OutputInterface $output Output stream, used to print messages. + * @param array $updates_available The list of the available updates + */ + protected function display_versions(OutputInterface $output, $updates_available) + { + $output->writeln(''); + $output->writeln('' . $this->user->lang('UPDATES_AVAILABLE') . ''); + foreach ($updates_available as $version_data) + { + $messages = array(); + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('VERSION'), $version_data['current']); + + if (isset($version_data['announcement'])) + { + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + } + + if (isset($version_data['download'])) + { + $messages[] = sprintf("\t%-30s| %s", $this->user->lang('DOWNLOAD_LATEST'), $version_data['download']); + } + + $messages[] = ''; + + $output->writeln(implode("\n", $messages)); + } + } +} -- cgit v1.2.1 From 8481bd4e1831e3f9911263957637f4095fb088b0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 24 Aug 2015 12:33:32 +0200 Subject: [ticket/12610] Use exception_interface PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 32 +++++++++------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 0ef3c970ac..982c86bf8c 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -13,6 +13,7 @@ namespace phpbb\console\command\update; +use phpbb\exception\exception_interface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -116,18 +117,9 @@ class check extends \phpbb\console\command\command */ protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) { - try - { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); - $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); - } - catch (\RuntimeException $e) - { - $output->writeln('' . $e->getMessage() . ''); - - return 2; - } + $ext_manager = $this->phpbb_container->get('ext.manager'); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); if ($input->getOption('verbose')) @@ -178,16 +170,7 @@ class check extends \phpbb\console\command\command $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); - try - { - $updates_available = $version_helper->get_suggested_updates($recheck); - } - catch (\RuntimeException $e) - { - $output->writeln('' . $this->user->lang('VERSIONCHECK_FAIL') . ''); - - return 2; - } + $updates_available = $version_helper->get_suggested_updates($recheck); if ($input->getOption('verbose')) { @@ -258,6 +241,11 @@ class check extends \phpbb\console\command\command $message .= ' | '; } } + catch (exception_interface $e) + { + $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); + $message .= ('' . $exception_message . ''); + } catch (\RuntimeException $e) { $message .= ('' . $e->getMessage() . ''); -- cgit v1.2.1 From 45dda53310bb618dce0813d61a85948cb334e4a9 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 26 Aug 2015 12:06:56 +0200 Subject: [ticket/12610] Improve output PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 32 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 982c86bf8c..03dd313291 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -52,8 +52,8 @@ class check extends \phpbb\console\command\command ->setName('update:check') ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) - ->addOption('stability', null, InputOption::VALUE_REQUIRED, 'CLI_DESCRIPTION_CRON_RUN_OPTION_STABILITY') - ->addOption('cache', 'c', InputOption::VALUE_NONE, 'CLI_DESCRIPTION_CRON_RUN_OPTION_CACHE') + ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) + ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) ; } @@ -215,6 +215,7 @@ class check extends \phpbb\console\command\command */ protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) { + /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); @@ -230,15 +231,30 @@ class check extends \phpbb\console\command\command try { $metadata = $md_manager->get_metadata('all'); - $message .= sprintf(" | %-{$current_version_length}s", $metadata['version']); - try + if (isset($metadata['extra']['version-check'])) { - $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); - $message .= sprintf(" | %s", implode(', ', array_keys($updates_available))); + try { + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + if (!empty($updates_available)) + { + $message .= sprintf(" | %-{$current_version_length}s | %s", + $metadata['version'], + implode(', ', array_keys($updates_available)) + ); + } + else + { + $message .= sprintf(" | %-{$current_version_length}s | ", + $metadata['version'] + ); + } + } catch (\RuntimeException $e) { + $message .= ' | '; + } } - catch (\RuntimeException $e) + else { - $message .= ' | '; + $message .= sprintf(" | %-{$current_version_length}s | ", $metadata['version']); } } catch (exception_interface $e) -- cgit v1.2.1 From c9e493a911d8296ce1ccca5de8ec4c9f84e1983d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 18 Feb 2016 22:33:39 +0100 Subject: [ticket/12610] Display the latest version and not the branch name in CLI PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 03dd313291..7c1e52c955 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -237,9 +237,14 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); if (!empty($updates_available)) { + $versions = array_map(function($entry) + { + return $entry['current']; + }, $updates_available); + $message .= sprintf(" | %-{$current_version_length}s | %s", $metadata['version'], - implode(', ', array_keys($updates_available)) + implode(', ', $versions) ); } else -- cgit v1.2.1 From 6c35ca80edd76906638326468b15aa9f355b477b Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 10:37:17 +0100 Subject: [ticket/12610] Add a better error message when an extension is missing PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 107 ++++++++++++++++----------- 1 file changed, 63 insertions(+), 44 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 7c1e52c955..19da2318ca 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -13,11 +13,15 @@ namespace phpbb\console\command\update; +use phpbb\config\config; use phpbb\exception\exception_interface; +use phpbb\language\language; +use phpbb\user; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; class check extends \phpbb\console\command\command { @@ -26,17 +30,23 @@ class check extends \phpbb\console\command\command /** @var \Symfony\Component\DependencyInjection\ContainerBuilder */ protected $phpbb_container; + /** + * @var language + */ + private $language; /** * Construct method */ - public function __construct(\phpbb\user $user, \phpbb\config\config $config, \Symfony\Component\DependencyInjection\ContainerInterface $phpbb_container) + public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language) { parent::__construct($user); $this->config = $config; $this->phpbb_container = $phpbb_container; - $this->user->add_lang(array('acp/common', 'acp/extensions')); + $this->language = $language; + + $this->language->add_lang(array('acp/common', 'acp/extensions')); } /** @@ -50,10 +60,10 @@ class check extends \phpbb\console\command\command { $this ->setName('update:check') - ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK')) - ->addArgument('ext-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) - ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) - ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->user->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) + ->setDescription($this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK')) + ->addArgument('ext-name', InputArgument::OPTIONAL, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_ARGUMENT_1')) + ->addOption('stability', null, InputOption::VALUE_REQUIRED, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_STABILITY')) + ->addOption('cache', 'c', InputOption::VALUE_NONE, $this->language->lang('CLI_DESCRIPTION_UPDATE_CHECK_OPTION_CACHE')) ; } @@ -83,7 +93,7 @@ class check extends \phpbb\console\command\command $stability = $input->getOption('stability'); if (!($stability == 'stable') && !($stability == 'unstable')) { - throw new \RuntimeException($this->user->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + throw new \RuntimeException($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); } } @@ -117,42 +127,51 @@ class check extends \phpbb\console\command\command */ protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); - $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); - - $metadata = $md_manager->get_metadata('all'); - if ($input->getOption('verbose')) + try { - $output->writeln('' . $md_manager->get_metadata('display-name') . ''); - $output->writeln(''); - - $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $metadata['version']); - } - - if (!empty($updates_available)) - { - $output->writeln(''); - $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + $ext_manager = $this->phpbb_container->get('ext.manager'); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); + $metadata = $md_manager->get_metadata('all'); if ($input->getOption('verbose')) { - $this->display_versions($output, $updates_available); + $output->writeln('' . $md_manager->get_metadata('display-name') . ''); + $output->writeln(''); + + $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); } - return 1; - } - else - { - $output->writeln(''); - $output->writeln('' . $this->user->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + if (!empty($updates_available)) + { + $output->writeln(''); + $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - if ($input->getOption('verbose')) + if ($input->getOption('verbose')) + { + $this->display_versions($output, $updates_available); + } + + return 1; + } + else { - $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + $output->writeln(''); + $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); + + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + } + + return 0; } + } + catch (\RuntimeException $e) + { + $output->writeln(''.$this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name).''); - return 0; + return 1; } } @@ -177,13 +196,13 @@ class check extends \phpbb\console\command\command $output->writeln('phpBB core'); $output->writeln(''); - $output->writeln('' . $this->user->lang('CURRENT_VERSION') . $this->user->lang('COLON') . ' ' . $this->config['version']); + $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); } if (!empty($updates_available)) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATE_NEEDED') . ''); + $output->writeln('' . $this->language->lang('UPDATE_NEEDED') . ''); if ($input->getOption('verbose')) { @@ -197,7 +216,7 @@ class check extends \phpbb\console\command\command if ($input->getOption('verbose')) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATE_NOT_NEEDED') . ''); + $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); } return 0; @@ -218,11 +237,11 @@ class check extends \phpbb\console\command\command /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); - $ext_name_length = max(30, strlen($this->user->lang('EXTENSION_NAME'))); - $current_version_length = max(15, strlen($this->user->lang('CURRENT_VERSION'))); - $latest_version_length = max(15, strlen($this->user->lang('LATEST_VERSION'))); + $ext_name_length = max(30, strlen($this->language->lang('EXTENSION_NAME'))); + $current_version_length = max(15, strlen($this->language->lang('CURRENT_VERSION'))); + $latest_version_length = max(15, strlen($this->language->lang('LATEST_VERSION'))); - $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->user->lang('EXTENSION_NAME'), $this->user->lang('CURRENT_VERSION'), $this->user->lang('LATEST_VERSION'))); + $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->language->lang('EXTENSION_NAME'), $this->language->lang('CURRENT_VERSION'), $this->language->lang('LATEST_VERSION'))); $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); foreach ($ext_manager->all_available() as $ext_name => $ext_path) { @@ -287,20 +306,20 @@ class check extends \phpbb\console\command\command protected function display_versions(OutputInterface $output, $updates_available) { $output->writeln(''); - $output->writeln('' . $this->user->lang('UPDATES_AVAILABLE') . ''); + $output->writeln('' . $this->language->lang('UPDATES_AVAILABLE') . ''); foreach ($updates_available as $version_data) { $messages = array(); - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('VERSION'), $version_data['current']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('VERSION'), $version_data['current']); if (isset($version_data['announcement'])) { - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); } if (isset($version_data['download'])) { - $messages[] = sprintf("\t%-30s| %s", $this->user->lang('DOWNLOAD_LATEST'), $version_data['download']); + $messages[] = sprintf("\t%-30s| %s", $this->language->lang('DOWNLOAD_LATEST'), $version_data['download']); } $messages[] = ''; -- cgit v1.2.1 From 32aa0596f3750ff19f3da799d649e7b2a3429c47 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 4 Dec 2016 17:43:51 +0100 Subject: [ticket/12610] Use Symfony style guide PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 173 +++++++++++++-------------- 1 file changed, 86 insertions(+), 87 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 19da2318ca..aaccfa4983 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -21,6 +21,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\ContainerInterface; class check extends \phpbb\console\command\command @@ -40,13 +41,13 @@ class check extends \phpbb\console\command\command */ public function __construct(user $user, config $config, ContainerInterface $phpbb_container, language $language) { - parent::__construct($user); - $this->config = $config; $this->phpbb_container = $phpbb_container; $this->language = $language; $this->language->add_lang(array('acp/common', 'acp/extensions')); + + parent::__construct($user); } /** @@ -81,6 +82,8 @@ class check extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $recheck = true; if ($input->getOption('cache')) { @@ -93,7 +96,8 @@ class check extends \phpbb\console\command\command $stability = $input->getOption('stability'); if (!($stability == 'stable') && !($stability == 'unstable')) { - throw new \RuntimeException($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + $io->error($this->language->lang('CLI_ERROR_INVALID_STABILITY', $stability)); + return 3; } } @@ -102,30 +106,29 @@ class check extends \phpbb\console\command\command { if ($ext_name == 'all') { - return $this->check_all_ext($input, $output, $stability, $recheck); + return $this->check_all_ext($io, $stability, $recheck); } else { - return $this->check_ext($input, $output, $stability, $recheck, $ext_name); + return $this->check_ext($io, $stability, $recheck, $ext_name); } } else { - return $this->check_core($input, $output, $stability, $recheck); + return $this->check_core($io,$stability, $recheck); } } /** - * Check if a given extension is up to date - * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @param string $ext_name The extension name - * @return int - */ - protected function check_ext(InputInterface $input, OutputInterface $output, $stability, $recheck, $ext_name) + * Check if a given extension is up to date + * + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name + * @return int + */ + protected function check_ext(SymfonyStyle $io, $stability, $recheck, $ext_name) { try { @@ -134,34 +137,29 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('' . $md_manager->get_metadata('display-name') . ''); - $output->writeln(''); + $io->title($md_manager->get_metadata('display-name')); - $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); + $io->note($this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $metadata['version']); } if (!empty($updates_available)) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $this->display_versions($output, $updates_available); + $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name'])); + + $this->display_versions($io, $updates_available); } return 1; } else { - $output->writeln(''); - $output->writeln('' . $this->language->lang('NOT_UP_TO_DATE', $metadata['name']) . ''); - - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } return 0; @@ -169,54 +167,50 @@ class check extends \phpbb\console\command\command } catch (\RuntimeException $e) { - $output->writeln(''.$this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name).''); + $io->error($this->language->lang('EXTENSION_NOT_INSTALLED', $ext_name)); return 1; } } /** - * Check if the core is up to date - * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @return int - */ - protected function check_core(InputInterface $input, OutputInterface $output, $stability, $recheck) + * Check if the core is up to date + * + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @return int + */ + protected function check_core(SymfonyStyle $io, $stability, $recheck) { $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); $updates_available = $version_helper->get_suggested_updates($recheck); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln('phpBB core'); - $output->writeln(''); + $io->title('phpBB core'); - $output->writeln('' . $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); + $io->note( $this->language->lang('CURRENT_VERSION') . $this->language->lang('COLON') . ' ' . $this->config['version']); } if (!empty($updates_available)) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATE_NEEDED') . ''); + $io->caution($this->language->lang('UPDATE_NEEDED')); - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $this->display_versions($output, $updates_available); + $this->display_versions($io, $updates_available); } return 1; } else { - if ($input->getOption('verbose')) + if ($io->isVerbose()) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATE_NOT_NEEDED') . ''); + $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } return 0; @@ -226,27 +220,22 @@ class check extends \phpbb\console\command\command /** * Check if all the available extensions are up to date * - * @param InputInterface $input Input stream, used to get the options. - * @param OutputInterface $output Output stream, used to print messages. - * @param OutputInterface $stability Force a given stability - * @param bool $recheck Disallow the use of the cache + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param bool $recheck Disallow the use of the cache * @return int */ - protected function check_all_ext(InputInterface $input, OutputInterface $output, $stability, $recheck) + protected function check_all_ext(SymfonyStyle $io, $stability, $recheck) { /** @var \phpbb\extension\manager $ext_manager */ $ext_manager = $this->phpbb_container->get('ext.manager'); - $ext_name_length = max(30, strlen($this->language->lang('EXTENSION_NAME'))); - $current_version_length = max(15, strlen($this->language->lang('CURRENT_VERSION'))); - $latest_version_length = max(15, strlen($this->language->lang('LATEST_VERSION'))); + $rows = []; - $output->writeln(sprintf("%-{$ext_name_length}s | %-{$current_version_length}s | %s", $this->language->lang('EXTENSION_NAME'), $this->language->lang('CURRENT_VERSION'), $this->language->lang('LATEST_VERSION'))); - $output->writeln(sprintf("%'-{$ext_name_length}s-+-%'-{$current_version_length}s-+-%'-{$latest_version_length}s", '', '', '')); foreach ($ext_manager->all_available() as $ext_name => $ext_path) { - $message = sprintf("%-{$ext_name_length}s", $ext_name); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $row = []; + $row[] = sprintf("%s", $ext_name); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); try { $metadata = $md_manager->get_metadata('all'); @@ -261,70 +250,80 @@ class check extends \phpbb\console\command\command return $entry['current']; }, $updates_available); - $message .= sprintf(" | %-{$current_version_length}s | %s", - $metadata['version'], - implode(', ', $versions) - ); + $row[] = sprintf("%s", $metadata['version']); + $row[] = implode(', ', $versions); } else { - $message .= sprintf(" | %-{$current_version_length}s | ", - $metadata['version'] - ); + $row[] = sprintf("%s", $metadata['version']); + $row[] = ''; } } catch (\RuntimeException $e) { - $message .= ' | '; + $row[] = $metadata['version']; + $row[] = ''; } } else { - $message .= sprintf(" | %-{$current_version_length}s | ", $metadata['version']); + $row[] = $metadata['version']; + $row[] = ''; } } catch (exception_interface $e) { $exception_message = call_user_func_array(array($this->user, 'lang'), array_merge(array($e->getMessage()), $e->get_parameters())); - $message .= ('' . $exception_message . ''); + $row[] = '' . $exception_message . ''; } catch (\RuntimeException $e) { - $message .= ('' . $e->getMessage() . ''); + $row[] = '' . $e->getMessage() . ''; } - $output->writeln($message); + $rows[] = $row; } + $io->table([ + $this->language->lang('EXTENSION_NAME'), + $this->language->lang('CURRENT_VERSION'), + $this->language->lang('LATEST_VERSION'), + ], $rows); + return 0; } /** * Display the details of the available updates * - * @param OutputInterface $output Output stream, used to print messages. - * @param array $updates_available The list of the available updates + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param array $updates_available The list of the available updates */ - protected function display_versions(OutputInterface $output, $updates_available) + protected function display_versions(SymfonyStyle $io, $updates_available) { - $output->writeln(''); - $output->writeln('' . $this->language->lang('UPDATES_AVAILABLE') . ''); + $io->section($this->language->lang('UPDATES_AVAILABLE')); + + $rows = []; foreach ($updates_available as $version_data) { - $messages = array(); - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('VERSION'), $version_data['current']); + $row = ['', '', '']; + $row[0] = $version_data['current']; if (isset($version_data['announcement'])) { - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('ANNOUNCEMENT_TOPIC'), $version_data['announcement']); + $row[1] = $version_data['announcement']; } if (isset($version_data['download'])) { - $messages[] = sprintf("\t%-30s| %s", $this->language->lang('DOWNLOAD_LATEST'), $version_data['download']); + $row[2] = $version_data['download']; } - $messages[] = ''; - - $output->writeln(implode("\n", $messages)); + $rows[] = $row; } + + $io->table([ + $this->language->lang('VERSION'), + $this->language->lang('ANNOUNCEMENT_TOPIC'), + $this->language->lang('DOWNLOAD_LATEST'), + ], $rows); } } -- cgit v1.2.1 From 103d344cd4476b452e42cd7ba0007b5a85caeaaf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 5 Dec 2016 15:46:05 +0100 Subject: [ticket/12610] Fix tests and use getOption() for console PHPBB3-12610 --- phpBB/phpbb/console/command/update/check.php | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index aaccfa4983..1f1cfa25d2 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -110,25 +110,26 @@ class check extends \phpbb\console\command\command } else { - return $this->check_ext($io, $stability, $recheck, $ext_name); + return $this->check_ext($input, $io, $stability, $recheck, $ext_name); } } else { - return $this->check_core($io,$stability, $recheck); + return $this->check_core($input, $io, $stability, $recheck); } } /** * Check if a given extension is up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO - * @param string $stability Force a given stability - * @param bool $recheck Disallow the use of the cache - * @param string $ext_name The extension name + * @param InputInterface $input Input stream, used to get the options. + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache + * @param string $ext_name The extension name * @return int */ - protected function check_ext(SymfonyStyle $io, $stability, $recheck, $ext_name) + protected function check_ext(InputInterface $input, SymfonyStyle $io, $stability, $recheck, $ext_name) { try { @@ -137,7 +138,7 @@ class check extends \phpbb\console\command\command $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->title($md_manager->get_metadata('display-name')); @@ -146,7 +147,7 @@ class check extends \phpbb\console\command\command if (!empty($updates_available)) { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->caution($this->language->lang('NOT_UP_TO_DATE', $metadata['name'])); @@ -157,7 +158,7 @@ class check extends \phpbb\console\command\command } else { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } @@ -176,19 +177,20 @@ class check extends \phpbb\console\command\command /** * Check if the core is up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO - * @param string $stability Force a given stability - * @param bool $recheck Disallow the use of the cache + * @param InputInterface $input Input stream, used to get the options. + * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param string $stability Force a given stability + * @param bool $recheck Disallow the use of the cache * @return int */ - protected function check_core(SymfonyStyle $io, $stability, $recheck) + protected function check_core(InputInterface $input, SymfonyStyle $io, $stability, $recheck) { $version_helper = $this->phpbb_container->get('version_helper'); $version_helper->force_stability($stability); $updates_available = $version_helper->get_suggested_updates($recheck); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->title('phpBB core'); @@ -199,7 +201,7 @@ class check extends \phpbb\console\command\command { $io->caution($this->language->lang('UPDATE_NEEDED')); - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $this->display_versions($io, $updates_available); } @@ -208,7 +210,7 @@ class check extends \phpbb\console\command\command } else { - if ($io->isVerbose()) + if ($input->getOption('verbose')) { $io->success($this->language->lang('UPDATE_NOT_NEEDED')); } @@ -220,7 +222,7 @@ class check extends \phpbb\console\command\command /** * Check if all the available extensions are up to date * - * @param SymfonyStyle $io IO handler, for formatted and unified IO + * @param SymfonyStyle $io IO handler, for formatted and unified IO * @param bool $recheck Disallow the use of the cache * @return int */ -- cgit v1.2.1 From 74cd513a8892285032a248322e3ce52b19645075 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 7 Dec 2016 10:13:09 -0800 Subject: [ticket/14895] CLI reparser:list should display proper list PHPBB3-14895 --- phpBB/phpbb/console/command/reparser/list_all.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index e42c3ac782..7dd0571975 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -54,7 +54,7 @@ class list_all extends \phpbb\console\command\command } /** - * Executes the command reparser:reparse + * Executes the command reparser:list * * @param InputInterface $input * @param OutputInterface $output @@ -62,7 +62,11 @@ class list_all extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('' . implode(', ', $this->reparser_names) . ''); + $output->writeln('' . $this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE') . ''); + foreach ($this->reparser_names as $reparser_name) + { + $output->writeln($reparser_name); + } return 0; } -- cgit v1.2.1 From d275fefc69bae24f547802d824607c9a054ff6d2 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 7 Dec 2016 23:49:54 -0800 Subject: [ticket/14895] Use SymfonyIO styling PHPBB3-14895 --- phpBB/phpbb/console/command/reparser/list_all.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 7dd0571975..028468649d 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\reparser; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class list_all extends \phpbb\console\command\command { @@ -62,11 +63,9 @@ class list_all extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('' . $this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE') . ''); - foreach ($this->reparser_names as $reparser_name) - { - $output->writeln($reparser_name); - } + $io = new SymfonyStyle($input, $output); + $io->section($this->user->lang('CLI_DESCRIPTION_REPARSER_AVAILABLE')); + $io->listing($this->reparser_names); return 0; } -- cgit v1.2.1 From b17fa7dfa588fc191f4ed268b88dcaec40294acb Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 8 Dec 2016 14:24:02 -0800 Subject: [ticket/14895] Use SymfonyStyle in all CLI PHPBB3-14895 --- phpBB/phpbb/console/command/cache/purge.php | 4 ++- phpBB/phpbb/console/command/config/delete.php | 7 ++-- phpBB/phpbb/console/command/config/get.php | 5 ++- phpBB/phpbb/console/command/config/increment.php | 5 ++- phpBB/phpbb/console/command/config/set.php | 5 ++- phpBB/phpbb/console/command/config/set_atomic.php | 7 ++-- phpBB/phpbb/console/command/cron/cron_list.php | 39 ++++++---------------- phpBB/phpbb/console/command/db/list_command.php | 30 +++++++++++------ phpBB/phpbb/console/command/db/migrate.php | 7 ++-- phpBB/phpbb/console/command/db/revert.php | 10 ++++-- phpBB/phpbb/console/command/extension/disable.php | 7 ++-- phpBB/phpbb/console/command/extension/enable.php | 7 ++-- phpBB/phpbb/console/command/extension/purge.php | 7 ++-- phpBB/phpbb/console/command/extension/show.php | 28 ++++++---------- .../command/fixup/recalculate_email_hash.php | 15 +++++---- 15 files changed, 100 insertions(+), 83 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/cache/purge.php b/phpBB/phpbb/console/command/cache/purge.php index d0c2ef6f72..1da97624f5 100644 --- a/phpBB/phpbb/console/command/cache/purge.php +++ b/phpBB/phpbb/console/command/cache/purge.php @@ -14,6 +14,7 @@ namespace phpbb\console\command\cache; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class purge extends \phpbb\console\command\command { @@ -84,6 +85,7 @@ class purge extends \phpbb\console\command\command $this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array()); - $output->writeln($this->user->lang('PURGE_CACHE_SUCCESS')); + $io = new SymfonyStyle($input, $output); + $io->success($this->user->lang('PURGE_CACHE_SUCCESS')); } } diff --git a/phpBB/phpbb/console/command/config/delete.php b/phpBB/phpbb/console/command/config/delete.php index efd276d7e3..a1ccefe286 100644 --- a/phpBB/phpbb/console/command/config/delete.php +++ b/phpBB/phpbb/console/command/config/delete.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\config; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class delete extends command { @@ -47,17 +48,19 @@ class delete extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $key = $input->getArgument('key'); if (isset($this->config[$key])) { $this->config->delete($key); - $output->writeln('' . $this->user->lang('CLI_CONFIG_DELETE_SUCCESS', $key) . ''); + $io->success($this->user->lang('CLI_CONFIG_DELETE_SUCCESS', $key)); } else { - $output->writeln('' . $this->user->lang('CLI_CONFIG_NOT_EXISTS', $key) . ''); + $io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key)); } } } diff --git a/phpBB/phpbb/console/command/config/get.php b/phpBB/phpbb/console/command/config/get.php index 9c03b49a3d..b2b824dd12 100644 --- a/phpBB/phpbb/console/command/config/get.php +++ b/phpBB/phpbb/console/command/config/get.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class get extends command { @@ -54,6 +55,8 @@ class get extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $key = $input->getArgument('key'); if (isset($this->config[$key]) && $input->getOption('no-newline')) @@ -66,7 +69,7 @@ class get extends command } else { - $output->writeln('' . $this->user->lang('CLI_CONFIG_NOT_EXISTS', $key) . ''); + $io->error($this->user->lang('CLI_CONFIG_NOT_EXISTS', $key)); } } } diff --git a/phpBB/phpbb/console/command/config/increment.php b/phpBB/phpbb/console/command/config/increment.php index b4d7438b66..8b3acc1620 100644 --- a/phpBB/phpbb/console/command/config/increment.php +++ b/phpBB/phpbb/console/command/config/increment.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class increment extends command { @@ -59,12 +60,14 @@ class increment extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $key = $input->getArgument('key'); $increment = $input->getArgument('increment'); $use_cache = !$input->getOption('dynamic'); $this->config->increment($key, $increment, $use_cache); - $output->writeln('' . $this->user->lang('CLI_CONFIG_INCREMENT_SUCCESS', $key) . ''); + $io->success($this->user->lang('CLI_CONFIG_INCREMENT_SUCCESS', $key)); } } diff --git a/phpBB/phpbb/console/command/config/set.php b/phpBB/phpbb/console/command/config/set.php index 695de31013..889fb630c6 100644 --- a/phpBB/phpbb/console/command/config/set.php +++ b/phpBB/phpbb/console/command/config/set.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class set extends command { @@ -59,12 +60,14 @@ class set extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $key = $input->getArgument('key'); $value = $input->getArgument('value'); $use_cache = !$input->getOption('dynamic'); $this->config->set($key, $value, $use_cache); - $output->writeln('' . $this->user->lang('CLI_CONFIG_SET_SUCCESS', $key) . ''); + $io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key)); } } diff --git a/phpBB/phpbb/console/command/config/set_atomic.php b/phpBB/phpbb/console/command/config/set_atomic.php index e8c69a0885..475d8a9271 100644 --- a/phpBB/phpbb/console/command/config/set_atomic.php +++ b/phpBB/phpbb/console/command/config/set_atomic.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class set_atomic extends command { @@ -65,6 +66,8 @@ class set_atomic extends command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $key = $input->getArgument('key'); $old_value = $input->getArgument('old'); $new_value = $input->getArgument('new'); @@ -72,12 +75,12 @@ class set_atomic extends command if ($this->config->set_atomic($key, $old_value, $new_value, $use_cache)) { - $output->writeln('' . $this->user->lang('CLI_CONFIG_SET_SUCCESS', $key) . ''); + $io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key)); return 0; } else { - $output->writeln('' . $this->user->lang('CLI_CONFIG_SET_FAILURE', $key) . ''); + $io->error($this->user->lang('CLI_CONFIG_SET_FAILURE', $key)); return 1; } } diff --git a/phpBB/phpbb/console/command/cron/cron_list.php b/phpBB/phpbb/console/command/cron/cron_list.php index c515fd9e80..0618cee4db 100644 --- a/phpBB/phpbb/console/command/cron/cron_list.php +++ b/phpBB/phpbb/console/command/cron/cron_list.php @@ -14,6 +14,7 @@ namespace phpbb\console\command\cron; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class cron_list extends \phpbb\console\command\command { @@ -55,57 +56,39 @@ class cron_list extends \phpbb\console\command\command */ protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $tasks = $this->cron_manager->get_tasks(); if (empty($tasks)) { - $output->writeln($this->user->lang('CRON_NO_TASKS')); + $io->error($this->user->lang('CRON_NO_TASKS')); return; } - $ready_tasks = array(); - $not_ready_tasks = array(); + $ready_tasks = $not_ready_tasks = array(); foreach ($tasks as $task) { if ($task->is_ready()) { - $ready_tasks[] = $task; + $ready_tasks[] = $task->get_name(); } else { - $not_ready_tasks[] = $task; + $not_ready_tasks[] = $task->get_name(); } } if (!empty($ready_tasks)) { - $output->writeln('' . $this->user->lang('TASKS_READY') . ''); - $this->print_tasks_names($ready_tasks, $output); - } - - if (!empty($ready_tasks) && !empty($not_ready_tasks)) - { - $output->writeln(''); + $io->section($this->user->lang('TASKS_READY')); + $io->listing($ready_tasks); } if (!empty($not_ready_tasks)) { - $output->writeln('' . $this->user->lang('TASKS_NOT_READY') . ''); - $this->print_tasks_names($not_ready_tasks, $output); - } - } - - /** - * Print a list of cron jobs - * - * @param array $tasks A list of task to display - * @param OutputInterface $output An OutputInterface instance - */ - protected function print_tasks_names(array $tasks, OutputInterface $output) - { - foreach ($tasks as $task) - { - $output->writeln($task->get_name()); + $io->section($this->user->lang('TASKS_NOT_READY')); + $io->listing($not_ready_tasks); } } } diff --git a/phpBB/phpbb/console/command/db/list_command.php b/phpBB/phpbb/console/command/db/list_command.php index 708107b592..77f26dd786 100644 --- a/phpBB/phpbb/console/command/db/list_command.php +++ b/phpBB/phpbb/console/command/db/list_command.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\db; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class list_command extends \phpbb\console\command\db\migration_command { @@ -34,6 +35,8 @@ class list_command extends \phpbb\console\command\db\migration_command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $show_installed = !$input->getOption('available'); $installed = $available = array(); @@ -51,23 +54,28 @@ class list_command extends \phpbb\console\command\db\migration_command if ($show_installed) { - $output->writeln('' . $this->user->lang('CLI_MIGRATIONS_INSTALLED') . $this->user->lang('COLON') . ''); - $output->writeln($installed); + $io->section($this->user->lang('CLI_MIGRATIONS_INSTALLED')); - if (empty($installed)) + if (!empty($installed)) { - $output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY')); + $io->listing($installed); + } + else + { + $io->text($this->user->lang('CLI_MIGRATIONS_EMPTY')); + $io->newLine(); } - - $output->writeln(''); } - $output->writeln('' . $this->user->lang('CLI_MIGRATIONS_AVAILABLE') . $this->user->lang('COLON') . ''); - $output->writeln($available); - - if (empty($available)) + $io->section($this->user->lang('CLI_MIGRATIONS_AVAILABLE')); + if (!empty($available)) + { + $io->listing($available); + } + else { - $output->writeln($this->user->lang('CLI_MIGRATIONS_EMPTY')); + $io->text($this->user->lang('CLI_MIGRATIONS_EMPTY')); + $io->newLine(); } } } diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index ae4211f7be..f2cc9142a6 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\db; use phpbb\db\output_handler\log_wrapper_migrator_output_handler; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class migrate extends \phpbb\console\command\db\migration_command { @@ -50,6 +51,8 @@ class migrate extends \phpbb\console\command\db\migration_command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $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)); $this->migrator->create_migrations_table(); @@ -66,7 +69,7 @@ class migrate extends \phpbb\console\command\db\migration_command } catch (\phpbb\db\migration\exception $e) { - $output->writeln('' . $e->getLocalisedMessage($this->user) . ''); + $io->error($e->getLocalisedMessage($this->user)); $this->finalise_update(); return 1; } @@ -78,6 +81,6 @@ class migrate extends \phpbb\console\command\db\migration_command } $this->finalise_update(); - $output->writeln($this->user->lang['DATABASE_UPDATE_COMPLETE']); + $io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL')); } } diff --git a/phpBB/phpbb/console/command/db/revert.php b/phpBB/phpbb/console/command/db/revert.php index 3fa2e17515..7977afc319 100644 --- a/phpBB/phpbb/console/command/db/revert.php +++ b/phpBB/phpbb/console/command/db/revert.php @@ -16,6 +16,7 @@ use phpbb\db\output_handler\log_wrapper_migrator_output_handler; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class revert extends \phpbb\console\command\db\migration_command { @@ -52,6 +53,8 @@ class revert extends \phpbb\console\command\db\migration_command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $name = str_replace('/', '\\', $input->getArgument('name')); $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 @@ class revert extends \phpbb\console\command\db\migration_command if (!in_array($name, $this->load_migrations())) { - $output->writeln('' . $this->user->lang('MIGRATION_NOT_VALID', $name) . ''); + $io->error($this->language->lang('MIGRATION_NOT_VALID', $name)); return 1; } else if ($this->migrator->migration_state($name) === false) { - $output->writeln('' . $this->user->lang('MIGRATION_NOT_INSTALLED', $name) . ''); + $io->error($this->language->lang('MIGRATION_NOT_INSTALLED', $name)); return 1; } @@ -78,11 +81,12 @@ class revert extends \phpbb\console\command\db\migration_command } catch (\phpbb\db\migration\exception $e) { - $output->writeln('' . $e->getLocalisedMessage($this->user) . ''); + $io->error($e->getLocalisedMessage($this->user)); $this->finalise_update(); return 1; } $this->finalise_update(); + $io->success($this->language->lang('INLINE_UPDATE_SUCCESSFUL')); } } diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index 1eee16cbd9..d022755753 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\extension; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class disable extends command { @@ -33,19 +34,21 @@ class disable extends command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $name = $input->getArgument('extension-name'); $this->manager->disable($name); $this->manager->load_extensions(); if ($this->manager->is_enabled($name)) { - $output->writeln('' . $this->user->lang('CLI_EXTENSION_DISABLE_FAILURE', $name) . ''); + $io->error($this->user->lang('CLI_EXTENSION_DISABLE_FAILURE', $name)); return 1; } else { $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_DISABLE', time(), array($name)); - $output->writeln('' . $this->user->lang('CLI_EXTENSION_DISABLE_SUCCESS', $name) . ''); + $io->success($this->user->lang('CLI_EXTENSION_DISABLE_SUCCESS', $name)); return 0; } } diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index 59ff11e9b7..14077d688b 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\extension; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class enable extends command { @@ -33,6 +34,8 @@ class enable extends command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $name = $input->getArgument('extension-name'); $this->manager->enable($name); $this->manager->load_extensions(); @@ -40,12 +43,12 @@ class enable extends command if ($this->manager->is_enabled($name)) { $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($name)); - $output->writeln('' . $this->user->lang('CLI_EXTENSION_ENABLE_SUCCESS', $name) . ''); + $io->success($this->user->lang('CLI_EXTENSION_ENABLE_SUCCESS', $name)); return 0; } else { - $output->writeln('' . $this->user->lang('CLI_EXTENSION_ENABLE_FAILURE', $name) . ''); + $io->error($this->user->lang('CLI_EXTENSION_ENABLE_FAILURE', $name)); return 1; } } diff --git a/phpBB/phpbb/console/command/extension/purge.php b/phpBB/phpbb/console/command/extension/purge.php index 517e9a74c9..25bde503f7 100644 --- a/phpBB/phpbb/console/command/extension/purge.php +++ b/phpBB/phpbb/console/command/extension/purge.php @@ -15,6 +15,7 @@ namespace phpbb\console\command\extension; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class purge extends command { @@ -33,19 +34,21 @@ class purge extends command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $name = $input->getArgument('extension-name'); $this->manager->purge($name); $this->manager->load_extensions(); if ($this->manager->is_enabled($name)) { - $output->writeln('' . $this->user->lang('CLI_EXTENSION_PURGE_FAILURE', $name) . ''); + $io->error($this->user->lang('CLI_EXTENSION_PURGE_FAILURE', $name)); return 1; } else { $this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_PURGE', time(), array($name)); - $output->writeln('' . $this->user->lang('CLI_EXTENSION_PURGE_SUCCESS', $name) . ''); + $io->success($this->user->lang('CLI_EXTENSION_PURGE_SUCCESS', $name)); return 0; } } diff --git a/phpBB/phpbb/console/command/extension/show.php b/phpBB/phpbb/console/command/extension/show.php index f9322034d7..7bad0c0a5a 100644 --- a/phpBB/phpbb/console/command/extension/show.php +++ b/phpBB/phpbb/console/command/extension/show.php @@ -14,6 +14,7 @@ namespace phpbb\console\command\extension; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class show extends command { @@ -27,36 +28,27 @@ class show extends command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $this->manager->load_extensions(); $all = array_keys($this->manager->all_available()); if (empty($all)) { - $output->writeln('' . $this->user->lang('CLI_EXTENSION_NOT_FOUND') . ''); + $io->note($this->user->lang('CLI_EXTENSION_NOT_FOUND')); return 3; } $enabled = array_keys($this->manager->all_enabled()); - $this->print_extension_list($output, $this->user->lang('CLI_EXTENSIONS_ENABLED') . $this->user->lang('COLON'), $enabled); - - $output->writeln(''); + $io->section($this->user->lang('CLI_EXTENSIONS_ENABLED')); + $io->listing($enabled); $disabled = array_keys($this->manager->all_disabled()); - $this->print_extension_list($output, $this->user->lang('CLI_EXTENSIONS_DISABLED') . $this->user->lang('COLON'), $disabled); - - $output->writeln(''); + $io->section($this->user->lang('CLI_EXTENSIONS_DISABLED')); + $io->listing($disabled); $purged = array_diff($all, $enabled, $disabled); - $this->print_extension_list($output, $this->user->lang('CLI_EXTENSIONS_AVAILABLE') . $this->user->lang('COLON'), $purged); - } - - protected function print_extension_list(OutputInterface $output, $type, array $extensions) - { - $output->writeln("$type"); - - foreach ($extensions as $extension) - { - $output->writeln(" - $extension"); - } + $io->section($this->user->lang('CLI_EXTENSIONS_AVAILABLE')); + $io->listing($purged); } } diff --git a/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php b/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php index ec4e1b0ee7..043f181e72 100644 --- a/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php +++ b/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php @@ -14,6 +14,7 @@ namespace phpbb\console\command\fixup; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class recalculate_email_hash extends \phpbb\console\command\command { @@ -37,6 +38,8 @@ class recalculate_email_hash extends \phpbb\console\command\command protected function execute(InputInterface $input, OutputInterface $output) { + $io = new SymfonyStyle($input, $output); + $sql = 'SELECT user_id, user_email, user_email_hash FROM ' . USERS_TABLE . ' WHERE user_type <> ' . USER_IGNORE . " @@ -59,17 +62,15 @@ class recalculate_email_hash extends \phpbb\console\command\command if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { - $output->writeln(sprintf( - 'user_id %d, email %s => %s', - $row['user_id'], - $row['user_email'], - $user_email_hash - )); + $io->table( + array('user_id', 'user_email', 'user_email_hash'), + array(array($row['user_id'], $row['user_email'], $user_email_hash)) + ); } } } $this->db->sql_freeresult($result); - $output->writeln('' . $this->user->lang('CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS') . ''); + $io->success($this->user->lang('CLI_FIXUP_RECALCULATE_EMAIL_HASH_SUCCESS')); } } -- cgit v1.2.1 From cbf6d71f6859fd6c036967ed19082f3e54efc328 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 8 Dec 2016 14:25:09 -0800 Subject: [ticket/14895] Fix issues in CLI classes PHPBB3-14895 --- phpBB/phpbb/console/command/cache/purge.php | 4 ++-- phpBB/phpbb/console/command/config/command.php | 2 +- phpBB/phpbb/console/command/config/delete.php | 2 +- phpBB/phpbb/console/command/config/get.php | 2 +- phpBB/phpbb/console/command/config/increment.php | 2 +- phpBB/phpbb/console/command/config/set.php | 2 +- phpBB/phpbb/console/command/cron/cron_list.php | 2 +- phpBB/phpbb/console/command/db/migrate.php | 6 +++--- .../phpbb/console/command/db/migration_command.php | 2 +- phpBB/phpbb/console/command/db/revert.php | 24 +++------------------- phpBB/phpbb/console/command/dev/migration_tips.php | 2 +- .../command/fixup/recalculate_email_hash.php | 2 +- 12 files changed, 17 insertions(+), 35 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/cache/purge.php b/phpBB/phpbb/console/command/cache/purge.php index 1da97624f5..b7a51b2bb4 100644 --- a/phpBB/phpbb/console/command/cache/purge.php +++ b/phpBB/phpbb/console/command/cache/purge.php @@ -40,7 +40,7 @@ class purge extends \phpbb\console\command\command * @param \phpbb\cache\driver\driver_interface $cache Cache instance * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\auth\auth $auth Auth instance - * @param \phpbb\log\log $log Logger instance + * @param \phpbb\log\log_interface $log Logger instance * @param \phpbb\config\config $config Config instance */ public function __construct(\phpbb\user $user, \phpbb\cache\driver\driver_interface $cache, \phpbb\db\driver\driver_interface $db, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\config\config $config) @@ -72,7 +72,7 @@ class purge extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/phpBB/phpbb/console/command/config/command.php b/phpBB/phpbb/console/command/config/command.php index f0ad5d4d19..19f67d3b6c 100644 --- a/phpBB/phpbb/console/command/config/command.php +++ b/phpBB/phpbb/console/command/config/command.php @@ -17,7 +17,7 @@ abstract class command extends \phpbb\console\command\command /** @var \phpbb\config\config */ protected $config; - function __construct(\phpbb\user $user, \phpbb\config\config $config) + public function __construct(\phpbb\user $user, \phpbb\config\config $config) { $this->config = $config; diff --git a/phpBB/phpbb/console/command/config/delete.php b/phpBB/phpbb/console/command/config/delete.php index a1ccefe286..2da0801337 100644 --- a/phpBB/phpbb/console/command/config/delete.php +++ b/phpBB/phpbb/console/command/config/delete.php @@ -43,7 +43,7 @@ class delete extends command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void * @see \phpbb\config\config::delete() */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/phpBB/phpbb/console/command/config/get.php b/phpBB/phpbb/console/command/config/get.php index b2b824dd12..f065787110 100644 --- a/phpBB/phpbb/console/command/config/get.php +++ b/phpBB/phpbb/console/command/config/get.php @@ -50,7 +50,7 @@ class get extends command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void * @see \phpbb\config\config::offsetGet() */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/phpBB/phpbb/console/command/config/increment.php b/phpBB/phpbb/console/command/config/increment.php index 8b3acc1620..647380a0bf 100644 --- a/phpBB/phpbb/console/command/config/increment.php +++ b/phpBB/phpbb/console/command/config/increment.php @@ -55,7 +55,7 @@ class increment extends command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void * @see \phpbb\config\config::increment() */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/phpBB/phpbb/console/command/config/set.php b/phpBB/phpbb/console/command/config/set.php index 889fb630c6..e9f7f8f91e 100644 --- a/phpBB/phpbb/console/command/config/set.php +++ b/phpBB/phpbb/console/command/config/set.php @@ -55,7 +55,7 @@ class set extends command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void * @see \phpbb\config\config::set() */ protected function execute(InputInterface $input, OutputInterface $output) diff --git a/phpBB/phpbb/console/command/cron/cron_list.php b/phpBB/phpbb/console/command/cron/cron_list.php index 0618cee4db..8f9d63eda2 100644 --- a/phpBB/phpbb/console/command/cron/cron_list.php +++ b/phpBB/phpbb/console/command/cron/cron_list.php @@ -52,7 +52,7 @@ class cron_list extends \phpbb\console\command\command * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * - * @return null + * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/phpBB/phpbb/console/command/db/migrate.php b/phpBB/phpbb/console/command/db/migrate.php index f2cc9142a6..4270e2d703 100644 --- a/phpBB/phpbb/console/command/db/migrate.php +++ b/phpBB/phpbb/console/command/db/migrate.php @@ -31,21 +31,21 @@ class migrate extends \phpbb\console\command\db\migration_command /** @var \phpbb\language\language */ protected $language; - function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) + public function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\log\log $log, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) { $this->language = $language; $this->log = $log; $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; parent::__construct($user, $migrator, $extension_manager, $config, $cache); - $this->user->add_lang(array('common', 'install', 'migrator')); + $this->language->add_lang(array('common', 'install', 'migrator')); } protected function configure() { $this ->setName('db:migrate') - ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_MIGRATE')) + ->setDescription($this->language->lang('CLI_DESCRIPTION_DB_MIGRATE')) ; } diff --git a/phpBB/phpbb/console/command/db/migration_command.php b/phpBB/phpbb/console/command/db/migration_command.php index b951560588..851f404fab 100644 --- a/phpBB/phpbb/console/command/db/migration_command.php +++ b/phpBB/phpbb/console/command/db/migration_command.php @@ -26,7 +26,7 @@ abstract class migration_command extends \phpbb\console\command\command /** @var \phpbb\cache\service */ protected $cache; - function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache) + public function __construct(\phpbb\user $user, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache) { $this->migrator = $migrator; $this->extension_manager = $extension_manager; diff --git a/phpBB/phpbb/console/command/db/revert.php b/phpBB/phpbb/console/command/db/revert.php index 7977afc319..3c79d8c554 100644 --- a/phpBB/phpbb/console/command/db/revert.php +++ b/phpBB/phpbb/console/command/db/revert.php @@ -18,35 +18,17 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class revert extends \phpbb\console\command\db\migration_command +class revert extends \phpbb\console\command\db\migrate { - /** @var string phpBB root path */ - protected $phpbb_root_path; - - /** @var \phpbb\filesystem\filesystem_interface */ - protected $filesystem; - - /** @var \phpbb\language\language */ - protected $language; - - function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\db\migrator $migrator, \phpbb\extension\manager $extension_manager, \phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\filesystem\filesystem_interface $filesystem, $phpbb_root_path) - { - $this->filesystem = $filesystem; - $this->language = $language; - $this->phpbb_root_path = $phpbb_root_path; - parent::__construct($user, $migrator, $extension_manager, $config, $cache); - $this->user->add_lang(array('common', 'migrator')); - } - protected function configure() { $this ->setName('db:revert') - ->setDescription($this->user->lang('CLI_DESCRIPTION_DB_REVERT')) + ->setDescription($this->language->lang('CLI_DESCRIPTION_DB_REVERT')) ->addArgument( 'name', InputArgument::REQUIRED, - $this->user->lang('CLI_MIGRATION_NAME') + $this->language->lang('CLI_MIGRATION_NAME') ) ; } diff --git a/phpBB/phpbb/console/command/dev/migration_tips.php b/phpBB/phpbb/console/command/dev/migration_tips.php index f9047bdac8..2ca0ddde2f 100644 --- a/phpBB/phpbb/console/command/dev/migration_tips.php +++ b/phpBB/phpbb/console/command/dev/migration_tips.php @@ -20,7 +20,7 @@ class migration_tips extends \phpbb\console\command\command /** @var \phpbb\extension\manager */ protected $extension_manager; - function __construct(\phpbb\user $user, \phpbb\extension\manager $extension_manager) + public function __construct(\phpbb\user $user, \phpbb\extension\manager $extension_manager) { $this->extension_manager = $extension_manager; parent::__construct($user); diff --git a/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php b/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php index 043f181e72..6f7096296d 100644 --- a/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php +++ b/phpBB/phpbb/console/command/fixup/recalculate_email_hash.php @@ -21,7 +21,7 @@ class recalculate_email_hash extends \phpbb\console\command\command /** @var \phpbb\db\driver\driver_interface */ protected $db; - function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db) + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db) { $this->db = $db; -- cgit v1.2.1 From 6a5b99b12b1812202843613994480cc6caf93354 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 8 Dec 2016 16:49:50 -0800 Subject: [ticket/14895] Fix broken tests PHPBB3-14895 --- phpBB/phpbb/console/command/cron/cron_list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/cron/cron_list.php b/phpBB/phpbb/console/command/cron/cron_list.php index 8f9d63eda2..ea61e45235 100644 --- a/phpBB/phpbb/console/command/cron/cron_list.php +++ b/phpBB/phpbb/console/command/cron/cron_list.php @@ -81,13 +81,13 @@ class cron_list extends \phpbb\console\command\command if (!empty($ready_tasks)) { - $io->section($this->user->lang('TASKS_READY')); + $io->title($this->user->lang('TASKS_READY')); $io->listing($ready_tasks); } if (!empty($not_ready_tasks)) { - $io->section($this->user->lang('TASKS_NOT_READY')); + $io->title($this->user->lang('TASKS_NOT_READY')); $io->listing($not_ready_tasks); } } -- cgit v1.2.1 From b4748a5d1ee31084da7e78f8ffaf5b036f2e5314 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 18 Dec 2016 01:28:51 -0800 Subject: [ticket/14925] Set reparser names in service definitions PHPBB3-14925 --- phpBB/phpbb/console/command/reparser/list_all.php | 4 ++-- phpBB/phpbb/console/command/reparser/reparse.php | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/reparser/list_all.php b/phpBB/phpbb/console/command/reparser/list_all.php index 028468649d..a79578abf0 100644 --- a/phpBB/phpbb/console/command/reparser/list_all.php +++ b/phpBB/phpbb/console/command/reparser/list_all.php @@ -34,10 +34,10 @@ class list_all extends \phpbb\console\command\command { parent::__construct($user); $this->reparser_names = array(); - foreach ($reparsers as $name => $reparser) + foreach ($reparsers as $reparser) { // Store the names without the "text_reparser." prefix - $this->reparser_names[] = preg_replace('(^text_reparser\\.)', '', $name); + $this->reparser_names[] = $reparser->get_name(); } } diff --git a/phpBB/phpbb/console/command/reparser/reparse.php b/phpBB/phpbb/console/command/reparser/reparse.php index cebeee0919..f285977ea2 100644 --- a/phpBB/phpbb/console/command/reparser/reparse.php +++ b/phpBB/phpbb/console/command/reparser/reparse.php @@ -140,13 +140,9 @@ class reparse extends \phpbb\console\command\command } $name = $input->getArgument('reparser-name'); - if (isset($name)) + if ($name) { - // Allow "post_text" to be an alias for "text_reparser.post_text" - if (!isset($this->reparsers[$name])) - { - $name = 'text_reparser.' . $name; - } + $name = $this->reparser_manager->find_reparser($name); $this->reparse($name); } else @@ -187,7 +183,7 @@ class reparse extends \phpbb\console\command\command /** * Reparse all text handled by given reparser within given range * - * @param string $name Reparser name + * @param string $name Reparser service name */ protected function reparse($name) { @@ -218,10 +214,10 @@ class reparse extends \phpbb\console\command\command return; } - $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max)); + $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max)); $progress = $this->create_progress_bar($max, $this->io, $this->output, true); - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name))); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name())); $progress->start(); // Start from $max and decrement $current by $size until we reach $min @@ -231,7 +227,7 @@ class reparse extends \phpbb\console\command\command $start = max($min, $current + 1 - $size); $end = max($min, $current); - $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $start, $end)); + $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end)); $reparser->reparse_range($start, $end); $current = $start - 1; -- cgit v1.2.1 From 2e3d90e05b7b08f6df89b9e3a98b1716d52cf340 Mon Sep 17 00:00:00 2001 From: javiexin Date: Sun, 12 Feb 2017 18:33:06 +0100 Subject: [ticket/15087] Optimize creation of metadata objects by caching Caching is done in ext_manager, and metadata_manager is further simplified by reducing the number of parameters needed. Also, move template output function from metadata_manager to acp_extensions, where it belongs. PHPBB3-15087 --- phpBB/phpbb/console/command/update/check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index 1f1cfa25d2..ed8ad79eea 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -134,7 +134,7 @@ class check extends \phpbb\console\command\command try { $ext_manager = $this->phpbb_container->get('ext.manager'); - $md_manager = $ext_manager->create_extension_metadata_manager($ext_name, null); + $md_manager = $ext_manager->create_extension_metadata_manager($ext_name); $updates_available = $ext_manager->version_check($md_manager, $recheck, false, $stability); $metadata = $md_manager->get_metadata('all'); -- cgit v1.2.1 From 891aab05935e9ebc237a83cef0b248998cb5fccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 11 Mar 2017 20:34:40 +0100 Subject: [ticket/15123] add check before enable or disable extension PHPBB3-15123 --- phpBB/phpbb/console/command/extension/disable.php | 7 +++++++ phpBB/phpbb/console/command/extension/enable.php | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index d022755753..be5c77a9a0 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -37,6 +37,13 @@ class disable extends command $io = new SymfonyStyle($input, $output); $name = $input->getArgument('extension-name'); + + if (!$this->manager->is_enabled($name)) + { + $io->error($this->user->lang('CLI_EXTENSION_ALREADY_DISABLED', $name)); + return 1; + } + $this->manager->disable($name); $this->manager->load_extensions(); diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index 14077d688b..2de7498c71 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -37,6 +37,13 @@ class enable extends command $io = new SymfonyStyle($input, $output); $name = $input->getArgument('extension-name'); + + if ($this->manager->is_enabled($name)) + { + $io->error($this->user->lang('CLI_EXTENSION_ALREADY_ENABLED', $name)); + return 1; + } + $this->manager->enable($name); $this->manager->load_extensions(); -- cgit v1.2.1 From 68c167fe7a5f0c86d97c9c3dda30f66d9df5b032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 11 Mar 2017 20:39:16 +0100 Subject: [ticket/15123] removed blank spaces PHPBB3-15123 --- phpBB/phpbb/console/command/extension/disable.php | 2 +- phpBB/phpbb/console/command/extension/enable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index be5c77a9a0..323f9b6d83 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -43,7 +43,7 @@ class disable extends command $io->error($this->user->lang('CLI_EXTENSION_ALREADY_DISABLED', $name)); return 1; } - + $this->manager->disable($name); $this->manager->load_extensions(); diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index 2de7498c71..e6b5f66c7f 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -43,7 +43,7 @@ class enable extends command $io->error($this->user->lang('CLI_EXTENSION_ALREADY_ENABLED', $name)); return 1; } - + $this->manager->enable($name); $this->manager->load_extensions(); -- cgit v1.2.1 From 8994295f2b7d5b2beece7bbd8f7a2861fa15625d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 11 Mar 2017 23:03:31 +0100 Subject: [ticket/15123] modified language string PHPBB3-15123 --- phpBB/phpbb/console/command/extension/disable.php | 2 +- phpBB/phpbb/console/command/extension/enable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index 323f9b6d83..05f7ce9704 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -40,7 +40,7 @@ class disable extends command if (!$this->manager->is_enabled($name)) { - $io->error($this->user->lang('CLI_EXTENSION_ALREADY_DISABLED', $name)); + $io->error($this->user->lang('CLI_EXTENSION_DISABLE_DISABLED', $name)); return 1; } diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index e6b5f66c7f..c7c336cdc9 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -40,7 +40,7 @@ class enable extends command if ($this->manager->is_enabled($name)) { - $io->error($this->user->lang('CLI_EXTENSION_ALREADY_ENABLED', $name)); + $io->error($this->user->lang('CLI_EXTENSION_ENABLE_ENABLED', $name)); return 1; } -- cgit v1.2.1 From 9b3609d6f60af328e6681146014453da0af4ee01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sun, 12 Mar 2017 22:44:18 +0100 Subject: [ticket/15123] modified language strings PHPBB3-15123 --- phpBB/phpbb/console/command/extension/disable.php | 2 +- phpBB/phpbb/console/command/extension/enable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index 05f7ce9704..12674c16cb 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -40,7 +40,7 @@ class disable extends command if (!$this->manager->is_enabled($name)) { - $io->error($this->user->lang('CLI_EXTENSION_DISABLE_DISABLED', $name)); + $io->error($this->user->lang('CLI_EXTENSION_DISABLED', $name)); return 1; } diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index c7c336cdc9..079e4ce1f6 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -40,7 +40,7 @@ class enable extends command if ($this->manager->is_enabled($name)) { - $io->error($this->user->lang('CLI_EXTENSION_ENABLE_ENABLED', $name)); + $io->error($this->user->lang('CLI_EXTENSION_ENABLED', $name)); return 1; } -- cgit v1.2.1 From 45f0adcd0a4e6c7e43183fe641fa03ef2d90d45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sun, 12 Mar 2017 22:45:33 +0100 Subject: [ticket/15123] modified return error codes PHPBB3-15123 --- phpBB/phpbb/console/command/extension/disable.php | 2 +- phpBB/phpbb/console/command/extension/enable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/disable.php b/phpBB/phpbb/console/command/extension/disable.php index 12674c16cb..b2e10fb960 100644 --- a/phpBB/phpbb/console/command/extension/disable.php +++ b/phpBB/phpbb/console/command/extension/disable.php @@ -41,7 +41,7 @@ class disable extends command if (!$this->manager->is_enabled($name)) { $io->error($this->user->lang('CLI_EXTENSION_DISABLED', $name)); - return 1; + return 2; } $this->manager->disable($name); diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index 079e4ce1f6..a8312d5c15 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -41,7 +41,7 @@ class enable extends command if ($this->manager->is_enabled($name)) { $io->error($this->user->lang('CLI_EXTENSION_ENABLED', $name)); - return 1; + return 2; } $this->manager->enable($name); -- cgit v1.2.1 From e2c0356f34bed706ca1dcf8fc0844109d764b935 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 3 Jun 2017 10:01:28 +0200 Subject: [ticket/15179] Replace spaces with a tab PHPBB3-15179 --- phpBB/phpbb/console/command/update/check.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/update/check.php b/phpBB/phpbb/console/command/update/check.php index ed8ad79eea..9ced651e8b 100644 --- a/phpBB/phpbb/console/command/update/check.php +++ b/phpBB/phpbb/console/command/update/check.php @@ -325,7 +325,7 @@ class check extends \phpbb\console\command\command $io->table([ $this->language->lang('VERSION'), $this->language->lang('ANNOUNCEMENT_TOPIC'), - $this->language->lang('DOWNLOAD_LATEST'), + $this->language->lang('DOWNLOAD_LATEST'), ], $rows); } } -- cgit v1.2.1 From 8a8d435ed4c065084fc35e48e8926b5e0ffb2ccc Mon Sep 17 00:00:00 2001 From: rxu Date: Fri, 26 May 2017 20:36:32 +0700 Subject: [ticket/15238] Add console command to fix forums/modules left/right IDs PHPBB3-15238 --- .../console/command/fixup/fix_left_right_ids.php | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 phpBB/phpbb/console/command/fixup/fix_left_right_ids.php (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php new file mode 100644 index 0000000000..7b932fa179 --- /dev/null +++ b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php @@ -0,0 +1,108 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +namespace phpbb\console\command\fixup; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; + +class fix_left_right_ids extends \phpbb\console\command\command +{ + /** @var \phpbb\user */ + protected $user; + + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\cache\driver\driver_interface */ + protected $cache; + + public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache) + { + $this->user = $user; + $this->db = $db; + $this->cache = $cache; + + parent::__construct($user); + } + + protected function configure() + { + $this + ->setName('fixup:fix-left-right-ids') + ->setDescription($this->user->lang('CLI_DESCRIPTION_FIX_LEFT_RIGHT_IDS')) + ; + } + + /** + * The code is mainly borrowed from Support toolkit for phpBB Olympus + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new SymfonyStyle($input, $output); + + $changes_made = false; + + // Fix Left/Right IDs for the modules table + $result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE); + while ($row = $this->db->sql_fetchrow($result)) + { + $i = 1; + $where = array('module_class = \'' . $row['module_class'] .'\''); + $changes_made = (($this->fixem($i, 'module_id', MODULES_TABLE, 0, $where)) || $changes_made) ? true : false; + } + $this->db->sql_freeresult($result); + + // Fix the Left/Right IDs for the forums table + $i = 1; + $changes_made = (($this->fixem($i, 'forum_id', FORUMS_TABLE)) || $changes_made) ? true : false; + + $this->cache->purge(); + + $io->success($this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS')); + } + + function fixem(&$i, $pkey, $table, $parent_id = 0, $where = array()) + { + $changes_made = false; + $sql = 'SELECT * FROM ' . $table . ' + WHERE parent_id = ' . (int) $parent_id . + ((!empty($where)) ? ' AND ' . implode(' AND ', $where) : '') . ' + ORDER BY left_id ASC'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Update the left_id for this module + if ($row['left_id'] != $i) + { + $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $pkey = {$row[$pkey]}"); + $changes_made = true; + } + $i++; + + // Go through children and update their left/right IDs + $changes_made = (($this->fixem($i, $pkey, $table, $row[$pkey], $where)) || $changes_made) ? true : false; + + // Update the right_id for the module + if ($row['right_id'] != $i) + { + $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $pkey = {$row[$pkey]}"); + $changes_made = true; + } + $i++; + } + $this->db->sql_freeresult($result); + + return $changes_made; + } +} -- cgit v1.2.1 From b0ed1f2388be4246ceddb2f9ec4c10963a18c073 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 6 Jun 2017 00:42:05 +0700 Subject: [ticket/15238] Code cleanup, add docblocks PHPBB3-15238 --- .../console/command/fixup/fix_left_right_ids.php | 50 +++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php index 7b932fa179..601a27118b 100644 --- a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php +++ b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php @@ -27,6 +27,13 @@ class fix_left_right_ids extends \phpbb\console\command\command /** @var \phpbb\cache\driver\driver_interface */ protected $cache; + /** + * Constructor + * + * @param \phpbb\user $user User instance + * @param \phpbb\db\driver\driver_interface $db Database connection + * @param \phpbb\cache\driver\driver_interface $cache Cache instance + */ public function __construct(\phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache) { $this->user = $user; @@ -36,6 +43,9 @@ class fix_left_right_ids extends \phpbb\console\command\command parent::__construct($user); } + /** + * {@inheritdoc} + */ protected function configure() { $this @@ -45,34 +55,52 @@ class fix_left_right_ids extends \phpbb\console\command\command } /** + * Executes the command fixup:fix-left-right-ids. + * + * Repairs the tree structure of the forums and modules. * The code is mainly borrowed from Support toolkit for phpBB Olympus + * + * @param InputInterface $input An InputInterface instance + * @param OutputInterface $output An OutputInterface instance + * + * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); - $changes_made = false; - // Fix Left/Right IDs for the modules table $result = $this->db->sql_query('SELECT DISTINCT(module_class) FROM ' . MODULES_TABLE); while ($row = $this->db->sql_fetchrow($result)) { $i = 1; - $where = array('module_class = \'' . $row['module_class'] .'\''); - $changes_made = (($this->fixem($i, 'module_id', MODULES_TABLE, 0, $where)) || $changes_made) ? true : false; + $where = array("module_class = '" . $this->db->sql_escape($row['module_class']) . "'"); + $this->fix_ids_tree($i, 'module_id', MODULES_TABLE, 0, $where); } $this->db->sql_freeresult($result); // Fix the Left/Right IDs for the forums table $i = 1; - $changes_made = (($this->fixem($i, 'forum_id', FORUMS_TABLE)) || $changes_made) ? true : false; + $this->fix_ids_tree($i, 'forum_id', FORUMS_TABLE); $this->cache->purge(); $io->success($this->user->lang('CLI_FIXUP_FIX_LEFT_RIGHT_IDS_SUCCESS')); } - function fixem(&$i, $pkey, $table, $parent_id = 0, $where = array()) + /** + * Item's tree structure rebuild helper + * The item is either forum or ACP/MCP/UCP module + * + * @param int $i Item id offset index + * @param string $field The key field to fix, forum_id|module_id + * @param string $table The table name to perform, FORUMS_TABLE|MODULES_TABLE + * @param int $parent_id Parent item id + * @param string $where Additional WHERE clause condition + * + * @return bool True on rebuild success, false otherwise + */ + function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array()) { $changes_made = false; $sql = 'SELECT * FROM ' . $table . ' @@ -82,21 +110,21 @@ class fix_left_right_ids extends \phpbb\console\command\command $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - // Update the left_id for this module + // Update the left_id for the item if ($row['left_id'] != $i) { - $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $pkey = {$row[$pkey]}"); + $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . " WHERE $field = " . (int) $row[$field]); $changes_made = true; } $i++; // Go through children and update their left/right IDs - $changes_made = (($this->fixem($i, $pkey, $table, $row[$pkey], $where)) || $changes_made) ? true : false; + $changes_made = (($this->fix_ids_tree($i, $field, $table, $row[$field], $where)) || $changes_made) ? true : false; - // Update the right_id for the module + // Update the right_id for the item if ($row['right_id'] != $i) { - $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $pkey = {$row[$pkey]}"); + $this->db->sql_query('UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . " WHERE $field = " . (int) $row[$field]); $changes_made = true; } $i++; -- cgit v1.2.1 From 7f08d46aa4888cba48317bf0a8175b399039aff6 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 18 Jun 2017 22:00:18 +0700 Subject: [ticket/15238] More code cleanup PHPBB3-15238 --- phpBB/phpbb/console/command/fixup/fix_left_right_ids.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php index 601a27118b..656011e4a6 100644 --- a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php +++ b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php @@ -10,6 +10,7 @@ * the docs/CREDITS.txt file. * */ + namespace phpbb\console\command\fixup; use Symfony\Component\Console\Input\InputInterface; @@ -96,7 +97,7 @@ class fix_left_right_ids extends \phpbb\console\command\command * @param string $field The key field to fix, forum_id|module_id * @param string $table The table name to perform, FORUMS_TABLE|MODULES_TABLE * @param int $parent_id Parent item id - * @param string $where Additional WHERE clause condition + * @param array $where Additional WHERE clause condition * * @return bool True on rebuild success, false otherwise */ -- cgit v1.2.1 From f3403fb10d7225d9aed121f17d1355b04fb0899e Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 20 Jun 2017 21:07:11 +0700 Subject: [ticket/15238] Add missing protected keyword PHPBB3-15238 --- phpBB/phpbb/console/command/fixup/fix_left_right_ids.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php index 656011e4a6..271b099a6c 100644 --- a/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php +++ b/phpBB/phpbb/console/command/fixup/fix_left_right_ids.php @@ -101,7 +101,7 @@ class fix_left_right_ids extends \phpbb\console\command\command * * @return bool True on rebuild success, false otherwise */ - function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array()) + protected function fix_ids_tree(&$i, $field, $table, $parent_id = 0, $where = array()) { $changes_made = false; $sql = 'SELECT * FROM ' . $table . ' -- cgit v1.2.1 From aa23af38d4d3a13918e859005277955debd76acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 12:53:44 +0200 Subject: [ticket/15349] Check if extension is enableable before enable PHPBB3-15346 --- phpBB/phpbb/console/command/extension/enable.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index a8312d5c15..b35fb9c4c6 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -37,6 +37,13 @@ class enable extends command $io = new SymfonyStyle($input, $output); $name = $input->getArgument('extension-name'); + $extension = $this->manager->get_extension($name); + + if (!$extension->is_enableable()) + { + $io->error($this->user->lang('CLI_EXTENSION_NOT_ENABLEABLE', $name)); + return 1; + } if ($this->manager->is_enabled($name)) { -- cgit v1.2.1 From bf289de26f137bfe50608b6f9c549b306ede5b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 12:54:13 +0200 Subject: [ticket/15349] Return 1 instead of 2 in case of error PHPBB3-15346 --- phpBB/phpbb/console/command/extension/enable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command') diff --git a/phpBB/phpbb/console/command/extension/enable.php b/phpBB/phpbb/console/command/extension/enable.php index b35fb9c4c6..f92de0069c 100644 --- a/phpBB/phpbb/console/command/extension/enable.php +++ b/phpBB/phpbb/console/command/extension/enable.php @@ -48,7 +48,7 @@ class enable extends command if ($this->manager->is_enabled($name)) { $io->error($this->user->lang('CLI_EXTENSION_ENABLED', $name)); - return 2; + return 1; } $this->manager->enable($name); -- cgit v1.2.1