Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

create_config_file.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 5.99 KiB


001  <?php
002  /**
003   *
004   * This file is part of the phpBB Forum Software package.
005   *
006   * @copyright (c) phpBB Limited <https://www.phpbb.com>
007   * @license GNU General Public License, version 2 (GPL-2.0)
008   *
009   * For full copyright and license information, please see
010   * the docs/CREDITS.txt file.
011   *
012   */
013   
014  namespace phpbb\install\module\install_filesystem\task;
015   
016  use phpbb\install\exception\user_interaction_required_exception;
017   
018  /**
019   * Dumps config file
020   */
021  class create_config_file extends \phpbb\install\task_base
022  {
023      /**
024       * @var \phpbb\filesystem\filesystem_interface
025       */
026      protected $filesystem;
027   
028      /**
029       * @var \phpbb\install\helper\database
030       */
031      protected $db_helper;
032   
033      /**
034       * @var \phpbb\install\helper\config
035       */
036      protected $install_config;
037   
038      /**
039       * @var \phpbb\install\helper\iohandler\iohandler_interface
040       */
041      protected $iohandler;
042   
043      /**
044       * @var string
045       */
046      protected $phpbb_root_path;
047   
048      /**
049       * @var string
050       */
051      protected $php_ext;
052   
053      /**
054       * @var array
055       */
056      protected $options;
057   
058      /**
059       * Constructor
060       *
061       * @param \phpbb\filesystem\filesystem_interface                $filesystem
062       * @param \phpbb\install\helper\config                            $install_config
063       * @param \phpbb\install\helper\database                        $db_helper
064       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler
065       * @param string                                                $phpbb_root_path
066       * @param string                                                $php_ext
067       * @param array                                                    $options
068       */
069      public function __construct(\phpbb\filesystem\filesystem_interface $filesystem,
070                                  \phpbb\install\helper\config $install_config,
071                                  \phpbb\install\helper\database $db_helper,
072                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
073                                  $phpbb_root_path,
074                                  $php_ext,
075                                  $options = array())
076      {
077          $this->install_config    = $install_config;
078          $this->db_helper        = $db_helper;
079          $this->filesystem        = $filesystem;
080          $this->iohandler        = $iohandler;
081          $this->phpbb_root_path    = $phpbb_root_path;
082          $this->php_ext            = $php_ext;
083          $this->options            = array_merge(array(
084              'debug' => false,
085              'debug_container' => false,
086              'environment' => null,
087          ), $options);
088   
089          parent::__construct(true);
090      }
091   
092      /**
093       * {@inheritdoc}
094       */
095      public function run()
096      {
097          $config_written = true;
098   
099          // Create config.php
100          $path_to_config = $this->phpbb_root_path . 'config.' . $this->php_ext;
101   
102          $fp = @fopen($path_to_config, 'w');
103          if (!$fp)
104          {
105              $config_written = false;
106          }
107   
108          $config_content = $this->get_config_data($this->options['debug'], $this->options['debug_container'], $this->options['environment']);
109   
110          if (!@fwrite($fp, $config_content))
111          {
112              $config_written = false;
113          }
114   
115          @fclose($fp);
116   
117          // chmod config.php to be only readable
118          if ($config_written)
119          {
120              try
121              {
122                  $this->filesystem->phpbb_chmod($path_to_config, \phpbb\filesystem\filesystem_interface::CHMOD_READ);
123              }
124              catch (\phpbb\filesystem\exception\filesystem_exception $e)
125              {
126                  // Do nothing, the user will get a notice later
127              }
128          }
129          else
130          {
131              $this->iohandler->add_error_message('UNABLE_TO_WRITE_CONFIG_FILE');
132              throw new user_interaction_required_exception();
133          }
134   
135          // Create a lock file to indicate that there is an install in progress
136          $fp = @fopen($this->phpbb_root_path . 'cache/install_lock', 'wb');
137          if ($fp === false)
138          {
139              // We were unable to create the lock file - abort
140              $this->iohandler->add_error_message('UNABLE_TO_WRITE_LOCK');
141              throw new user_interaction_required_exception();
142          }
143          @fclose($fp);
144   
145          try
146          {
147              $this->filesystem->phpbb_chmod($this->phpbb_root_path . 'cache/install_lock', 0777);
148          }
149          catch (\phpbb\filesystem\exception\filesystem_exception $e)
150          {
151              // Do nothing, the user will get a notice later
152          }
153      }
154   
155      /**
156       * Returns the content which should be dumped to config.php
157       *
158       * @param bool        $debug                 If the debug constants should be enabled by default or not
159       * @param bool        $debug_container     If the container should be compiled on
160       *                                        every page load or not
161       * @param string    $environment        The environment to use
162       *
163       * @return string    content to be written to the config file
164       */
165      protected function get_config_data($debug = false, $debug_container = false, $environment = null)
166      {
167          $config_content = "<?php\n";
168          $config_content .= "// phpBB 3.2.x auto-generated configuration file\n// Do not change anything in this file!\n";
169   
170          $dbms = $this->install_config->get('dbms');
171          $db_driver = $this->db_helper->get_available_dbms($dbms);
172          $db_driver = $db_driver[$dbms]['DRIVER'];
173   
174          $config_data_array = array(
175              'dbms'            => $db_driver,
176              'dbhost'        => $this->install_config->get('dbhost'),
177              'dbport'        => $this->install_config->get('dbport'),
178              'dbname'        => $this->install_config->get('dbname'),
179              'dbuser'        => $this->install_config->get('dbuser'),
180              'dbpasswd'        => $this->install_config->get('dbpasswd'),
181              'table_prefix'    => $this->install_config->get('table_prefix'),
182   
183              'phpbb_adm_relative_path'    => 'adm/',
184   
185              'acm_type'        => 'phpbb\cache\driver\file',
186          );
187   
188          foreach ($config_data_array as $key => $value)
189          {
190              $config_content .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
191          }
192   
193          $config_content .= "\n@define('PHPBB_INSTALLED', true);\n";
194          $config_content .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n";
195   
196          if ($environment)
197          {
198              $config_content .= "@define('PHPBB_ENVIRONMENT', 'test');\n";
199          }
200          else if ($debug)
201          {
202              $config_content .= "@define('PHPBB_ENVIRONMENT', 'development');\n";
203          }
204          else
205          {
206              $config_content .= "@define('PHPBB_ENVIRONMENT', 'production');\n";
207          }
208   
209          if ($debug_container)
210          {
211              $config_content .= "@define('DEBUG_CONTAINER', true);\n";
212          }
213          else
214          {
215              $config_content .= "// @define('DEBUG_CONTAINER', true);\n";
216          }
217   
218          if ($environment === 'test')
219          {
220              $config_content .= "@define('DEBUG_TEST', true);\n";
221   
222              // Mandatory for the functional tests, will be removed by PHPBB3-12623
223              $config_content .= "@define('DEBUG', true);\n";
224          }
225   
226          return $config_content;
227      }
228   
229      /**
230       * {@inheritdoc}
231       */
232      static public function get_step_count()
233      {
234          return 1;
235      }
236   
237      /**
238       * {@inheritdoc}
239       */
240      public function get_task_lang_name()
241      {
242          return 'TASK_CREATE_CONFIG_FILE';
243      }
244  }
245