aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/console/command
diff options
context:
space:
mode:
authorTristan Darricau <tristan.darricau@sensiolabs.com>2015-05-31 17:19:42 +0200
committerMate Bartus <mate.bartus@gmail.com>2015-07-08 01:28:08 +0200
commit06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3 (patch)
tree23923bb100b08fe4a0e30c5a98cccad8f6148f42 /phpBB/phpbb/install/console/command
parent524b98e7bd19bff7b12c7ba4c771d6d60d4300a6 (diff)
downloadforums-06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3.tar
forums-06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3.tar.gz
forums-06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3.tar.bz2
forums-06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3.tar.xz
forums-06f4ebce1b1cc8ecd5ddd84f7d2705007a685de3.zip
[ticket/13740] CLI installer and fixes
[ci skip] PHPBB3-13740
Diffstat (limited to 'phpBB/phpbb/install/console/command')
-rw-r--r--phpBB/phpbb/install/console/command/install/config/default_config.php103
-rw-r--r--phpBB/phpbb/install/console/command/install/config/show.php131
-rw-r--r--phpBB/phpbb/install/console/command/install/config/validate.php132
-rw-r--r--phpBB/phpbb/install/console/command/install/install.php194
4 files changed, 560 insertions, 0 deletions
diff --git a/phpBB/phpbb/install/console/command/install/config/default_config.php b/phpBB/phpbb/install/console/command/install/config/default_config.php
new file mode 100644
index 0000000000..75c9f94901
--- /dev/null
+++ b/phpBB/phpbb/install/console/command/install/config/default_config.php
@@ -0,0 +1,103 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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\install\console\command\install\config;
+
+use phpbb\language\language;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Yaml\Yaml;
+
+class default_config extends \phpbb\console\command\command
+{
+ /**
+ * @var language
+ */
+ protected $language;
+
+ /**
+ * Constructor
+ *
+ * @param language $language
+ */
+ public function __construct(language $language)
+ {
+ $this->language = $language;
+
+ parent::__construct(new \phpbb\user($language, 'datetime'));
+ }
+
+ /**
+ *
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('install:config:default')
+ ;
+ }
+
+ /**
+ * Display the default configuration
+ *
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ *
+ * @return null
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $default_config = <<<EOL
+installer:
+ admin:
+ name: admin
+ password: adminadmin
+ email: admin@example.org
+
+ board:
+ lang: en
+ name: My Board
+ description: My amazing new phpBB board
+
+ database:
+ dbms: sqlite3
+ dbhost: ~
+ dbport: ~
+ dbuser: ~
+ dbpasswd: ~
+ dbname: ~
+ table_prefix: phpbb_
+
+ email:
+ enabled: false
+ smtp_delivery : ~
+ smtp_host: ~
+ smtp_auth: ~
+ smtp_user: ~
+ smtp_pass: ~
+
+ server:
+ cookie_secure: false
+ server_protocol: http://
+ force_server_vars: false
+ server_name: localhost
+ server_port: 80
+ script_path: /
+EOL;
+
+ $default_config = Yaml::parse($default_config);
+ $default_config = Yaml::dump($default_config, 10);
+ $output->writeln($default_config);
+ }
+}
diff --git a/phpBB/phpbb/install/console/command/install/config/show.php b/phpBB/phpbb/install/console/command/install/config/show.php
new file mode 100644
index 0000000000..4155440fc3
--- /dev/null
+++ b/phpBB/phpbb/install/console/command/install/config/show.php
@@ -0,0 +1,131 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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\install\console\command\install\config;
+
+use phpbb\install\helper\iohandler\factory;
+use phpbb\install\installer;
+use phpbb\install\installer_configuration;
+use phpbb\language\language;
+use Symfony\Component\Config\Definition\Exception\Exception;
+use Symfony\Component\Config\Definition\Processor;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use Symfony\Component\Yaml\Exception\ParseException;
+use Symfony\Component\Yaml\Yaml;
+
+class show extends \phpbb\console\command\command
+{
+ /**
+ * @var factory
+ */
+ protected $iohandler_factory;
+
+ /**
+ * @var installer
+ */
+ protected $installer;
+
+ /**
+ * @var language
+ */
+ protected $language;
+
+ /**
+ * Constructor
+ *
+ * @param language $language
+ * @param factory $factory
+ * @param installer $installer
+ */
+ public function __construct(language $language, factory $factory, installer $installer)
+ {
+ $this->iohandler_factory = $factory;
+ $this->installer = $installer;
+ $this->language = $language;
+
+ parent::__construct(new \phpbb\user($language, 'datetime'));
+ }
+
+ /**
+ *
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('install:config:show')
+ ->addArgument(
+ 'config-file',
+ InputArgument::REQUIRED,
+ $this->language->lang('CLI_CONFIG_FILE'))
+ ->setDescription($this->language->lang('CLI_INSTALL_SHOW_CONFIG'))
+ ;
+ }
+
+ /**
+ * Show the validated configuration
+ *
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ *
+ * @return null
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->iohandler_factory->set_environment('cli');
+
+ /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
+ $iohandler = $this->iohandler_factory->get();
+ $style = new SymfonyStyle($input, $output);
+ $iohandler->set_style($style, $output);
+
+ $config_file = $input->getArgument('config-file');
+
+ if (!is_file($config_file))
+ {
+ $iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
+
+ return;
+ }
+
+ try
+ {
+ $config = Yaml::parse(file_get_contents($config_file), true, false);
+ }
+ catch (ParseException $e)
+ {
+ $iohandler->add_error_message('INVALID_YAML_FILE');
+
+ return;
+ }
+
+ $processor = new Processor();
+ $configuration = new installer_configuration();
+
+ try
+ {
+ $config = $processor->processConfiguration($configuration, $config);
+ }
+ catch (Exception $e)
+ {
+ $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
+
+ return;
+ }
+
+ $iohandler->add_log_message(Yaml::dump(array('installer' => $config), 10, 4, true, false));
+ }
+}
diff --git a/phpBB/phpbb/install/console/command/install/config/validate.php b/phpBB/phpbb/install/console/command/install/config/validate.php
new file mode 100644
index 0000000000..19b6f99a8b
--- /dev/null
+++ b/phpBB/phpbb/install/console/command/install/config/validate.php
@@ -0,0 +1,132 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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\install\console\command\install\config;
+
+use phpbb\install\helper\iohandler\factory;
+use phpbb\install\installer;
+use phpbb\install\installer_configuration;
+use phpbb\language\language;
+use Symfony\Component\Config\Definition\Exception\Exception;
+use Symfony\Component\Config\Definition\Processor;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use Symfony\Component\Yaml\Exception\ParseException;
+use Symfony\Component\Yaml\Yaml;
+
+class validate extends \phpbb\console\command\command
+{
+ /**
+ * @var factory
+ */
+ protected $iohandler_factory;
+
+ /**
+ * @var installer
+ */
+ protected $installer;
+
+ /**
+ * @var language
+ */
+ protected $language;
+
+ /**
+ * Constructor
+ *
+ * @param language $language
+ * @param factory $factory
+ * @param installer $installer
+ */
+ public function __construct(language $language, factory $factory, installer $installer)
+ {
+ $this->iohandler_factory = $factory;
+ $this->installer = $installer;
+ $this->language = $language;
+
+ parent::__construct(new \phpbb\user($language, 'datetime'));
+ }
+
+ /**
+ *
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('install:config:validate')
+ ->addArgument(
+ 'config-file',
+ InputArgument::REQUIRED,
+ $this->language->lang('CLI_CONFIG_FILE'))
+ ->setDescription($this->language->lang('CLI_INSTALL_VALIDATE_CONFIG'))
+ ;
+ }
+
+ /**
+ * Validate the configuration file
+ *
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ *
+ * @return null
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->iohandler_factory->set_environment('cli');
+
+ /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
+ $iohandler = $this->iohandler_factory->get();
+ $style = new SymfonyStyle($input, $output);
+ $iohandler->set_style($style, $output);
+
+ $config_file = $input->getArgument('config-file');
+
+ if (!is_file($config_file))
+ {
+ $iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
+
+ return 1;
+ }
+
+ try
+ {
+ $config = Yaml::parse(file_get_contents($config_file), true, false);
+ }
+ catch (ParseException $e)
+ {
+ $iohandler->add_error_message('INVALID_YAML_FILE');
+
+ return 1;
+ }
+
+ $processor = new Processor();
+ $configuration = new installer_configuration();
+
+ try
+ {
+ $config = $processor->processConfiguration($configuration, $config);
+ }
+ catch (Exception $e)
+ {
+ $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
+
+ return 1;
+ }
+
+ $iohandler->add_success_message('CONFIGURATION_VALID');
+ return 0;
+ }
+}
diff --git a/phpBB/phpbb/install/console/command/install/install.php b/phpBB/phpbb/install/console/command/install/install.php
new file mode 100644
index 0000000000..d3f6d363f8
--- /dev/null
+++ b/phpBB/phpbb/install/console/command/install/install.php
@@ -0,0 +1,194 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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\install\console\command\install;
+
+use phpbb\install\exception\installer_exception;
+use phpbb\install\helper\iohandler\cli_iohandler;
+use phpbb\install\helper\iohandler\factory;
+use phpbb\install\installer;
+use phpbb\install\installer_configuration;
+use phpbb\language\language;
+use Symfony\Component\Config\Definition\Exception\Exception;
+use Symfony\Component\Config\Definition\Processor;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+use Symfony\Component\Yaml\Exception\ParseException;
+use Symfony\Component\Yaml\Yaml;
+
+class install extends \phpbb\console\command\command
+{
+ /**
+ * @var factory
+ */
+ protected $iohandler_factory;
+
+ /**
+ * @var installer
+ */
+ protected $installer;
+
+ /**
+ * @var language
+ */
+ protected $language;
+
+ /**
+ * Constructor
+ *
+ * @param language $language
+ * @param factory $factory
+ * @param installer $installer
+ */
+ public function __construct(language $language, factory $factory, installer $installer)
+ {
+ $this->iohandler_factory = $factory;
+ $this->installer = $installer;
+ $this->language = $language;
+
+ parent::__construct(new \phpbb\user($language, 'datetime'));
+ }
+
+ /**
+ *
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setName('install')
+ ->addArgument(
+ 'config-file',
+ InputArgument::REQUIRED,
+ $this->language->lang('CLI_CONFIG_FILE'))
+ ->setDescription($this->language->lang('CLI_INSTALL_BOARD'))
+ ;
+ }
+
+ /**
+ * Executes the command install.
+ *
+ * Install the board
+ *
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ *
+ * @return null
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ // @todo check that phpBB is not already installed
+
+ $this->iohandler_factory->set_environment('cli');
+
+ /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
+ $iohandler = $this->iohandler_factory->get();
+ $style = new SymfonyStyle($input, $output);
+ $iohandler->set_style($style, $output);
+
+ $this->installer->set_iohandler($iohandler);
+
+ $config_file = $input->getArgument('config-file');
+
+ if (!is_file($config_file))
+ {
+ $iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
+
+ return;
+ }
+
+ try
+ {
+ $config = Yaml::parse(file_get_contents($config_file), true, false);
+ }
+ catch (ParseException $e)
+ {
+ $iohandler->add_error_message('INVALID_YAML_FILE');
+
+ return;
+ }
+
+ $processor = new Processor();
+ $configuration = new installer_configuration();
+
+ try
+ {
+ $config = $processor->processConfiguration($configuration, $config);
+ }
+ catch (Exception $e)
+ {
+ $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
+
+ return;
+ }
+
+ $this->register_configuration($iohandler, $config);
+
+ try
+ {
+ $this->installer->run();
+ }
+ catch (installer_exception $e)
+ {
+ $iohandler->add_error_message($e->getMessage());
+ return;
+ }
+ }
+
+ /**
+ * Register the configuration to simulate the forms.
+ *
+ * @param cli_iohandler $iohandler
+ * @param array $config
+ */
+ private function register_configuration(cli_iohandler $iohandler, $config)
+ {
+ $iohandler->set_input('admin_name', $config['admin']['name']);
+ $iohandler->set_input('admin_pass1', $config['admin']['password']);
+ $iohandler->set_input('admin_pass2', $config['admin']['password']);
+ $iohandler->set_input('board_email', $config['admin']['email']);
+ $iohandler->set_input('submit_admin', 'submit');
+
+ $iohandler->set_input('default_lang', $config['board']['lang']);
+ $iohandler->set_input('board_name', $config['board']['name']);
+ $iohandler->set_input('board_description', $config['board']['description']);
+ $iohandler->set_input('submit_board', 'submit');
+
+ $iohandler->set_input('dbms', $config['database']['dbms']);
+ $iohandler->set_input('dbhost', $config['database']['dbhost']);
+ $iohandler->set_input('dbport', $config['database']['dbport']);
+ $iohandler->set_input('dbuser', $config['database']['dbuser']);
+ $iohandler->set_input('dbpasswd', $config['database']['dbpasswd']);
+ $iohandler->set_input('dbname', $config['database']['dbname']);
+ $iohandler->set_input('table_prefix', $config['database']['table_prefix']);
+ $iohandler->set_input('submit_database', 'submit');
+
+ $iohandler->set_input('email_enable', $config['email']['enabled']);
+ $iohandler->set_input('smtp_delivery', $config['email']['smtp_delivery']);
+ $iohandler->set_input('smtp_host', $config['email']['smtp_host']);
+ $iohandler->set_input('smtp_auth', $config['email']['smtp_auth']);
+ $iohandler->set_input('smtp_user', $config['email']['smtp_user']);
+ $iohandler->set_input('smtp_pass', $config['email']['smtp_pass']);
+ $iohandler->set_input('submit_email', 'submit');
+
+ $iohandler->set_input('cookie_secure', $config['server']['cookie_secure']);
+ $iohandler->set_input('server_protocol', $config['server']['server_protocol']);
+ $iohandler->set_input('force_server_vars', $config['server']['force_server_vars']);
+ $iohandler->set_input('server_name', $config['server']['server_name']);
+ $iohandler->set_input('server_port', $config['server']['server_port']);
+ $iohandler->set_input('script_path', $config['server']['script_path']);
+ $iohandler->set_input('submit_server', 'submit');
+ }
+}