diff options
author | Marc Alexander <admin@m-a-styles.de> | 2016-04-23 23:04:05 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2016-04-23 23:04:05 +0200 |
commit | ead261e6dba4d470160c6a31f95430b4053c0d54 (patch) | |
tree | c0eedf387f538cbe991da6ba36b5c61055122146 | |
parent | 29bb1ab72d68ff9a19cb3e1d99d4a4a9060e55a1 (diff) | |
parent | d713ce94ff218c2464823cb23dae1007354c60f3 (diff) | |
download | forums-ead261e6dba4d470160c6a31f95430b4053c0d54.tar forums-ead261e6dba4d470160c6a31f95430b4053c0d54.tar.gz forums-ead261e6dba4d470160c6a31f95430b4053c0d54.tar.bz2 forums-ead261e6dba4d470160c6a31f95430b4053c0d54.tar.xz forums-ead261e6dba4d470160c6a31f95430b4053c0d54.zip |
Merge pull request #4286 from VSEphpbb/ticket/14569
[ticket/14569] Extract CLI progress bar creation to a method
-rw-r--r-- | phpBB/phpbb/console/command/command.php | 45 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/reparser/reparse.php | 40 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/thumbnail/delete.php | 27 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/thumbnail/generate.php | 27 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/user/reclean.php | 40 |
5 files changed, 48 insertions, 131 deletions
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('<info>[%percent:3s%%]</info> %message%'); + $progress->setOverwrite(false); + } + else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) + { + $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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 @@ -122,44 +122,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('<info>[%percent:3s%%]</info> %message%'); - $progress->setOverwrite(false); - } - else if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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 * * @param InputInterface $input @@ -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('<info>[%percent:3s%%]</info> %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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('<info>[%percent:3s%%]</info> %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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 @@ -142,46 +142,6 @@ class reclean extends command } /** - * 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('<info>[%percent:3s%%]</info> %message%'); - $progress->setOverwrite(false); - } - else if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) - { - $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %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 * * @return int |