[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/install/console/command/install/ -> install.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\install\console\command\install;
  15  
  16  use phpbb\install\exception\installer_exception;
  17  use phpbb\install\helper\install_helper;
  18  use phpbb\install\helper\iohandler\cli_iohandler;
  19  use phpbb\install\helper\iohandler\factory;
  20  use phpbb\install\installer;
  21  use phpbb\install\installer_configuration;
  22  use phpbb\language\language;
  23  use Symfony\Component\Config\Definition\Exception\Exception;
  24  use Symfony\Component\Config\Definition\Processor;
  25  use Symfony\Component\Console\Input\InputArgument;
  26  use Symfony\Component\Console\Input\InputInterface;
  27  use Symfony\Component\Console\Output\OutputInterface;
  28  use Symfony\Component\Console\Style\SymfonyStyle;
  29  use Symfony\Component\Yaml\Exception\ParseException;
  30  use Symfony\Component\Yaml\Yaml;
  31  
  32  class install extends \phpbb\console\command\command
  33  {
  34      /**
  35       * @var factory
  36       */
  37      protected $iohandler_factory;
  38  
  39      /**
  40       * @var installer
  41       */
  42      protected $installer;
  43  
  44      /**
  45       * @var install_helper
  46       */
  47      protected $install_helper;
  48  
  49      /**
  50       * @var language
  51       */
  52      protected $language;
  53  
  54      /**
  55       * Constructor
  56       *
  57       * @param language            $language
  58       * @param factory            $factory
  59       * @param installer            $installer
  60       * @param install_helper    $install_helper
  61       */
  62  	public function __construct(language $language, factory $factory, installer $installer, install_helper $install_helper)
  63      {
  64          $this->iohandler_factory = $factory;
  65          $this->installer = $installer;
  66          $this->language = $language;
  67          $this->install_helper = $install_helper;
  68  
  69          parent::__construct(new \phpbb\user($language, 'datetime'));
  70      }
  71  
  72      /**
  73       * {@inheritdoc}
  74       */
  75  	protected function configure()
  76      {
  77          $this
  78              ->setName('install')
  79              ->addArgument(
  80                  'config-file',
  81                  InputArgument::REQUIRED,
  82                  $this->language->lang('CLI_CONFIG_FILE'))
  83              ->setDescription($this->language->lang('CLI_INSTALL_BOARD'))
  84          ;
  85      }
  86  
  87      /**
  88       * Executes the command install.
  89       *
  90       * Install the board
  91       *
  92       * @param InputInterface  $input  An InputInterface instance
  93       * @param OutputInterface $output An OutputInterface instance
  94       *
  95       * @return null
  96       */
  97  	protected function execute(InputInterface $input, OutputInterface $output)
  98      {
  99          $this->iohandler_factory->set_environment('cli');
 100  
 101          /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
 102          $iohandler = $this->iohandler_factory->get();
 103          $style = new SymfonyStyle($input, $output);
 104          $iohandler->set_style($style, $output);
 105  
 106          $this->installer->set_iohandler($iohandler);
 107  
 108          $config_file = $input->getArgument('config-file');
 109  
 110          if ($this->install_helper->is_phpbb_installed())
 111          {
 112              $iohandler->add_error_message('INSTALL_PHPBB_INSTALLED');
 113  
 114              return 1;
 115          }
 116  
 117          if (!is_file($config_file))
 118          {
 119              $iohandler->add_error_message(array('MISSING_FILE', $config_file));
 120  
 121              return 1;
 122          }
 123  
 124          try
 125          {
 126              $config = Yaml::parse(file_get_contents($config_file), true, false);
 127          }
 128          catch (ParseException $e)
 129          {
 130              $iohandler->add_error_message(array('INVALID_YAML_FILE', $config_file));
 131  
 132              return 1;
 133          }
 134  
 135          $processor = new Processor();
 136          $configuration = new installer_configuration();
 137  
 138          try
 139          {
 140              $config = $processor->processConfiguration($configuration, $config);
 141          }
 142          catch (Exception $e)
 143          {
 144              $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
 145  
 146              return 1;
 147          }
 148  
 149          $this->register_configuration($iohandler, $config);
 150  
 151          try
 152          {
 153              $this->installer->run();
 154              return 0;
 155          }
 156          catch (installer_exception $e)
 157          {
 158              $iohandler->add_error_message($e->getMessage());
 159              return 1;
 160          }
 161      }
 162  
 163      /**
 164       * Register the configuration to simulate the forms.
 165       *
 166       * @param cli_iohandler $iohandler
 167       * @param array $config
 168       */
 169  	private function register_configuration(cli_iohandler $iohandler, $config)
 170      {
 171          $iohandler->set_input('admin_name', $config['admin']['name']);
 172          $iohandler->set_input('admin_pass1', $config['admin']['password']);
 173          $iohandler->set_input('admin_pass2', $config['admin']['password']);
 174          $iohandler->set_input('board_email', $config['admin']['email']);
 175          $iohandler->set_input('submit_admin', 'submit');
 176  
 177          $iohandler->set_input('default_lang', $config['board']['lang']);
 178          $iohandler->set_input('board_name', $config['board']['name']);
 179          $iohandler->set_input('board_description', $config['board']['description']);
 180          $iohandler->set_input('submit_board', 'submit');
 181  
 182          $iohandler->set_input('dbms', $config['database']['dbms']);
 183          $iohandler->set_input('dbhost', $config['database']['dbhost']);
 184          $iohandler->set_input('dbport', $config['database']['dbport']);
 185          $iohandler->set_input('dbuser', $config['database']['dbuser']);
 186          $iohandler->set_input('dbpasswd', $config['database']['dbpasswd']);
 187          $iohandler->set_input('dbname', $config['database']['dbname']);
 188          $iohandler->set_input('table_prefix', $config['database']['table_prefix']);
 189          $iohandler->set_input('submit_database', 'submit');
 190  
 191          $iohandler->set_input('email_enable', $config['email']['enabled']);
 192          $iohandler->set_input('smtp_delivery', $config['email']['smtp_delivery']);
 193          $iohandler->set_input('smtp_host', $config['email']['smtp_host']);
 194          $iohandler->set_input('smtp_port', $config['email']['smtp_port']);
 195          $iohandler->set_input('smtp_auth', $config['email']['smtp_auth']);
 196          $iohandler->set_input('smtp_user', $config['email']['smtp_user']);
 197          $iohandler->set_input('smtp_pass', $config['email']['smtp_pass']);
 198          $iohandler->set_input('submit_email', 'submit');
 199  
 200          $iohandler->set_input('cookie_secure', $config['server']['cookie_secure']);
 201          $iohandler->set_input('server_protocol', $config['server']['server_protocol']);
 202          $iohandler->set_input('force_server_vars', $config['server']['force_server_vars']);
 203          $iohandler->set_input('server_name', $config['server']['server_name']);
 204          $iohandler->set_input('server_port', $config['server']['server_port']);
 205          $iohandler->set_input('script_path', $config['server']['script_path']);
 206          $iohandler->set_input('submit_server', 'submit');
 207  
 208          $iohandler->set_input('install-extensions', $config['extensions']);
 209      }
 210  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1