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 |
installer.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;
015
016 use phpbb\cache\driver\driver_interface;
017 use phpbb\di\ordered_service_collection;
018 use phpbb\install\exception\cannot_build_container_exception;
019 use phpbb\install\exception\installer_config_not_writable_exception;
020 use phpbb\install\exception\jump_to_restart_point_exception;
021 use phpbb\install\exception\resource_limit_reached_exception;
022 use phpbb\install\exception\user_interaction_required_exception;
023 use phpbb\install\helper\config;
024 use phpbb\install\helper\container_factory;
025 use phpbb\install\helper\iohandler\ajax_iohandler;
026 use phpbb\install\helper\iohandler\cli_iohandler;
027 use phpbb\install\helper\iohandler\iohandler_interface;
028 use phpbb\path_helper;
029
030 class installer
031 {
032 /**
033 * @var driver_interface
034 */
035 protected $cache;
036
037 /**
038 * @var container_factory
039 */
040 protected $container_factory;
041
042 /**
043 * @var config
044 */
045 protected $install_config;
046
047 /**
048 * @var ordered_service_collection
049 */
050 protected $installer_modules;
051
052 /**
053 * @var iohandler_interface
054 */
055 protected $iohandler;
056
057 /**
058 * @var string
059 */
060 protected $web_root;
061
062 /**
063 * Stores the number of steps that a given module has
064 *
065 * @var array
066 */
067 protected $module_step_count;
068
069 /**
070 * @var bool
071 */
072 protected $purge_cache_before;
073
074 /**
075 * Constructor
076 *
077 * @param driver_interface $cache Cache service
078 * @param config $config Installer config handler
079 * @param path_helper $path_helper Path helper
080 * @param container_factory $container Container
081 */
082 public function __construct(driver_interface $cache, config $config, path_helper $path_helper, container_factory $container)
083 {
084 $this->cache = $cache;
085 $this->install_config = $config;
086 $this->container_factory = $container;
087 $this->installer_modules = null;
088 $this->web_root = $path_helper->get_web_root_path();
089 $this->purge_cache_before = false;
090 }
091
092 /**
093 * Sets modules to execute
094 *
095 * Note: The installer will run modules in the order they are set in
096 * the array.
097 *
098 * @param ordered_service_collection $modules Service collection of module service names
099 */
100 public function set_modules(ordered_service_collection $modules)
101 {
102 $this->installer_modules = $modules;
103 }
104
105 /**
106 * Sets input-output handler objects
107 *
108 * @param iohandler_interface $iohandler
109 */
110 public function set_iohandler(iohandler_interface $iohandler)
111 {
112 $this->iohandler = $iohandler;
113 }
114
115 /**
116 * Sets whether to purge cache before the installation process
117 *
118 * @param bool $purge_cache_before
119 */
120 public function set_purge_cache_before($purge_cache_before)
121 {
122 $this->purge_cache_before = $purge_cache_before;
123 }
124
125 /**
126 * Run phpBB installer
127 */
128 public function run()
129 {
130 if ($this->iohandler instanceof ajax_iohandler)
131 {
132 $this->iohandler->acquire_lock();
133 }
134
135 // Load install progress
136 $this->install_config->load_config();
137
138 if (!$this->install_config->get('cache_purged_before', false) && $this->purge_cache_before)
139 {
140 /** @var \phpbb\cache\driver\driver_interface $cache */
141 $cache = $this->container_factory->get('cache.driver');
142 $cache->purge();
143 $this->install_config->set('cache_purged_before', true);
144 }
145
146 // Recover install progress
147 $module_index = $this->recover_progress();
148
149 // Variable used to check if the install process have been finished
150 $install_finished = false;
151 $fail_cleanup = false;
152 $send_refresh = false;
153
154 // We are installing something, so the introduction stage can go now...
155 $this->install_config->set_finished_navigation_stage(array('install', 0, 'introduction'));
156 $this->iohandler->set_finished_stage_menu(array('install', 0, 'introduction'));
157
158 if ($this->install_config->get_task_progress_count() === 0)
159 {
160 // Count all tasks in the current installer modules
161 $step_count = 0;
162
163 /** @var \phpbb\install\module_interface $module */
164 foreach ($this->installer_modules as $name => $module)
165 {
166 $module_step_count = $module->get_step_count();
167 $step_count += $module_step_count;
168 $this->module_step_count[$name] = $module_step_count;
169 }
170
171 // Set task count
172 $this->install_config->set_task_progress_count($step_count);
173 }
174
175 // Set up progress information
176 $this->iohandler->set_task_count(
177 $this->install_config->get_task_progress_count()
178 );
179
180 try
181 {
182 $iterator = $this->installer_modules->getIterator();
183
184 if ($module_index < $iterator->count())
185 {
186 $iterator->seek($module_index);
187 }
188 else
189 {
190 $iterator->seek($module_index - 1);
191 $iterator->next();
192 }
193
194 while ($iterator->valid())
195 {
196 $module = $iterator->current();
197 $name = $iterator->key();
198
199 // Check if module should be executed
200 if (!$module->is_essential() && !$module->check_requirements())
201 {
202 $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
203 $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
204
205 $this->iohandler->add_log_message(array(
206 'SKIP_MODULE',
207 $name,
208 ));
209 $this->install_config->increment_current_task_progress($this->module_step_count[$name]);
210 }
211 else
212 {
213 // Set the correct stage in the navigation bar
214 $this->install_config->set_active_navigation_stage($module->get_navigation_stage_path());
215 $this->iohandler->set_active_stage_menu($module->get_navigation_stage_path());
216
217 $this->iohandler->send_response();
218
219 $module->run();
220
221 $this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
222 $this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
223 }
224
225 $module_index++;
226 $iterator->next();
227
228 // Save progress
229 $this->install_config->set_active_module($name, $module_index);
230
231 if ($iterator->valid() && ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0))
232 {
233 throw new resource_limit_reached_exception();
234 }
235 }
236
237 // Installation finished
238 $install_finished = true;
239
240 if ($this->iohandler instanceof cli_iohandler)
241 {
242 $this->iohandler->add_success_message('INSTALLER_FINISHED');
243 }
244 else
245 {
246 // Start session if not installing and get user object
247 // to allow redirecting to ACP
248 $user = $this->container_factory->get('user');
249 if (!isset($module) || !($module instanceof \phpbb\install\module\install_finish\module))
250 {
251 $auth = $this->container_factory->get('auth');
252
253 $user->session_begin();
254 $auth->acl($user->data);
255 $user->setup();
256 }
257
258 $phpbb_root_path = $this->container_factory->get_parameter('core.root_path');
259
260 $acp_url = append_sid($phpbb_root_path . 'adm/index.php', 'i=acp_help_phpbb&mode=help_phpbb', true, $user->session_id);
261 $this->iohandler->add_success_message('INSTALLER_FINISHED', array(
262 'ACP_LINK',
263 $acp_url,
264 ));
265 }
266 }
267 catch (user_interaction_required_exception $e)
268 {
269 $this->iohandler->send_response(true);
270 }
271 catch (resource_limit_reached_exception $e)
272 {
273 $send_refresh = true;
274 }
275 catch (jump_to_restart_point_exception $e)
276 {
277 $this->install_config->jump_to_restart_point($e->get_restart_point_name());
278 $send_refresh = true;
279 }
280 catch (\Exception $e)
281 {
282 $this->iohandler->add_error_message($e->getMessage());
283 $this->iohandler->send_response(true);
284 $fail_cleanup = true;
285 }
286
287 if ($this->iohandler instanceof ajax_iohandler)
288 {
289 $this->iohandler->release_lock();
290 }
291
292 if ($install_finished)
293 {
294 // Send install finished message
295 $this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
296 $this->iohandler->send_response(true);
297 }
298 else if ($send_refresh)
299 {
300 $this->iohandler->request_refresh();
301 $this->iohandler->send_response(true);
302 }
303
304 // Save install progress
305 try
306 {
307 if ($install_finished || $fail_cleanup)
308 {
309 $this->install_config->clean_up_config_file();
310 $this->cache->purge();
311
312 try
313 {
314 /** @var \phpbb\cache\driver\driver_interface $cache */
315 $cache = $this->container_factory->get('cache.driver');
316 $cache->purge();
317 }
318 catch (cannot_build_container_exception $e)
319 {
320 // Do not do anything, this just means there is no config.php yet
321 }
322 }
323 else
324 {
325 $this->install_config->save_config();
326 }
327 }
328 catch (installer_config_not_writable_exception $e)
329 {
330 // It is allowed to fail this test during requirements testing
331 $progress_data = $this->install_config->get_progress_data();
332
333 if ($progress_data['last_task_module_name'] !== 'installer.module.requirements_install')
334 {
335 $this->iohandler->add_error_message('INSTALLER_CONFIG_NOT_WRITABLE');
336 }
337 }
338 }
339
340 /**
341 * Recover install progress
342 *
343 * @return string Index of the next installer module to execute
344 */
345 protected function recover_progress()
346 {
347 $progress_array = $this->install_config->get_progress_data();
348 return $progress_array['last_task_module_index'];
349 }
350 }
351