Merge pull request #4077 from Nicofuma/ticket/14306

[ticket/14306] Automatically enable a safe mode when container building fails
This commit is contained in:
Marc Alexander 2016-01-15 18:13:34 +01:00
commit 8e584dfa6b
4 changed files with 106 additions and 64 deletions

View file

@ -146,3 +146,10 @@ function popup(url, width, height, name)
<div id="main">
<div class="main">
{% if CONTAINER_EXCEPTION !== false %}
<div class="errorbox">
<p>{{ lang('CONTAINER_EXCEPTION') }}</p><br />
<p>{{ lang('EXCEPTION') }}{{ lang('COLON') }} {{ CONTAINER_EXCEPTION.getMessage() }}</p>
<pre>{{ CONTAINER_EXCEPTION.getTraceAsString() }}</pre>
</div>
{% endif %}

View file

@ -26,7 +26,7 @@ function adm_page_header($page_title)
{
global $config, $user, $template;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
global $phpbb_dispatcher;
global $phpbb_dispatcher, $phpbb_container;
if (defined('HEADER_INC'))
{
@ -105,6 +105,8 @@ function adm_page_header($page_title)
'S_CONTENT_ENCODING' => 'UTF-8',
'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
'CONTAINER_EXCEPTION' => $phpbb_container->hasParameter('container_exception') ? $phpbb_container->getParameter('container_exception') : false,
));
// An array of http headers that phpbb will set. The following event may override these.

View file

@ -225,6 +225,9 @@ $lang = array_merge($lang, array(
'BACK' => 'Back',
'CONTAINER_EXCEPTION' => 'phpBB encountered an error building the container due to an installed extension. For this reason, all extensions have been temporarily disabled. Please try purging your forum cache. All extensions will automatically be re-enabled once the container error is resolved. If this error continues, please visit <a href="https://www.phpbb.com/support">phpBB.com</a> for support.',
'EXCEPTION' => 'Exception',
'COLOUR_SWATCH' => 'Web-safe colour swatch',
'CONFIG_UPDATED' => 'Configuration updated successfully.',
'CRON_LOCK_ERROR' => 'Could not obtain cron lock.',

View file

@ -90,7 +90,7 @@ class container_builder
*
* @var array
*/
protected $custom_parameters = null;
protected $custom_parameters = [];
/**
* @var \phpbb\config_php_file
@ -107,13 +107,16 @@ class container_builder
*/
private $container_extensions;
/** @var \Exception */
private $build_exception;
/**
* Constructor
*
* @param string $phpbb_root_path Path to the phpbb includes directory.
* @param string $php_ext php file extension
*/
function __construct($phpbb_root_path, $php_ext)
public function __construct($phpbb_root_path, $php_ext)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@ -125,6 +128,8 @@ class container_builder
* @return \phpbb_cache_container|ContainerBuilder
*/
public function get_container()
{
try
{
$container_filename = $this->get_container_filename();
$config_cache = new ConfigCache($container_filename, defined('DEBUG'));
@ -188,6 +193,33 @@ class container_builder
return $this->container;
}
catch (\Exception $e)
{
// Don't try to recover if we are in the development environment
if ($this->get_environment() === 'development')
{
throw $e;
}
if ($this->build_exception === null)
{
$this->build_exception = $e;
return $this
->without_extensions()
->without_cache()
->with_custom_parameters(array_merge($this->custom_parameters, [
'container_exception' => $e,
]))
->get_container();
}
else
{
// Rethrow the original exception if it's still failing
throw $this->build_exception;
}
}
}
/**
* Enable the extensions.
@ -450,14 +482,12 @@ class container_builder
* Inject the customs parameters into the container
*/
protected function inject_custom_parameters()
{
if ($this->custom_parameters !== null)
{
foreach ($this->custom_parameters as $key => $value)
{
$this->container->setParameter($key, $value);
}
}
}
/**