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_schema.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 6.04 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_database\task;
015   
016  use phpbb\install\exception\resource_limit_reached_exception;
017   
018  /**
019   * Create database schema
020   */
021  class create_schema extends \phpbb\install\task_base
022  {
023      /**
024       * @var \phpbb\install\helper\config
025       */
026      protected $config;
027   
028      /**
029       * @var \phpbb\db\driver\driver_interface
030       */
031      protected $db;
032   
033      /**
034       * @var \phpbb\db\tools\tools_interface
035       */
036      protected $db_tools;
037   
038      /**
039       * @var \phpbb\install\helper\database
040       */
041      protected $database_helper;
042   
043      /**
044       * @var \phpbb\filesystem\filesystem_interface
045       */
046      protected $filesystem;
047   
048      /**
049       * @var \phpbb\install\helper\iohandler\iohandler_interface
050       */
051      protected $iohandler;
052   
053      /**
054       * @var string
055       */
056      protected $phpbb_root_path;
057   
058      /**
059       * @var string
060       */
061      protected $php_ext;
062   
063      /**
064       * Constructor
065       *
066       * @param \phpbb\install\helper\config                            $config                Installer's config provider
067       * @param \phpbb\install\helper\database                        $db_helper            Installer's database helper
068       * @param \phpbb\filesystem\filesystem_interface                $filesystem            Filesystem service
069       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler            Installer's input-output handler
070       * @param string                                                $phpbb_root_path    Path phpBB's root
071       * @param string                                                $php_ext            Extension of PHP files
072       */
073      public function __construct(\phpbb\install\helper\config $config,
074                                  \phpbb\install\helper\database $db_helper,
075                                  \phpbb\filesystem\filesystem_interface $filesystem,
076                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
077                                  $phpbb_root_path,
078                                  $php_ext)
079      {
080          $dbms = $db_helper->get_available_dbms($config->get('dbms'));
081          $dbms = $dbms[$config->get('dbms')]['DRIVER'];
082          $factory = new \phpbb\db\tools\factory();
083   
084          $this->db                = new $dbms();
085          $this->db->sql_connect(
086              $config->get('dbhost'),
087              $config->get('dbuser'),
088              $config->get('dbpasswd'),
089              $config->get('dbname'),
090              $config->get('dbport'),
091              false,
092              false
093          );
094   
095          $this->config            = $config;
096          $this->db_tools            = $factory->get($this->db);
097          $this->database_helper    = $db_helper;
098          $this->filesystem        = $filesystem;
099          $this->iohandler        = $iohandler;
100          $this->phpbb_root_path    = $phpbb_root_path;
101          $this->php_ext            = $php_ext;
102   
103          parent::__construct(true);
104      }
105   
106      /**
107       * {@inheritdoc}
108       */
109      public function run()
110      {
111          // As this task may take a large amount of time to complete refreshing the page might be necessary for some
112          // server configurations with limited resources
113          if (!$this->config->get('pre_schema_forced_refresh'))
114          {
115              if ($this->config->get_time_remaining() < 5)
116              {
117                  $this->config->set('pre_schema_forced_refresh', true);
118                  throw new resource_limit_reached_exception();
119              }
120          }
121   
122          $this->db->sql_return_on_error(true);
123   
124          $dbms = $this->config->get('dbms');
125          $dbms_info = $this->database_helper->get_available_dbms($dbms);
126          $schema_name = $dbms_info[$dbms]['SCHEMA'];
127          $delimiter = $dbms_info[$dbms]['DELIM'];
128          $table_prefix = $this->config->get('table_prefix');
129   
130          if ($dbms === 'mysql')
131          {
132              if (version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
133              {
134                  $schema_name .= '_41';
135              }
136              else
137              {
138                  $schema_name .= '_40';
139              }
140          }
141   
142          $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
143   
144          // Load database vendor specific code if there is any
145          if ($this->filesystem->exists($db_schema_path))
146          {
147              $sql_query = @file_get_contents($db_schema_path);
148              $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
149              $sql_query = $this->database_helper->remove_comments($sql_query);
150              $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
151   
152              foreach ($sql_query as $sql)
153              {
154                  if (!$this->db->sql_query($sql))
155                  {
156                      $error = $this->db->sql_error($this->db->get_sql_error_sql());
157                      $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
158                  }
159              }
160   
161              unset($sql_query);
162          }
163   
164          $change_prefix = false;
165   
166          // Generate database schema
167          if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json'))
168          {
169              $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
170              $db_table_schema = json_decode($db_table_schema, true);
171              $change_prefix = true;
172          }
173          else
174          {
175              global $table_prefix;
176   
177              $table_prefix = $this->config->get('table_prefix');
178   
179              if (!defined('CONFIG_TABLE'))
180              {
181                  // We need to include the constants file for the table constants
182                  // when we generate the schema from the migration files.
183                  include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);
184              }
185   
186              $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
187              $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
188              $factory = new \phpbb\db\tools\factory();
189              $db_tools = $factory->get($this->db, true);
190              $schema_generator = new \phpbb\db\migration\schema_generator(
191                  $migrator_classes,
192                  new \phpbb\config\config(array()),
193                  $this->db,
194                  $db_tools,
195                  $this->phpbb_root_path,
196                  $this->php_ext,
197                  $table_prefix
198              );
199              $db_table_schema = $schema_generator->get_schema();
200          }
201   
202          if (!defined('CONFIG_TABLE'))
203          {
204              // CONFIG_TABLE is required by sql_create_index() to check the
205              // length of index names. However table_prefix is not defined
206              // here yet, so we need to create the constant ourselves.
207              define('CONFIG_TABLE', $table_prefix . 'config');
208          }
209   
210          foreach ($db_table_schema as $table_name => $table_data)
211          {
212              $this->db_tools->sql_create_table(
213                  ( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
214                  $table_data
215              );
216          }
217      }
218   
219      /**
220       * {@inheritdoc}
221       */
222      static public function get_step_count()
223      {
224          return 1;
225      }
226   
227      /**
228       * {@inheritdoc}
229       */
230      public function get_task_lang_name()
231      {
232          return 'TASK_CREATE_DATABASE_SCHEMA';
233      }
234  }
235