[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 database schema 20 */ 21 class create_schema_file 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\filesystem\filesystem_interface 35 */ 36 protected $filesystem; 37 38 /** 39 * @var string 40 */ 41 protected $phpbb_root_path; 42 43 /** 44 * @var string 45 */ 46 protected $php_ext; 47 48 /** 49 * Constructor 50 * 51 * @param \phpbb\install\helper\config $config Installer's config provider 52 * @param \phpbb\install\helper\database $db_helper Installer's database helper 53 * @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service 54 * @param string $phpbb_root_path Path phpBB's root 55 * @param string $php_ext Extension of PHP files 56 */ 57 public function __construct(\phpbb\install\helper\config $config, 58 \phpbb\install\helper\database $db_helper, 59 \phpbb\filesystem\filesystem_interface $filesystem, 60 $phpbb_root_path, 61 $php_ext) 62 { 63 $dbms = $db_helper->get_available_dbms($config->get('dbms')); 64 $dbms = $dbms[$config->get('dbms')]['DRIVER']; 65 66 $this->db = new $dbms(); 67 $this->db->sql_connect( 68 $config->get('dbhost'), 69 $config->get('dbuser'), 70 $config->get('dbpasswd'), 71 $config->get('dbname'), 72 $config->get('dbport'), 73 false, 74 false 75 ); 76 77 $this->config = $config; 78 $this->filesystem = $filesystem; 79 $this->phpbb_root_path = $phpbb_root_path; 80 $this->php_ext = $php_ext; 81 82 parent::__construct(true); 83 } 84 85 /** 86 * {@inheritdoc} 87 */ 88 public function run() 89 { 90 // Generate database schema 91 if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json')) 92 { 93 $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json'); 94 $this->config->set('change_table_prefix', true); 95 } 96 else 97 { 98 global $table_prefix; 99 100 // As this task may take a large amount of time to complete refreshing the page might be necessary for some 101 // server configurations with limited resources 102 if (!$this->config->get('pre_schema_forced_refresh', false)) 103 { 104 if ($this->config->get_time_remaining() < 5) 105 { 106 $this->config->set('pre_schema_forced_refresh', true); 107 throw new resource_limit_reached_exception(); 108 } 109 } 110 111 $table_prefix = $this->config->get('table_prefix'); 112 113 if (!defined('CONFIG_TABLE')) 114 { 115 // We need to include the constants file for the table constants 116 // when we generate the schema from the migration files. 117 include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext); 118 } 119 120 $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext); 121 $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); 122 $factory = new \phpbb\db\tools\factory(); 123 $db_tools = $factory->get($this->db, true); 124 $schema_generator = new \phpbb\db\migration\schema_generator( 125 $migrator_classes, 126 new \phpbb\config\config(array()), 127 $this->db, 128 $db_tools, 129 $this->phpbb_root_path, 130 $this->php_ext, 131 $table_prefix 132 ); 133 $db_table_schema = $schema_generator->get_schema(); 134 $db_table_schema = json_encode($db_table_schema, JSON_PRETTY_PRINT); 135 136 $this->config->set('change_table_prefix', false); 137 } 138 139 $fp = @fopen($this->phpbb_root_path . 'store/schema.json', 'wb'); 140 if (!$fp) 141 { 142 throw new \Exception('INST_SCHEMA_FILE_NOT_WRITABLE'); 143 } 144 145 fwrite($fp, $db_table_schema); 146 fclose($fp); 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_CREATE_DATABASE_SCHEMA_FILE'; 163 } 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |