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 |
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 * Recovers install configuration from file
222 */
223 public function load_config()
224 {
225 if (!$this->filesystem->exists($this->install_config_file))
226 {
227 return;
228 }
229
230 $file_content = @file_get_contents($this->install_config_file);
231 $serialized_data = trim(substr($file_content, 8));
232
233 $installer_config = array();
234 $progress_data = array();
235 $navigation_data = array();
236
237 if (!empty($serialized_data))
238 {
239 $unserialized_data = json_decode($serialized_data, true);
240
241 $installer_config = (is_array($unserialized_data['installer_config'])) ? $unserialized_data['installer_config'] : array();
242 $progress_data = (is_array($unserialized_data['progress_data'])) ? $unserialized_data['progress_data'] : array();
243 $navigation_data = (is_array($unserialized_data['navigation_data'])) ? $unserialized_data['navigation_data'] : array();
244 }
245
246 $this->installer_config = array_merge($this->installer_config, $installer_config);
247 $this->progress_data = array_merge($this->progress_data, $progress_data);
248 $this->navigation_data = array_merge($this->navigation_data, $navigation_data);
249 }
250
251 /**
252 * Creates a progress restart point
253 *
254 * Restart points can be used to repeat certain tasks periodically.
255 * You need to call this method from the first task you want to repeat.
256 *
257 * @param string $name Name of the restart point
258 */
259 public function create_progress_restart_point($name)
260 {
261 $tmp_progress_data = $this->progress_data;
262 unset($tmp_progress_data['_restart_points']);
263
264 $this->progress_data['_restart_points'][$name] = $tmp_progress_data;
265 }
266
267 /**
268 * Set restart point to continue from
269 *
270 * @param string $name Name of the restart point
271 *
272 * @return bool Returns false if the restart point name does not exist, otherwise true
273 */
274 public function jump_to_restart_point($name)
275 {
276 if (!isset($this->progress_data['_restart_points'][$name]) || empty($this->progress_data['_restart_points'][$name]))
277 {
278 return false;
279 }
280
281 foreach ($this->progress_data['_restart_points'][$name] as $key => $value)
282 {
283 $this->progress_data[$key] = $value;
284 }
285
286 return true;
287 }
288
289 /**
290 * Returns whether a restart point with a given name exists or not
291 *
292 * @param string $name Name of the restart point
293 *
294 * @return bool
295 */
296 public function has_restart_point($name)
297 {
298 return isset($this->progress_data['_restart_points'][$name]);
299 }
300
301 /**
302 * Dumps install configuration to disk
303 */
304 public function save_config()
305 {
306 if ($this->do_clean_up)
307 {
308 @unlink($this->install_config_file);
309 return;
310 }
311
312 // Create array to save
313 $save_array = array(
314 'installer_config' => $this->installer_config,
315 'progress_data' => $this->progress_data,
316 'navigation_data' => $this->navigation_data,
317 );
318
319 // Create file content
320 $file_content = '<?php // ';
321 $file_content .= json_encode($save_array);
322 $file_content .= "\n";
323
324 // Dump file_content to disk
325 $fp = @fopen($this->install_config_file, 'w');
326 if (!$fp)
327 {
328 throw new installer_config_not_writable_exception();
329 }
330
331 fwrite($fp, $file_content);
332 fclose($fp);
333 }
334
335 /**
336 * Increments the task progress
337 *
338 * @param int $increment_by The amount to increment by
339 */
340 public function increment_current_task_progress($increment_by = 1)
341 {
342 $this->progress_data['current_task_progress'] += $increment_by;
343
344 if ($this->progress_data['current_task_progress'] > $this->progress_data['max_task_progress'])
345 {
346 $this->progress_data['current_task_progress'] = $this->progress_data['max_task_progress'];
347 }
348 }
349
350 /**
351 * Sets the task progress to a specific number
352 *
353 * @param int $task_progress The task progress number to be set
354 */
355 public function set_current_task_progress($task_progress)
356 {
357 $this->progress_data['current_task_progress'] = $task_progress;
358 }
359
360 /**
361 * Sets the number of tasks belonging to the installer in the current mode.
362 *
363 * @param int $task_progress_count Number of tasks
364 */
365 public function set_task_progress_count($task_progress_count)
366 {
367 $this->progress_data['max_task_progress'] = $task_progress_count;
368 }
369
370 /**
371 * Returns the number of the current task being executed
372 *
373 * @return int
374 */
375 public function get_current_task_progress()
376 {
377 return $this->progress_data['current_task_progress'];
378 }
379
380 /**
381 * Returns the number of tasks belonging to the installer in the current mode.
382 *
383 * @return int
384 */
385 public function get_task_progress_count()
386 {
387 return $this->progress_data['max_task_progress'];
388 }
389
390 /**
391 * Marks stage as completed in the navigation bar
392 *
393 * @param array $nav_path Array to the navigation elem
394 */
395 public function set_finished_navigation_stage($nav_path)
396 {
397 if (isset($this->navigation_data['finished']) && in_array($nav_path, $this->navigation_data['finished']))
398 {
399 return;
400 }
401
402 $this->navigation_data['finished'][] = $nav_path;
403 }
404
405 /**
406 * Marks stage as active in the navigation bar
407 *
408 * @param array $nav_path Array to the navigation elem
409 */
410 public function set_active_navigation_stage($nav_path)
411 {
412 $this->navigation_data['active'] = $nav_path;
413 }
414
415 /**
416 * Returns navigation data
417 *
418 * @return array
419 */
420 public function get_navigation_data()
421 {
422 return $this->navigation_data;
423 }
424
425 /**
426 * Removes install config file
427 */
428 public function clean_up_config_file()
429 {
430 $this->do_clean_up = true;
431 @unlink($this->install_config_file);
432 }
433
434 /**
435 * Filling up system_data array
436 */
437 protected function setup_system_data()
438 {
439 // Query maximum runtime from php.ini
440 $execution_time = $this->php_ini->getNumeric('max_execution_time');
441 $execution_time = min(15, $execution_time / 2);
442 $this->system_data['max_execution_time'] = $execution_time;
443
444 // Set start time
445 $this->system_data['start_time'] = microtime(true);
446
447 // Get memory limit
448 $this->system_data['memory_limit'] = $this->php_ini->getBytes('memory_limit');
449 }
450 }
451