[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/phpbb/install/module/install_database/task/ -> add_tables.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  use phpbb\install\exception\resource_limit_reached_exception;
  17  
  18  /**
  19   * Create tables
  20   */
  21  class add_tables extends \phpbb\install\task_base
  22  {
  23      /**
  24       * @var \phpbb\install\helper\config
  25       */
  26      protected $config;
  27  
  28      /**
  29       * @var \phpbb\db\driver\driver_interface
  30       */
  31      protected $db;
  32  
  33      /**
  34       * @var \phpbb\db\tools\tools_interface
  35       */
  36      protected $db_tools;
  37  
  38      /**
  39       * @var \phpbb\filesystem\filesystem_interface
  40       */
  41      protected $filesystem;
  42  
  43      /**
  44       * @var string
  45       */
  46      protected $schema_file_path;
  47  
  48      /**
  49       * Constructor
  50       *
  51       * @param \phpbb\install\helper\config                $config
  52       * @param \phpbb\install\helper\database            $db_helper
  53       * @param \phpbb\filesystem\filesystem_interface    $filesystem
  54       * @param string                                    $phpbb_root_path
  55       */
  56  	public function __construct(\phpbb\install\helper\config $config,
  57                                  \phpbb\install\helper\database $db_helper,
  58                                  \phpbb\filesystem\filesystem_interface $filesystem,
  59                                  $phpbb_root_path)
  60      {
  61          $dbms = $db_helper->get_available_dbms($config->get('dbms'));
  62          $dbms = $dbms[$config->get('dbms')]['DRIVER'];
  63          $factory = new \phpbb\db\tools\factory();
  64  
  65          $this->db                = new $dbms();
  66          $this->db->sql_connect(
  67              $config->get('dbhost'),
  68              $config->get('dbuser'),
  69              $config->get('dbpasswd'),
  70              $config->get('dbname'),
  71              $config->get('dbport'),
  72              false,
  73              false
  74          );
  75  
  76          $this->config            = $config;
  77          $this->db_tools            = $factory->get($this->db);
  78          $this->filesystem        = $filesystem;
  79          $this->schema_file_path    = $phpbb_root_path . 'store/schema.json';
  80  
  81          parent::__construct(true);
  82      }
  83  
  84      /**
  85       * {@inheritdoc}
  86       */
  87  	public function run()
  88      {
  89          $this->db->sql_return_on_error(true);
  90  
  91          $table_prefix = $this->config->get('table_prefix');
  92          $change_prefix = $this->config->get('change_table_prefix', true);
  93  
  94          if (!defined('CONFIG_TABLE'))
  95          {
  96              // CONFIG_TABLE is required by sql_create_index() to check the
  97              // length of index names. However table_prefix is not defined
  98              // here yet, so we need to create the constant ourselves.
  99              define('CONFIG_TABLE', $table_prefix . 'config');
 100          }
 101  
 102          $db_table_schema = @file_get_contents($this->schema_file_path);
 103          $db_table_schema = json_decode($db_table_schema, true);
 104          $total = count($db_table_schema);
 105          $i = $this->config->get('add_table_index', 0);
 106          $db_table_schema = array_slice($db_table_schema, $i);
 107  
 108          foreach ($db_table_schema as $table_name => $table_data)
 109          {
 110              $i++;
 111  
 112              $this->db_tools->sql_create_table(
 113                  ( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
 114                  $table_data
 115              );
 116  
 117              // Stop execution if resource limit is reached
 118              if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
 119              {
 120                  break;
 121              }
 122          }
 123  
 124          $this->config->set('add_table_index', $i);
 125  
 126          if ($i < $total)
 127          {
 128              throw new resource_limit_reached_exception();
 129          }
 130          else
 131          {
 132              @unlink($this->schema_file_path);
 133          }
 134      }
 135  
 136      /**
 137       * {@inheritdoc}
 138       */
 139  	static public function get_step_count()
 140      {
 141          return 1;
 142      }
 143  
 144      /**
 145       * {@inheritdoc}
 146       */
 147  	public function get_task_lang_name()
 148      {
 149          return 'TASK_CREATE_TABLES';
 150      }
 151  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1