Verzeichnisstruktur phpBB-3.3.16
- Veröffentlicht
- 27.04.2026
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 |
config.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\helper;
015
016 use phpbb\install\exception\installer_config_not_writable_exception;
017
018 /**
019 * Stores common settings and installation status
020 */
021 class config
022 {
023 /**
024 * @var \phpbb\filesystem\filesystem_interface
025 */
026 protected $filesystem;
027
028 /**
029 * Array which contains config settings for the installer
030 *
031 * The array will also store all the user input, as well as any
032 * data that is passed to other tasks by a task.
033 *
034 * @var array
035 */
036 protected $installer_config;
037
038 /**
039 * @var string
040 */
041 protected $install_config_file;
042
043 /**
044 * @var \bantu\IniGetWrapper\IniGetWrapper
045 */
046 protected $php_ini;
047
048 /**
049 * @var string
050 */
051 protected $phpbb_root_path;
052
053 /**
054 * Array containing progress information
055 *
056 * @var array
057 */
058 protected $progress_data;
059
060 /**
061 * Array containing system information
062 *
063 * The array contains run time and memory limitations.
064 *
065 * @var array
066 */
067 protected $system_data;
068
069 /**
070 * Array containing navigation bar information
071 *
072 * @var array
073 */
074 protected $navigation_data;
075
076 /**
077 * Flag indicating that config file should be cleaned up
078 *
079 * @var bool
080 */
081 protected $do_clean_up;
082
083 /**
084 * Constructor
085 */
086 public function __construct(\phpbb\filesystem\filesystem_interface $filesystem, \bantu\IniGetWrapper\IniGetWrapper $php_ini, $phpbb_root_path)
087 {
088 $this->filesystem = $filesystem;
089 $this->php_ini = $php_ini;
090 $this->phpbb_root_path = $phpbb_root_path;
091 $this->do_clean_up = false;
092
093 // Set up data arrays
094 $this->navigation_data = array();
095 $this->installer_config = array();
096 $this->system_data = array();
097 $this->progress_data = array(
098 'last_task_module_name' => '', // Stores the service name of the latest finished module
099 'last_task_module_index' => 0, // Stores the index of the latest finished module
100 'last_task_index' => 0, // Stores the index of the latest finished task
101 'max_task_progress' => 0,
102 'current_task_progress' => 0,
103 '_restart_points' => array(),
104 'use_restart_point' => false,
105 );
106
107 $this->install_config_file = $this->phpbb_root_path . 'store/install_config.php';
108
109 $this->setup_system_data();
110 }
111
112 /**
113 * Returns data for a specified parameter
114 *
115 * @param string $param_name Name of the parameter to return
116 * @param mixed $default Default value to return when the specified data
117 * does not exist.
118 *
119 * @return mixed value of the specified parameter or the default value if the data
120 * cannot be recovered.
121 */
122 public function get($param_name, $default = false)
123 {
124 return (isset($this->installer_config[$param_name])) ? $this->installer_config[$param_name] : $default;
125 }
126
127 /**
128 * Sets a parameter in installer_config
129 *
130 * @param string $param_name Name of the parameter
131 * @param mixed $value Values to set the parameter
132 */
133 public function set($param_name, $value)
134 {
135 $this->installer_config = array_merge($this->installer_config, array(
136 $param_name => $value,
137 ));
138 }
139
140 /**
141 * Returns system parameter
142 *
143 * @param string $param_name Name of the parameter
144 *
145 * @return mixed Returns system parameter if it is defined, false otherwise
146 */
147 public function system_get($param_name)
148 {
149 return (isset($this->system_data[$param_name])) ? $this->system_data[$param_name] : false;
150 }
151
152 /**
153 * Returns remaining time until the run time limit
154 *
155 * @return int Remaining time until the run time limit in seconds
156 */
157 public function get_time_remaining()
158 {
159 if ($this->system_data['max_execution_time'] <= 0)
160 {
161 return PHP_INT_MAX;
162 }
163
164 return ($this->system_data['start_time'] + $this->system_data['max_execution_time']) - microtime(true);
165 }
166
167 /**
168 * Returns remaining memory available for PHP
169 *
170 * @return int Remaining memory until reaching the limit
171 */
172 public function get_memory_remaining()
173 {
174 if ($this->system_data['memory_limit'] <= 0)
175 {
176 return 1;
177 }
178
179 if (function_exists('memory_get_usage'))
180 {
181 return ($this->system_data['memory_limit'] - memory_get_usage());
182 }
183
184 // If we cannot get the information then just return a positive number (and cross fingers)
185 return 1;
186 }
187
188 /**
189 * Saves the latest executed task
190 *
191 * @param int $task_service_index Index of the installer task service in the module
192 */
193 public function set_finished_task($task_service_index)
194 {
195 $this->progress_data['last_task_index'] = $task_service_index;
196 }
197
198 /**
199 * Set active module
200 *
201 * @param string $module_service_name Name of the installer module service
202 * @param int $module_service_index Index of the installer module service
203 */
204 public function set_active_module($module_service_name, $module_service_index)
205 {
206 $this->progress_data['last_task_module_name'] = $module_service_name;
207 $this->progress_data['last_task_module_index'] = $module_service_index;
208 }
209
210 /**
211 * Getter for progress data
212 *
213 * @return array
214 */
215 public function get_progress_data()
216 {
217 return $this->progress_data;
218 }
219
220 /**
221 * Checks whether install config exists, i.e. whether an installation is in progress
222 *
223 * @return bool
224 */
225 public function exists(): bool
226 {
227 return $this->filesystem->exists($this->install_config_file);
228 }
229
230 /**
231 * Recovers install configuration from file
232 */
233 public function load_config()
234 {
235 if (!$this->exists())
236 {
237 return;
238 }
239
240 $file_content = @file_get_contents($this->install_config_file);
241 $serialized_data = trim(substr($file_content, 8));
242
243 $installer_config = array();
244 $progress_data = array();
245 $navigation_data = array();
246
247 if (!empty($serialized_data))
248 {
249 $unserialized_data = json_decode($serialized_data, true);
250
251 $installer_config = (is_array($unserialized_data['installer_config'])) ? $unserialized_data['installer_config'] : array();
252 $progress_data = (is_array($unserialized_data['progress_data'])) ? $unserialized_data['progress_data'] : array();
253 $navigation_data = (is_array($unserialized_data['navigation_data'])) ? $unserialized_data['navigation_data'] : array();
254 }
255
256 $this->installer_config = array_merge($this->installer_config, $installer_config);
257 $this->progress_data = array_merge($this->progress_data, $progress_data);
258 $this->navigation_data = array_merge($this->navigation_data, $navigation_data);
259 }
260
261 /**
262 * Creates a progress restart point
263 *
264 * Restart points can be used to repeat certain tasks periodically.
265 * You need to call this method from the first task you want to repeat.
266 *
267 * @param string $name Name of the restart point
268 */
269 public function create_progress_restart_point($name)
270 {
271 $tmp_progress_data = $this->progress_data;
272 unset($tmp_progress_data['_restart_points']);
273
274 $this->progress_data['_restart_points'][$name] = $tmp_progress_data;
275 }
276
277 /**
278 * Set restart point to continue from
279 *
280 * @param string $name Name of the restart point
281 *
282 * @return bool Returns false if the restart point name does not exist, otherwise true
283 */
284 public function jump_to_restart_point($name)
285 {
286 if (!isset($this->progress_data['_restart_points'][$name]) || empty($this->progress_data['_restart_points'][$name]))
287 {
288 return false;
289 }
290
291 foreach ($this->progress_data['_restart_points'][$name] as $key => $value)
292 {
293 $this->progress_data[$key] = $value;
294 }
295
296 return true;
297 }
298
299 /**
300 * Returns whether a restart point with a given name exists or not
301 *
302 * @param string $name Name of the restart point
303 *
304 * @return bool
305 */
306 public function has_restart_point($name)
307 {
308 return isset($this->progress_data['_restart_points'][$name]);
309 }
310
311 /**
312 * Dumps install configuration to disk
313 */
314 public function save_config()
315 {
316 if ($this->do_clean_up)
317 {
318 @unlink($this->install_config_file);
319 return;
320 }
321
322 // Create array to save
323 $save_array = array(
324 'installer_config' => $this->installer_config,
325 'progress_data' => $this->progress_data,
326 'navigation_data' => $this->navigation_data,
327 );
328
329 // Create file content
330 $file_content = '<?php // ';
331 $file_content .= json_encode($save_array);
332 $file_content .= "\n";
333
334 // Dump file_content to disk
335 $fp = @fopen($this->install_config_file, 'w');
336 if (!$fp)
337 {
338 throw new installer_config_not_writable_exception();
339 }
340
341 fwrite($fp, $file_content);
342 fclose($fp);
343 // Enforce 0600 permission for install config
344 $this->filesystem->chmod([$this->install_config_file], 0600);
345 }
346
347 /**
348 * Increments the task progress
349 *
350 * @param int $increment_by The amount to increment by
351 */
352 public function increment_current_task_progress($increment_by = 1)
353 {
354 $this->progress_data['current_task_progress'] += $increment_by;
355
356 if ($this->progress_data['current_task_progress'] > $this->progress_data['max_task_progress'])
357 {
358 $this->progress_data['current_task_progress'] = $this->progress_data['max_task_progress'];
359 }
360 }
361
362 /**
363 * Sets the task progress to a specific number
364 *
365 * @param int $task_progress The task progress number to be set
366 */
367 public function set_current_task_progress($task_progress)
368 {
369 $this->progress_data['current_task_progress'] = $task_progress;
370 }
371
372 /**
373 * Sets the number of tasks belonging to the installer in the current mode.
374 *
375 * @param int $task_progress_count Number of tasks
376 */
377 public function set_task_progress_count($task_progress_count)
378 {
379 $this->progress_data['max_task_progress'] = $task_progress_count;
380 }
381
382 /**
383 * Returns the number of the current task being executed
384 *
385 * @return int
386 */
387 public function get_current_task_progress()
388 {
389 return $this->progress_data['current_task_progress'];
390 }
391
392 /**
393 * Returns the number of tasks belonging to the installer in the current mode.
394 *
395 * @return int
396 */
397 public function get_task_progress_count()
398 {
399 return $this->progress_data['max_task_progress'];
400 }
401
402 /**
403 * Marks stage as completed in the navigation bar
404 *
405 * @param array $nav_path Array to the navigation elem
406 */
407 public function set_finished_navigation_stage($nav_path)
408 {
409 if (isset($this->navigation_data['finished']) && in_array($nav_path, $this->navigation_data['finished']))
410 {
411 return;
412 }
413
414 $this->navigation_data['finished'][] = $nav_path;
415 }
416
417 /**
418 * Marks stage as active in the navigation bar
419 *
420 * @param array $nav_path Array to the navigation elem
421 */
422 public function set_active_navigation_stage($nav_path)
423 {
424 $this->navigation_data['active'] = $nav_path;
425 }
426
427 /**
428 * Returns navigation data
429 *
430 * @return array
431 */
432 public function get_navigation_data()
433 {
434 return $this->navigation_data;
435 }
436
437 /**
438 * Removes install config file
439 */
440 public function clean_up_config_file()
441 {
442 $this->do_clean_up = true;
443 @unlink($this->install_config_file);
444 }
445
446 /**
447 * Filling up system_data array
448 */
449 protected function setup_system_data()
450 {
451 // Query maximum runtime from php.ini
452 $execution_time = $this->php_ini->getNumeric('max_execution_time');
453 $execution_time = min(15, $execution_time / 2);
454 $this->system_data['max_execution_time'] = $execution_time;
455
456 // Set start time
457 $this->system_data['start_time'] = microtime(true);
458
459 // Get memory limit
460 $this->system_data['memory_limit'] = $this->php_ini->getBytes('memory_limit');
461 }
462 }
463