aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/language/en/cli.php3
-rw-r--r--phpBB/phpbb/console/command/user/reclean.php76
2 files changed, 76 insertions, 3 deletions
diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php
index 872aa464b5..db4b5f9ec6 100644
--- a/phpBB/language/en/cli.php
+++ b/phpBB/language/en/cli.php
@@ -136,7 +136,8 @@ $lang = array_merge($lang, array(
'CLI_USER_ADD_SUCCESS' => 'Successfully added user %s.',
'CLI_USER_DELETE_CONFIRM' => 'Are you sure you want to delete ā€˜%sā€™? [y/N]',
- 'CLI_USER_RECLEAN_SUCCESS' => [
+ 'CLI_USER_RECLEAN_START' => 'Re-cleaning usernames',
+ 'CLI_USER_RECLEAN_DONE' => [
0 => 'Re-cleaning complete. No usernames needed to be cleaned.',
1 => 'Re-cleaning complete. %d username was cleaned.',
2 => 'Re-cleaning complete. %d usernames were cleaned.',
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('<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% %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;
+ }
}