aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Friedman <maf675@gmail.com>2016-02-29 11:38:49 -0800
committerMatt Friedman <maf675@gmail.com>2016-02-29 11:41:07 -0800
commit6fe084a2fd967c188bdca827a46647120a5ea58d (patch)
tree3479fea79ef9f71173f7b64b01179804fa9ab0c3
parentd17a8ab523f5cc77352170c679767c5523f57ec9 (diff)
downloadforums-6fe084a2fd967c188bdca827a46647120a5ea58d.tar
forums-6fe084a2fd967c188bdca827a46647120a5ea58d.tar.gz
forums-6fe084a2fd967c188bdca827a46647120a5ea58d.tar.bz2
forums-6fe084a2fd967c188bdca827a46647120a5ea58d.tar.xz
forums-6fe084a2fd967c188bdca827a46647120a5ea58d.zip
[ticket/12684] Updates for 3.2 API
PHPBB3-12684
-rw-r--r--phpBB/config/default/container/services_console.yml2
-rw-r--r--phpBB/language/en/cli.php2
-rw-r--r--phpBB/phpbb/console/command/user/add.php42
-rw-r--r--tests/console/user/add_test.php19
4 files changed, 49 insertions, 16 deletions
diff --git a/phpBB/config/default/container/services_console.yml b/phpBB/config/default/container/services_console.yml
index b39353d841..006df0d7b3 100644
--- a/phpBB/config/default/container/services_console.yml
+++ b/phpBB/config/default/container/services_console.yml
@@ -182,6 +182,8 @@ services:
- '@dbal.conn'
- '@config'
- '@passwords.manager'
+ - '%core.root_path%'
+ - '%core.php_ext%'
tags:
- { name: console.command }
diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php
index 9a082b0c57..4c0fbde286 100644
--- a/phpBB/language/en/cli.php
+++ b/phpBB/language/en/cli.php
@@ -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',
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
{
@@ -29,18 +31,35 @@ class add extends \phpbb\console\command\command
protected $password_manager;
/**
+ * phpBB root path
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * 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)
+ 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'];
diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php
index 6f80a8658a..5e4b76063e 100644
--- a/tests/console/user/add_test.php
+++ b/tests/console/user/add_test.php
@@ -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();