diff options
author | Matt Friedman <maf675@gmail.com> | 2016-03-27 10:24:12 -0700 |
---|---|---|
committer | Matt Friedman <maf675@gmail.com> | 2016-03-31 15:07:59 -0700 |
commit | 4b789c041844396f3a5e6a51142c45c13d2edd59 (patch) | |
tree | c28e306305753d1284a1f4bc2be45a7a58971dda | |
parent | ed0f151d863d7449d73336b3697e37259812215e (diff) | |
download | forums-4b789c041844396f3a5e6a51142c45c13d2edd59.tar forums-4b789c041844396f3a5e6a51142c45c13d2edd59.tar.gz forums-4b789c041844396f3a5e6a51142c45c13d2edd59.tar.bz2 forums-4b789c041844396f3a5e6a51142c45c13d2edd59.tar.xz forums-4b789c041844396f3a5e6a51142c45c13d2edd59.zip |
[ticket/14561] Use the user loader where appropriate
PHPBB3-14561
-rw-r--r-- | phpBB/config/default/container/services_console.yml | 2 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/user/activate.php | 31 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/user/delete.php | 31 | ||||
-rw-r--r-- | tests/console/user/activate_test.php | 1 | ||||
-rw-r--r-- | tests/console/user/base.php | 3 | ||||
-rw-r--r-- | tests/console/user/delete_test.php | 1 |
6 files changed, 29 insertions, 40 deletions
diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml index 994ac55ee9..3f27ee666a 100644 --- a/phpBB/config/default/container/services_console.yml +++ b/phpBB/config/default/container/services_console.yml @@ -229,6 +229,7 @@ services: - '@language' - '@log' - '@notification_manager' + - '@user_loader' - '%core.root_path%' - '%core.php_ext%' tags: @@ -254,6 +255,7 @@ services: - '@dbal.conn' - '@language' - '@log' + - '@user_loader' - '%core.root_path%' - '%core.php_ext%' tags: 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; - } } diff --git a/tests/console/user/activate_test.php b/tests/console/user/activate_test.php index 08b25c6c95..1588a76e47 100644 --- a/tests/console/user/activate_test.php +++ b/tests/console/user/activate_test.php @@ -40,6 +40,7 @@ class phpbb_console_user_activate_test extends phpbb_console_user_base $this->language, $this->log, $this->notifications, + $this->user_loader, $this->phpbb_root_path, $this->php_ext )); diff --git a/tests/console/user/base.php b/tests/console/user/base.php index c6ffc428ed..7ff11af1ae 100644 --- a/tests/console/user/base.php +++ b/tests/console/user/base.php @@ -25,6 +25,7 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case protected $passwords_manager; protected $command_name; protected $question; + protected $user_loader; protected $phpbb_root_path; protected $php_ext; @@ -70,6 +71,8 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case '\phpbb\datetime' )); + $this->user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); + $driver_helper = new \phpbb\passwords\driver\helper($this->config); $passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($this->config, $driver_helper), diff --git a/tests/console/user/delete_test.php b/tests/console/user/delete_test.php index dc4c07e8b8..88f91afab1 100644 --- a/tests/console/user/delete_test.php +++ b/tests/console/user/delete_test.php @@ -27,6 +27,7 @@ class phpbb_console_user_delete_test extends phpbb_console_user_base $this->db, $this->language, $this->log, + $this->user_loader, $this->phpbb_root_path, $this->php_ext )); |