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