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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
obtain_database_data.php
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\obtain_data\task;
015
016 use phpbb\install\exception\user_interaction_required_exception;
017
018 /**
019 * This class requests and validates database information from the user
020 */
021 class obtain_database_data extends \phpbb\install\task_base implements \phpbb\install\task_interface
022 {
023 /**
024 * @var \phpbb\install\helper\database
025 */
026 protected $database_helper;
027
028 /**
029 * @var \phpbb\install\helper\config
030 */
031 protected $install_config;
032
033 /**
034 * @var \phpbb\install\helper\iohandler\iohandler_interface
035 */
036 protected $io_handler;
037
038 /**
039 * Constructor
040 *
041 * @param \phpbb\install\helper\database $database_helper Installer's database helper
042 * @param \phpbb\install\helper\config $install_config Installer's config helper
043 * @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
044 */
045 public function __construct(\phpbb\install\helper\database $database_helper,
046 \phpbb\install\helper\config $install_config,
047 \phpbb\install\helper\iohandler\iohandler_interface $iohandler)
048 {
049 $this->database_helper = $database_helper;
050 $this->install_config = $install_config;
051 $this->io_handler = $iohandler;
052
053 parent::__construct(true);
054 }
055
056 /**
057 * {@inheritdoc}
058 */
059 public function run()
060 {
061 // Check if data is sent
062 if ($this->io_handler->get_input('submit_database', false))
063 {
064 $this->process_form();
065 }
066 else
067 {
068 $this->request_form_data();
069 }
070 }
071
072 /**
073 * Process form data
074 */
075 protected function process_form()
076 {
077 // Collect database data
078 $dbms = $this->io_handler->get_input('dbms', '');
079 $dbhost = $this->io_handler->get_input('dbhost', '', true);
080 $dbport = $this->io_handler->get_input('dbport', '');
081 $dbuser = $this->io_handler->get_input('dbuser', '');
082 $dbpasswd = $this->io_handler->get_raw_input('dbpasswd', '');
083 $dbname = $this->io_handler->get_input('dbname', '');
084 $table_prefix = $this->io_handler->get_input('table_prefix', '');
085
086 // Check database data
087 $user_data_vaild = $this->check_database_data($dbms, $dbhost, $dbport, $dbuser, $dbpasswd, $dbname, $table_prefix);
088
089 // Save database data if it is correct
090 if ($user_data_vaild)
091 {
092 $this->install_config->set('dbms', $dbms);
093 $this->install_config->set('dbhost', $dbhost);
094 $this->install_config->set('dbport', $dbport);
095 $this->install_config->set('dbuser', $dbuser);
096 $this->install_config->set('dbpasswd', $dbpasswd);
097 $this->install_config->set('dbname', $dbname);
098 $this->install_config->set('table_prefix', $table_prefix);
099 }
100 else
101 {
102 $this->request_form_data(true);
103 }
104 }
105
106 /**
107 * Request data from the user
108 *
109 * @param bool $use_request_data Whether to use submited data
110 *
111 * @throws \phpbb\install\exception\user_interaction_required_exception When the user is required to provide data
112 */
113 protected function request_form_data($use_request_data = false)
114 {
115 if ($use_request_data)
116 {
117 $dbms = $this->io_handler->get_input('dbms', '');
118 $dbhost = $this->io_handler->get_input('dbhost', '', true);
119 $dbport = $this->io_handler->get_input('dbport', '');
120 $dbuser = $this->io_handler->get_input('dbuser', '');
121 $dbname = $this->io_handler->get_input('dbname', '');
122 $table_prefix = $this->io_handler->get_input('table_prefix', 'phpbb_');
123 }
124 else
125 {
126 $dbms = '';
127 $dbhost = '';
128 $dbport = '';
129 $dbuser = '';
130 $dbname = '';
131 $table_prefix = 'phpbb_';
132 }
133
134 $dbms_select = array();
135 foreach ($this->database_helper->get_available_dbms() as $dbms_key => $dbms_array)
136 {
137 $dbms_select[] = array(
138 'value' => $dbms_key,
139 'label' => 'DB_OPTION_' . strtoupper($dbms_key),
140 'selected' => ($dbms_key === $dbms),
141 );
142 }
143
144 $database_form = array(
145 'dbms' => array(
146 'label' => 'DBMS',
147 'type' => 'select',
148 'options' => $dbms_select,
149 ),
150 'dbhost' => array(
151 'label' => 'DB_HOST',
152 'description' => 'DB_HOST_EXPLAIN',
153 'type' => 'text',
154 'default' => $dbhost,
155 ),
156 'dbport' => array(
157 'label' => 'DB_PORT',
158 'description' => 'DB_PORT_EXPLAIN',
159 'type' => 'text',
160 'default' => $dbport,
161 ),
162 'dbuser' => array(
163 'label' => 'DB_USERNAME',
164 'type' => 'text',
165 'default' => $dbuser,
166 ),
167 'dbpasswd' => array(
168 'label' => 'DB_PASSWORD',
169 'type' => 'password',
170 ),
171 'dbname' => array(
172 'label' => 'DB_NAME',
173 'type' => 'text',
174 'default' => $dbname,
175 ),
176 'table_prefix' => array(
177 'label' => 'TABLE_PREFIX',
178 'description' => 'TABLE_PREFIX_EXPLAIN',
179 'type' => 'text',
180 'default' => $table_prefix,
181 ),
182 'submit_database' => array(
183 'label' => 'SUBMIT',
184 'type' => 'submit',
185 ),
186 );
187
188 $this->io_handler->add_user_form_group('DB_CONFIG', $database_form);
189
190 // Require user interaction
191 throw new user_interaction_required_exception();
192 }
193
194 /**
195 * Check database data
196 *
197 * @param string $dbms Selected database type
198 * @param string $dbhost Database host address
199 * @param int $dbport Database port number
200 * @param string $dbuser Database username
201 * @param string $dbpass Database password
202 * @param string $dbname Database name
203 * @param string $table_prefix Database table prefix
204 *
205 * @return bool True if database data is correct, false otherwise
206 */
207 protected function check_database_data($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix)
208 {
209 $available_dbms = $this->database_helper->get_available_dbms();
210 $data_valid = true;
211
212 // Check if PHP has the database extensions for the specified DBMS
213 if (!isset($available_dbms[$dbms]))
214 {
215 $this->io_handler->add_error_message('INST_ERR_NO_DB');
216 $data_valid = false;
217 }
218
219 // Validate table prefix
220 $prefix_valid = $this->database_helper->validate_table_prefix($dbms, $table_prefix);
221 if (is_array($prefix_valid))
222 {
223 foreach ($prefix_valid as $error)
224 {
225 $this->io_handler->add_error_message(
226 $error['title'],
227 (isset($error['description'])) ? $error['description'] : false
228 );
229 }
230
231 $data_valid = false;
232 }
233
234 // Try to connect to database if all provided data is valid
235 if ($data_valid)
236 {
237 $connect_test = $this->database_helper->check_database_connection($dbms, $dbhost, $dbport, $dbuser, $dbpass, $dbname, $table_prefix);
238 if (is_array($connect_test))
239 {
240 foreach ($connect_test as $error)
241 {
242 $this->io_handler->add_error_message(
243 $error['title'],
244 (isset($error['description'])) ? $error['description'] : false
245 );
246 }
247
248 $data_valid = false;
249 }
250 }
251
252 return $data_valid;
253 }
254
255 /**
256 * {@inheritdoc}
257 */
258 static public function get_step_count()
259 {
260 return 0;
261 }
262
263 /**
264 * {@inheritdoc}
265 */
266 public function get_task_lang_name()
267 {
268 return '';
269 }
270 }
271