Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 141 |
|
0.00% |
0 / 5 |
CRAP | n/a |
0 / 0 |
|
| phpbb_require_updated | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| phpbb_include_updated | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| installer_msg_handler | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
240 | |||
| installer_class_loader | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| installer_shutdown_function | |
0.00% |
0 / 56 |
|
0.00% |
0 / 1 |
132 | |||
| 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 | /** @ignore */ |
| 15 | if (!defined('IN_PHPBB') || !defined('IN_INSTALL')) |
| 16 | { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | function phpbb_require_updated($path, $phpbb_root_path, $optional = false) |
| 21 | { |
| 22 | $new_path = $phpbb_root_path . 'install/update/new/' . $path; |
| 23 | $old_path = $phpbb_root_path . $path; |
| 24 | |
| 25 | if (file_exists($new_path)) |
| 26 | { |
| 27 | require($new_path); |
| 28 | } |
| 29 | else if (!$optional || file_exists($old_path)) |
| 30 | { |
| 31 | require($old_path); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function phpbb_include_updated($path, $phpbb_root_path, $optional = false) |
| 36 | { |
| 37 | $new_path = $phpbb_root_path . 'install/update/new/' . $path; |
| 38 | $old_path = $phpbb_root_path . $path; |
| 39 | |
| 40 | if (file_exists($new_path)) |
| 41 | { |
| 42 | include($new_path); |
| 43 | } |
| 44 | else if (!$optional || file_exists($old_path)) |
| 45 | { |
| 46 | include($old_path); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function installer_msg_handler($errno, $msg_text, $errfile, $errline): bool |
| 51 | { |
| 52 | global $phpbb_installer_container, $msg_long_text; |
| 53 | |
| 54 | // Acording to https://www.php.net/manual/en/language.operators.errorcontrol.php |
| 55 | // error_reporting() return a different error code inside the error handler after php 8.0 |
| 56 | $suppresed = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE; |
| 57 | if (PHP_VERSION_ID < 80000) |
| 58 | { |
| 59 | $suppresed = 0; |
| 60 | } |
| 61 | |
| 62 | if (error_reporting() == $suppresed) |
| 63 | { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | // If the message handler is stripping text, fallback to the long version if available |
| 68 | if (!$msg_text && !empty($msg_long_text)) |
| 69 | { |
| 70 | $msg_text = $msg_long_text; |
| 71 | } |
| 72 | |
| 73 | switch ($errno) |
| 74 | { |
| 75 | case E_NOTICE: |
| 76 | case E_WARNING: |
| 77 | case E_USER_WARNING: |
| 78 | case E_USER_NOTICE: |
| 79 | $msg = '[phpBB Debug] "' . $msg_text . '" in file ' . $errfile . ' on line ' . $errline; |
| 80 | |
| 81 | if (!empty($phpbb_installer_container)) |
| 82 | { |
| 83 | try |
| 84 | { |
| 85 | /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */ |
| 86 | $iohandler = $phpbb_installer_container->get('installer.helper.iohandler'); |
| 87 | $iohandler->add_warning_message($msg); |
| 88 | } |
| 89 | catch (\phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception $e) |
| 90 | { |
| 91 | print($msg); |
| 92 | } |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | print($msg); |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | break; |
| 101 | case E_USER_ERROR: |
| 102 | $msg = '<b>General Error:</b><br>' . $msg_text . '<br> in file ' . $errfile . ' on line ' . $errline . '<br><br>'; |
| 103 | |
| 104 | if (!empty($phpbb_installer_container)) |
| 105 | { |
| 106 | try |
| 107 | { |
| 108 | /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */ |
| 109 | $iohandler = $phpbb_installer_container->get('installer.helper.iohandler'); |
| 110 | $iohandler->add_error_message($msg, get_backtrace()); |
| 111 | $iohandler->send_response(true); |
| 112 | exit(); |
| 113 | } |
| 114 | catch (\phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception $e) |
| 115 | { |
| 116 | throw new \phpbb\exception\runtime_exception($msg); |
| 117 | } |
| 118 | } |
| 119 | throw new \phpbb\exception\runtime_exception($msg); |
| 120 | break; |
| 121 | case E_DEPRECATED: |
| 122 | return true; |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Register class loaders for installer |
| 131 | * |
| 132 | * @param string $phpbb_root_path phpBB root path |
| 133 | * @param string $phpEx PHP file extension |
| 134 | */ |
| 135 | function installer_class_loader($phpbb_root_path, $phpEx) |
| 136 | { |
| 137 | $phpbb_class_loader_new = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); |
| 138 | $phpbb_class_loader_new->register(); |
| 139 | $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); |
| 140 | $phpbb_class_loader->register(); |
| 141 | $phpbb_class_loader = new \phpbb\class_loader('phpbb\\convert\\', "{$phpbb_root_path}install/convert/", $phpEx); |
| 142 | $phpbb_class_loader->register(); |
| 143 | $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); |
| 144 | $phpbb_class_loader_ext->register(); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Installer shutdown function. Tries to resolve errors that might have occured |
| 149 | * during execution of installer |
| 150 | * |
| 151 | * @param int $display_errors Original display errors value |
| 152 | */ |
| 153 | function installer_shutdown_function($display_errors) |
| 154 | { |
| 155 | $error = error_get_last(); |
| 156 | |
| 157 | if ($error) |
| 158 | { |
| 159 | // Restore original display errors value |
| 160 | @ini_set('display_errors', $display_errors); |
| 161 | |
| 162 | // Manually define phpBB root path and phpEx. These will not be passed |
| 163 | // on from app.php |
| 164 | $phpbb_root_path = __DIR__ . '/../'; |
| 165 | $phpEx = 'php'; |
| 166 | |
| 167 | installer_class_loader($phpbb_root_path, $phpEx); |
| 168 | $supported_error_levels = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED; |
| 169 | |
| 170 | $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer/'); |
| 171 | $filesystem = new \phpbb\filesystem\filesystem(); |
| 172 | if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false && is_writable($cache->cache_dir)) |
| 173 | { |
| 174 | $file_age = @filemtime($error['file']); |
| 175 | |
| 176 | if ($file_age !== false && ($file_age + 60) < time()) |
| 177 | { |
| 178 | $cache->purge(); |
| 179 | |
| 180 | $symfony_request = new \phpbb\symfony_request(new \phpbb\request\request(new \phpbb\request\type_cast_helper())); |
| 181 | |
| 182 | header('Location: ' . $symfony_request->getRequestUri()); |
| 183 | exit(); |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | // Language system is not available |
| 188 | die('The installer has detected an issue with a cached file. Try reloading the page and/or manually clearing the cache to resolve the issue. If you require further assistance, please visit the <a href="https://www.phpbb.com/community/" target="_blank">phpBB support forums</a>.'); |
| 189 | } |
| 190 | } |
| 191 | else if ($error['type'] & $supported_error_levels) |
| 192 | { |
| 193 | // Convert core errors to user warnings for trigger_error() |
| 194 | if ($error['type'] == E_CORE_ERROR || $error['type'] == E_COMPILE_ERROR) |
| 195 | { |
| 196 | $error['type'] = E_USER_ERROR; |
| 197 | } |
| 198 | else if ($error['type'] == E_CORE_WARNING) |
| 199 | { |
| 200 | $error['type'] = E_USER_WARNING; |
| 201 | } |
| 202 | |
| 203 | try |
| 204 | { |
| 205 | installer_msg_handler($error['type'], $error['message'], $error['file'], $error['line']); |
| 206 | } |
| 207 | catch (\phpbb\exception\runtime_exception $exception) |
| 208 | { |
| 209 | echo '<!DOCTYPE html>'; |
| 210 | echo '<html dir="ltr">'; |
| 211 | echo '<head>'; |
| 212 | echo '<meta charset="utf-8">'; |
| 213 | echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">'; |
| 214 | echo '<title>General Error</title>'; |
| 215 | echo '<style type="text/css">' . "\n" . '/* <![CDATA[ */' . "\n"; |
| 216 | echo '* { margin: 0; padding: 0; } html { font-size: 100%; height: 100%; margin-bottom: 1px; background-color: #E4EDF0; } body { font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif; color: #536482; background: #E4EDF0; font-size: 62.5%; margin: 0; } '; |
| 217 | echo 'a:link, a:active, a:visited { color: #006699; text-decoration: none; } a:hover { color: #DD6900; text-decoration: underline; } '; |
| 218 | echo '#wrap { padding: 0 20px 15px 20px; min-width: 615px; } #page-header { text-align: right; height: 40px; } #page-footer { clear: both; font-size: 1em; text-align: center; } '; |
| 219 | echo '.panel { margin: 4px 0; background-color: #FFFFFF; border: solid 1px #A9B8C2; } '; |
| 220 | echo '#errorpage #page-header a { font-weight: bold; line-height: 6em; } #errorpage #content { padding: 10px; } #errorpage #content h1 { line-height: 1.2em; margin-bottom: 0; color: #DF075C; } '; |
| 221 | echo '#errorpage #content div { margin-top: 20px; margin-bottom: 5px; border-bottom: 1px solid #CCCCCC; padding-bottom: 5px; color: #333333; font: bold 1.2em "Lucida Grande", Arial, Helvetica, sans-serif; text-decoration: none; line-height: 120%; text-align: left; } '; |
| 222 | echo "\n" . '/* ]]> */' . "\n"; |
| 223 | echo '</style>'; |
| 224 | echo '</head>'; |
| 225 | echo '<body id="errorpage">'; |
| 226 | echo '<div id="wrap">'; |
| 227 | echo ' <div id="acp">'; |
| 228 | echo ' <div class="panel">'; |
| 229 | echo ' <div id="content">'; |
| 230 | echo ' <h1>General Error</h1>'; |
| 231 | |
| 232 | echo ' <div>' . $exception->getMessage() . '</div>'; |
| 233 | |
| 234 | echo ' </div>'; |
| 235 | echo ' </div>'; |
| 236 | echo ' </div>'; |
| 237 | echo ' <div id="page-footer">'; |
| 238 | echo ' Powered by <a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited'; |
| 239 | echo ' </div>'; |
| 240 | echo '</div>'; |
| 241 | echo '</body>'; |
| 242 | echo '</html>'; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | phpbb_require_updated('includes/startup.' . $phpEx, $phpbb_root_path); |
| 249 | phpbb_require_updated('phpbb/class_loader.' . $phpEx, $phpbb_root_path); |
| 250 | |
| 251 | installer_class_loader($phpbb_root_path, $phpEx); |
| 252 | |
| 253 | // In case $phpbb_adm_relative_path is not set (in case of an update), use the default. |
| 254 | $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; |
| 255 | $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; |
| 256 | |
| 257 | // Include files |
| 258 | phpbb_require_updated('includes/compatibility_globals.' . $phpEx, $phpbb_root_path); |
| 259 | phpbb_require_updated('includes/functions.' . $phpEx, $phpbb_root_path); |
| 260 | phpbb_require_updated('includes/functions_content.' . $phpEx, $phpbb_root_path); |
| 261 | phpbb_include_updated('includes/functions_compatibility.' . $phpEx, $phpbb_root_path); |
| 262 | phpbb_require_updated('includes/functions_user.' . $phpEx, $phpbb_root_path); |
| 263 | phpbb_require_updated('includes/utf/utf_tools.' . $phpEx, $phpbb_root_path); |
| 264 | |
| 265 | // Set PHP error handler to ours |
| 266 | set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'installer_msg_handler'); |
| 267 | $php_ini = new \bantu\IniGetWrapper\IniGetWrapper(); |
| 268 | |
| 269 | $ini_display_errors = $php_ini->getNumeric('display_errors'); |
| 270 | register_shutdown_function('installer_shutdown_function', $ini_display_errors); |
| 271 | // Suppress errors until we have created the containers |
| 272 | @ini_set('display_errors', 0); |
| 273 | |
| 274 | $phpbb_installer_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); |
| 275 | $phpbb_installer_container_builder |
| 276 | ->with_environment('installer') |
| 277 | ->without_extensions(); |
| 278 | |
| 279 | $other_config_path = $phpbb_root_path . 'install/update/new/config'; |
| 280 | $config_path = (file_exists($other_config_path . '/installer/config.yml')) ? $other_config_path : $phpbb_root_path . 'config'; |
| 281 | |
| 282 | $phpbb_installer_container = $phpbb_installer_container_builder |
| 283 | ->with_config_path($config_path) |
| 284 | ->with_custom_parameters(array('cache.driver.class' => 'phpbb\cache\driver\file')) |
| 285 | ->get_container(); |
| 286 | |
| 287 | @ini_set('display_errors', $ini_display_errors); |