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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user') 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/user/reclean.php | 40 ---------------------------- 1 file changed, 40 deletions(-) (limited to 'phpBB/phpbb/console/command/user') 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