[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/install/module/install_database/task/ -> set_up_database.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\module\install_database\task;
  15  
  16  /**
  17   * Set up database for table generation
  18   */
  19  class set_up_database extends \phpbb\install\task_base
  20  {
  21      /**
  22       * @var \phpbb\install\helper\config
  23       */
  24      protected $config;
  25  
  26      /**
  27       * @var \phpbb\db\driver\driver_interface
  28       */
  29      protected $db;
  30  
  31      /**
  32       * @var \phpbb\install\helper\database
  33       */
  34      protected $database_helper;
  35  
  36      /**
  37       * @var \phpbb\filesystem\filesystem_interface
  38       */
  39      protected $filesystem;
  40  
  41      /**
  42       * @var \phpbb\install\helper\iohandler\iohandler_interface
  43       */
  44      protected $iohandler;
  45  
  46      /**
  47       * @var string
  48       */
  49      protected $schema_file_path;
  50  
  51      /**
  52       * @var string
  53       */
  54      protected $phpbb_root_path;
  55  
  56      /**
  57       * Constructor
  58       *
  59       * @param \phpbb\install\helper\config                            $config
  60       * @param \phpbb\install\helper\database                        $db_helper
  61       * @param \phpbb\filesystem\filesystem_interface                $filesystem
  62       * @param \phpbb\install\helper\iohandler\iohandler_interface    $iohandler
  63       * @param string                                                $phpbb_root_path
  64       */
  65  	public function __construct(\phpbb\install\helper\config $config,
  66                                  \phpbb\install\helper\database $db_helper,
  67                                  \phpbb\filesystem\filesystem_interface $filesystem,
  68                                  \phpbb\install\helper\iohandler\iohandler_interface $iohandler,
  69                                  $phpbb_root_path)
  70      {
  71          $dbms = $db_helper->get_available_dbms($config->get('dbms'));
  72          $dbms = $dbms[$config->get('dbms')]['DRIVER'];
  73  
  74          $this->db                = new $dbms();
  75          $this->db->sql_connect(
  76              $config->get('dbhost'),
  77              $config->get('dbuser'),
  78              $config->get('dbpasswd'),
  79              $config->get('dbname'),
  80              $config->get('dbport'),
  81              false,
  82              false
  83          );
  84  
  85          $this->config            = $config;
  86          $this->database_helper    = $db_helper;
  87          $this->filesystem        = $filesystem;
  88          $this->iohandler        = $iohandler;
  89          $this->phpbb_root_path    = $phpbb_root_path;
  90  
  91          parent::__construct(false);
  92      }
  93  
  94      /**
  95       * {@inheritdoc}
  96       */
  97  	public function check_requirements()
  98      {
  99          $dbms = $this->config->get('dbms');
 100          $dbms_info = $this->database_helper->get_available_dbms($dbms);
 101          $schema_name = $dbms_info[$dbms]['SCHEMA'];
 102  
 103          if ($dbms === 'mysql')
 104          {
 105              if (version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
 106              {
 107                  $schema_name .= '_41';
 108              }
 109              else
 110              {
 111                  $schema_name .= '_40';
 112              }
 113          }
 114  
 115          $this->schema_file_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
 116  
 117          return $this->filesystem->exists($this->schema_file_path);
 118      }
 119  
 120      /**
 121       * {@inheritdoc}
 122       */
 123  	public function run()
 124      {
 125          $this->db->sql_return_on_error(true);
 126  
 127          $dbms = $this->config->get('dbms');
 128          $dbms_info = $this->database_helper->get_available_dbms($dbms);
 129          $delimiter = $dbms_info[$dbms]['DELIM'];
 130          $table_prefix = $this->config->get('table_prefix');
 131  
 132          $sql_query = @file_get_contents($this->schema_file_path);
 133          $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
 134          $sql_query = $this->database_helper->remove_comments($sql_query);
 135          $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
 136  
 137          foreach ($sql_query as $sql)
 138          {
 139              if (!$this->db->sql_query($sql))
 140              {
 141                  $error = $this->db->sql_error($this->db->get_sql_error_sql());
 142                  $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
 143              }
 144          }
 145  
 146          unset($sql_query);
 147      }
 148  
 149      /**
 150       * {@inheritdoc}
 151       */
 152  	static public function get_step_count()
 153      {
 154          return 1;
 155      }
 156  
 157      /**
 158       * {@inheritdoc}
 159       */
 160  	public function get_task_lang_name()
 161      {
 162          return 'TASK_SETUP_DATABASE';
 163      }
 164  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1