mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/12684] Updates for 3.2 API
PHPBB3-12684
This commit is contained in:
parent
d17a8ab523
commit
6fe084a2fd
4 changed files with 49 additions and 16 deletions
|
@ -182,6 +182,8 @@ services:
|
|||
- '@dbal.conn'
|
||||
- '@config'
|
||||
- '@passwords.manager'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ $lang = array_merge($lang, array(
|
|||
'CLI_DESCRIPTION_THUMBNAIL_GENERATE' => 'Generate all missing thumbnails.',
|
||||
'CLI_DESCRIPTION_THUMBNAIL_RECREATE' => 'Recreate all thumbnails.',
|
||||
|
||||
'CLI_DESCRIPTION_USER_ADD' => 'Add a new user',
|
||||
'CLI_DESCRIPTION_USER_ADD' => 'Add a new user.',
|
||||
'CLI_DESCRIPTION_USER_ADD_OPTION_USERNAME' => 'Username of the new user',
|
||||
'CLI_DESCRIPTION_USER_ADD_OPTION_PASSWORD' => 'Password of the new user',
|
||||
'CLI_DESCRIPTION_USER_ADD_OPTION_EMAIL' => 'E-mail address of the new user',
|
||||
|
|
|
@ -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('<info>' . $this->user->lang('SUCCESS_ADD_USER', $username) . '</info>');
|
||||
$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'];
|
||||
|
|
|
@ -27,6 +27,8 @@ class phpbb_console_command_user_add_test extends phpbb_database_test_case
|
|||
protected $passwords_manager;
|
||||
protected $command_name;
|
||||
protected $dialog;
|
||||
protected $phpbb_root_path;
|
||||
protected $php_ext;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
|
@ -35,22 +37,26 @@ class phpbb_console_command_user_add_test extends phpbb_database_test_case
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
global $db, $config, $phpbb_dispatcher, $phpbb_container;
|
||||
global $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx;
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('cache.driver', new phpbb_mock_cache());
|
||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||
|
||||
$cache = $phpbb_container->get('cache.driver');
|
||||
|
||||
$config = $this->config = new \phpbb\config\config(array(
|
||||
'board_timezone' => 'UTC',
|
||||
'default_lang' => 'en',
|
||||
));
|
||||
set_config(null, null, null, $this->config);
|
||||
set_config_count(null, null, null, $this->config);
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
|
||||
$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
|
||||
$user = $this->user = $this->getMock('\phpbb\user', array(), array(
|
||||
new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
|
||||
'\phpbb\datetime')
|
||||
);
|
||||
$this->user->method('lang')->will($this->returnArgument(0));
|
||||
|
||||
$driver_helper = new \phpbb\passwords\driver\helper($this->config);
|
||||
|
@ -64,6 +70,9 @@ class phpbb_console_command_user_add_test extends phpbb_database_test_case
|
|||
$passwords_helper = new \phpbb\passwords\helper;
|
||||
$this->passwords_manager = new \phpbb\passwords\manager($this->config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $phpEx;
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
@ -104,7 +113,7 @@ class phpbb_console_command_user_add_test extends phpbb_database_test_case
|
|||
public function get_command_tester()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new add($this->user, $this->db, $this->config, $this->passwords_manager));
|
||||
$application->add(new add($this->user, $this->db, $this->config, $this->passwords_manager, $this->phpbb_root_path, $this->php_ext));
|
||||
|
||||
$command = $application->find('user:add');
|
||||
$this->command_name = $command->getName();
|
||||
|
|
Loading…
Add table
Reference in a new issue