From 54ab1f1e808e4b30c3840a947c256810f550852b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 21 Jan 2020 21:29:46 +0100 Subject: [PATCH 1/6] [ticket/16354] Add shutdown handler to handle issues while loading container PHPBB3-16354 --- phpBB/install/startup.php | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 50758f5b98..fa63bf1993 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -103,17 +103,51 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline) return false; } +function installer_class_loader($phpbb_root_path, $phpEx) +{ + $phpbb_class_loader_new = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); + $phpbb_class_loader_new->register(); + $phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); + $phpbb_class_loader->register(); + $phpbb_class_loader = new \phpbb\class_loader('phpbb\\convert\\', "{$phpbb_root_path}install/convert/", $phpEx); + $phpbb_class_loader->register(); + $phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); + $phpbb_class_loader_ext->register(); +} + +function installer_shutdown_function($display_errors) +{ + $error = error_get_last(); + + if ($error) + { + // Restore original display errors value + @ini_set('display_errors', $display_errors); + + $phpbb_root_path = __DIR__ . '/../'; + $phpEx = 'php'; + + installer_class_loader($phpbb_root_path, $phpEx); + $supported_error_levels = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED; + + $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer'); + if (strpos($error['file'], realpath($cache->cache_dir)) !== false) + { + $cache->purge(); + + die('The installer has detected an issue with a cached file. Try reloading the page to resolve the issue. If you require further assistance, please visit the phpBB support forums.'); + } + else if ($error['type'] & $supported_error_levels) + { + trigger_error($error['message'], $error['type']); + } + } +} + phpbb_require_updated('includes/startup.' . $phpEx, $phpbb_root_path); phpbb_require_updated('phpbb/class_loader.' . $phpEx, $phpbb_root_path); -$phpbb_class_loader_new = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); -$phpbb_class_loader_new->register(); -$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); -$phpbb_class_loader->register(); -$phpbb_class_loader = new \phpbb\class_loader('phpbb\\convert\\', "{$phpbb_root_path}install/convert/", $phpEx); -$phpbb_class_loader->register(); -$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx); -$phpbb_class_loader_ext->register(); +installer_class_loader($phpbb_root_path, $phpEx); // In case $phpbb_adm_relative_path is not set (in case of an update), use the default. $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/'; @@ -129,6 +163,9 @@ phpbb_require_updated('includes/utf/utf_tools.' . $phpEx, $phpbb_root_path); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'installer_msg_handler'); +$php_ini = new \bantu\IniGetWrapper\IniGetWrapper(); + +register_shutdown_function('installer_shutdown_function', $php_ini->getNumeric('display_errors')); $phpbb_installer_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); $phpbb_installer_container_builder From 5fb52285913cecf214795e52a46d38e0e52375f6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 22 Jan 2020 20:14:28 +0100 Subject: [PATCH 2/6] [ticket/16354] Reload page after cache purge & purge time limit PHPBB3-16354 --- phpBB/install/startup.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index fa63bf1993..94091f1beb 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -133,9 +133,21 @@ function installer_shutdown_function($display_errors) $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer'); if (strpos($error['file'], realpath($cache->cache_dir)) !== false) { - $cache->purge(); + $file_age = @filemtime($error['file']); - die('The installer has detected an issue with a cached file. Try reloading the page to resolve the issue. If you require further assistance, please visit the phpBB support forums.'); + if ($file_age !== false && ($file_age + 60) < time()) + { + $cache->purge(); + + $symfony_request = new \phpbb\symfony_request(new \phpbb\request\request(new \phpbb\request\type_cast_helper())); + + header('Location: ' . $symfony_request->getRequestUri()); + exit(); + } + else + { + 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 phpBB support forums.'); + } } else if ($error['type'] & $supported_error_levels) { From ee4620ef9e86068c1250bde6103289de02184c59 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 22 Jan 2020 21:04:18 +0100 Subject: [PATCH 3/6] [ticket/16354] Improve error output PHPBB3-16354 --- phpBB/install/startup.php | 59 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 94091f1beb..7c0ce5ecd2 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -151,7 +151,57 @@ function installer_shutdown_function($display_errors) } else if ($error['type'] & $supported_error_levels) { - trigger_error($error['message'], $error['type']); + // Convert core errors to user warnings for trigger_error() + if ($error['type'] == E_CORE_ERROR || $error['type'] == E_COMPILE_ERROR) + { + $error['type'] = E_USER_ERROR; + } + else if ($error['type'] == E_CORE_WARNING) + { + $error['type'] = E_USER_WARNING; + } + + try + { + installer_msg_handler($error['type'], $error['message'], $error['file'], $error['line']); + } + catch (\phpbb\exception\runtime_exception $exception) + { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo 'General Error'; + echo ''; + echo ''; + echo ''; + echo '
'; + echo '
'; + echo '
'; + echo '
'; + echo '

General Error

'; + + echo '
' . $exception->getMessage() . '
'; + + echo '
'; + echo '
'; + echo '
'; + echo ' '; + echo '
'; + echo ''; + echo ''; + } } } } @@ -177,7 +227,10 @@ phpbb_require_updated('includes/utf/utf_tools.' . $phpEx, $phpbb_root_path); set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'installer_msg_handler'); $php_ini = new \bantu\IniGetWrapper\IniGetWrapper(); -register_shutdown_function('installer_shutdown_function', $php_ini->getNumeric('display_errors')); +$ini_display_errors = $php_ini->getNumeric('display_errors'); +register_shutdown_function('installer_shutdown_function', $ini_display_errors); +// Suppress errors until we have created the containers +@ini_set('display_errors', 0); $phpbb_installer_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); $phpbb_installer_container_builder @@ -191,3 +244,5 @@ $phpbb_installer_container = $phpbb_installer_container_builder ->with_config_path($config_path) ->with_custom_parameters(array('cache.driver.class' => 'phpbb\cache\driver\file')) ->get_container(); + +@ini_set('display_errors', $ini_display_errors); From 115d0e794ebcded5b3e909e2eb8340146ada0d2f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Feb 2020 17:44:54 +0100 Subject: [PATCH 4/6] [ticket/16354] Clean up startup a bit and add annotations PHPBB3-16354 --- phpBB/install/startup.php | 18 +++++++++++++++++- phpBB/phpbb/filesystem/filesystem.php | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index 7c0ce5ecd2..be5a0fc223 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -103,6 +103,12 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline) return false; } +/** + * Register class loaders for installer + * + * @param string $phpbb_root_path phpBB root path + * @param string $phpEx PHP file extension + */ function installer_class_loader($phpbb_root_path, $phpEx) { $phpbb_class_loader_new = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx); @@ -115,6 +121,12 @@ function installer_class_loader($phpbb_root_path, $phpEx) $phpbb_class_loader_ext->register(); } +/** + * Installer shutdown function. Tries to resolve errors that might have occured + * during execution of installer + * + * @param int $display_errors Original display errors value + */ function installer_shutdown_function($display_errors) { $error = error_get_last(); @@ -124,6 +136,8 @@ function installer_shutdown_function($display_errors) // Restore original display errors value @ini_set('display_errors', $display_errors); + // Manually define phpBB root path and phpEx. These will not be passed + // on from app.php $phpbb_root_path = __DIR__ . '/../'; $phpEx = 'php'; @@ -131,7 +145,8 @@ function installer_shutdown_function($display_errors) $supported_error_levels = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED; $cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer'); - if (strpos($error['file'], realpath($cache->cache_dir)) !== false) + $filesystem = new \phpbb\filesystem\filesystem(); + if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false) { $file_age = @filemtime($error['file']); @@ -146,6 +161,7 @@ function installer_shutdown_function($display_errors) } else { + // Language system is not available 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 phpBB support forums.'); } } diff --git a/phpBB/phpbb/filesystem/filesystem.php b/phpBB/phpbb/filesystem/filesystem.php index 9acead0876..7f44d5f1de 100644 --- a/phpBB/phpbb/filesystem/filesystem.php +++ b/phpBB/phpbb/filesystem/filesystem.php @@ -637,7 +637,7 @@ class filesystem implements filesystem_interface } /** - * Try to resolve real path when PHP's realpath failes to do so + * Try to resolve real path when PHP's realpath fails to do so * * @param string $path * @return bool|string From 5c1782a605db8b53cd432a97bbb790fe11dba5c9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Feb 2020 20:21:16 +0100 Subject: [PATCH 5/6] [ticket/16354] Remove backtrace as it does not show meaningful info PHPBB3-16354 --- phpBB/install/startup.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index be5a0fc223..dfead2ab38 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -85,13 +85,7 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline) return; break; case E_USER_ERROR: - $msg = 'General Error:
' . $msg_text . '
in file ' . $errfile . ' on line ' . $errline; - - $backtrace = get_backtrace(); - if ($backtrace) - { - $msg .= '

BACKTRACE
' . $backtrace; - } + $msg = 'General Error:
' . $msg_text . '
in file ' . $errfile . ' on line ' . $errline . '

'; throw new \phpbb\exception\runtime_exception($msg); break; From c606055df2bb026ca1df667f6e6a678b1b23df8f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 13 Feb 2020 21:23:56 +0100 Subject: [PATCH 6/6] [ticket/16354] Use target _blank for support forums link PHPBB3-16354 --- phpBB/install/startup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index dfead2ab38..007b20da35 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -156,7 +156,7 @@ function installer_shutdown_function($display_errors) else { // Language system is not available - 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 phpBB support forums.'); + 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 phpBB support forums.'); } } else if ($error['type'] & $supported_error_levels)