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

add_default_data.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 4.48 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 add_default_data extends \phpbb\install\task_base
022  {
023      /**
024       * @var \phpbb\db\driver\driver_interface
025       */
026      protected $db;
027   
028      /**
029       * @var \phpbb\install\helper\database
030       */
031      protected $database_helper;
032   
033      /**
034       * @var \phpbb\install\helper\config
035       */
036      protected $config;
037   
038      /**
039       * @var \phpbb\install\helper\iohandler\iohandler_interface
040       */
041      protected $iohandler;
042   
043      /**
044       * @var \phpbb\language\language
045       */
046      protected $language;
047   
048      /**
049       * @var string
050       */
051      protected $phpbb_root_path;
052   
053      /**
054       * Constructor
055       *
056       * @param \phpbb\install\helper\database                        $db_helper    Installer's database helper
057       * @param \phpbb\install\helper\config                            $config        Installer config
058       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler    Installer's input-output handler
059       * @param \phpbb\install\helper\container_factory                $container    Installer's DI container
060       * @param \phpbb\language\language                                $language    Language service
061       * @param string                                                $root_path    Root path of phpBB
062       */
063      public function __construct(\phpbb\install\helper\database $db_helper,
064                                  \phpbb\install\helper\config $config,
065                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
066                                  \phpbb\install\helper\container_factory $container,
067                                  \phpbb\language\language $language,
068                                  $root_path)
069      {
070          $this->db                = $container->get('dbal.conn.driver');
071          $this->database_helper    = $db_helper;
072          $this->config            = $config;
073          $this->iohandler        = $iohandler;
074          $this->language            = $language;
075          $this->phpbb_root_path    = $root_path;
076   
077          parent::__construct(true);
078      }
079   
080      /**
081       * {@inheritdoc}
082       */
083      public function run()
084      {
085          $this->db->sql_return_on_error(true);
086   
087          $table_prefix = $this->config->get('table_prefix');
088          $dbms = $this->config->get('dbms');
089          $dbms_info = $this->database_helper->get_available_dbms($dbms);
090   
091          // Get schema data from file
092          $sql_query = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema_data.sql');
093   
094          // Clean up SQL
095          $sql_query = $this->replace_dbms_specific_sql($sql_query);
096          $sql_query = preg_replace('# phpbb_([^\s]*) #i', ' ' . $table_prefix . '\1 ', $sql_query);
097          $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', array($this, 'lang_replace_callback'), $sql_query);
098          $sql_query = $this->database_helper->remove_comments($sql_query);
099          $sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
100   
101          $i = $this->config->get('add_default_data_index', 0);
102          $total = sizeof($sql_query);
103          $sql_query = array_slice($sql_query, $i);
104   
105          foreach ($sql_query as $sql)
106          {
107              if (!$this->db->sql_query($sql))
108              {
109                  $error = $this->db->sql_error($this->db->get_sql_error_sql());
110                  $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
111              }
112   
113              $i++;
114   
115              // Stop execution if resource limit is reached
116              if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
117              {
118                  break;
119              }
120          }
121   
122          $this->config->set('add_default_data_index', $i);
123   
124          if ($i < $total)
125          {
126              throw new resource_limit_reached_exception();
127          }
128      }
129   
130      /**
131       * Process DB specific SQL
132       *
133       * @return string
134       */
135      protected function replace_dbms_specific_sql($query)
136      {
137          if ($this->db instanceof \phpbb\db\driver\mssql_base)
138          {
139              $query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $query);
140          }
141          else if ($this->db instanceof \phpbb\db\driver\postgres)
142          {
143              $query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $query);
144          }
145          else if ($this->db instanceof \phpbb\db\driver\mysql_base)
146          {
147              $query = str_replace('\\', '\\\\', $query);
148          }
149   
150          return $query;
151      }
152   
153      /**
154       * Callback function for language replacing
155       *
156       * @param array    $matches
157       * @return string
158       */
159      public function lang_replace_callback($matches)
160      {
161          if (!empty($matches[1]))
162          {
163              return $this->db->sql_escape($this->language->lang($matches[1]));
164          }
165   
166          return '';
167      }
168   
169      /**
170       * {@inheritdoc}
171       */
172      static public function get_step_count()
173      {
174          return 1;
175      }
176   
177      /**
178       * {@inheritdoc}
179       */
180      public function get_task_lang_name()
181      {
182          return 'TASK_ADD_DEFAULT_DATA';
183      }
184  }
185