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 /phpBB/phpbb/console | |
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
Diffstat (limited to 'phpBB/phpbb/console')
-rw-r--r-- | phpBB/phpbb/console/command/user/activate.php | 31 | ||||
-rw-r--r-- | phpBB/phpbb/console/command/user/delete.php | 31 |
2 files changed, 22 insertions, 40 deletions
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; - } } |