Do not exit the application when the logger has errors logged during bootstrap and stop preference loading on every request
Only fatals should exit the application. Preferences must be loaded only once after login.
This commit is contained in:
parent
3e04122e34
commit
9cbfe88ea6
|
@ -81,7 +81,7 @@ abstract class ApplicationBootstrap
|
|||
*
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Configuration directory
|
||||
|
@ -258,40 +258,9 @@ abstract class ApplicationBootstrap
|
|||
{
|
||||
$application = new static($configDir);
|
||||
$application->bootstrap();
|
||||
|
||||
if (Logger::hasErrorsOccurred()) {
|
||||
$application->stopApplication(Logger::getQueue());
|
||||
}
|
||||
|
||||
return $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop application and show information about errors
|
||||
*
|
||||
* @param array $errors
|
||||
*/
|
||||
public function stopApplication(array $errors = array())
|
||||
{
|
||||
$msg = "Application could not be started!\n\n";
|
||||
|
||||
if (count($errors)) {
|
||||
foreach ($errors as $error) {
|
||||
$msg .= $error[0]. "\n";
|
||||
}
|
||||
} else {
|
||||
$msg .= "Further information about the error may have been written to the application's log file.\n"
|
||||
. 'Please check it in order to analyse the problem.';
|
||||
}
|
||||
|
||||
if ($this->isWeb()) {
|
||||
$msg = nl2br($msg);
|
||||
}
|
||||
|
||||
echo $msg;
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup Icinga auto loader
|
||||
*
|
||||
|
@ -383,11 +352,19 @@ abstract class ApplicationBootstrap
|
|||
*/
|
||||
protected function setupErrorHandling()
|
||||
{
|
||||
if ($this->config->get('global', 'environment') == 'development') {
|
||||
error_reporting(E_ALL | E_NOTICE);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
error_reporting(E_ALL | E_NOTICE);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('display_errors', 1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up logger
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
protected function setupLogger()
|
||||
{
|
||||
Logger::create($this->config->logging);
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -62,12 +62,13 @@ class Cli extends ApplicationBootstrap
|
|||
{
|
||||
$this->assertRunningOnCli();
|
||||
$this
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupTimezone()
|
||||
->setupInternationalization()
|
||||
->parseBasicParams()
|
||||
->fixLoggingConfig()
|
||||
->setupErrorHandling()
|
||||
->setupLogger()
|
||||
->setupResourceFactory()
|
||||
->setupModuleManager();
|
||||
}
|
||||
|
|
|
@ -55,9 +55,10 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
protected function bootstrap()
|
||||
{
|
||||
return $this
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupTimezone()
|
||||
->setupErrorHandling()
|
||||
->setupLogger()
|
||||
->setupModules();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,12 +117,13 @@ class Web extends ApplicationBootstrap
|
|||
protected function bootstrap()
|
||||
{
|
||||
return $this
|
||||
->setupErrorHandling()
|
||||
->loadConfig()
|
||||
->setupResourceFactory()
|
||||
->setupSession()
|
||||
->setupUser()
|
||||
->setupTimezone()
|
||||
->setupErrorHandling()
|
||||
->setupResourceFactory()
|
||||
->setupLogger()
|
||||
->setupInternationalization()
|
||||
->setupRequest()
|
||||
->setupZendMvc()
|
||||
|
@ -139,7 +140,6 @@ class Web extends ApplicationBootstrap
|
|||
*/
|
||||
private function setupRoute()
|
||||
{
|
||||
|
||||
$this->frontController->getRouter()->addRoute(
|
||||
'module_javascript',
|
||||
new Zend_Controller_Router_Route(
|
||||
|
@ -203,25 +203,6 @@ class Web extends ApplicationBootstrap
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a NullStore as the preference provider
|
||||
*
|
||||
* @param Preferences $preferences The preference registry to attach the NullStore to
|
||||
* @param User $user The user, required for API compliance
|
||||
*
|
||||
* @see NullStore
|
||||
*/
|
||||
private function registerFallbackPreferenceProvider($preferences, $user)
|
||||
{
|
||||
$this->getConfig()->preferences->type = 'null';
|
||||
$preferenceStore = StoreFactory::create(
|
||||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
|
||||
$preferences->attach($preferenceStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user object and inject preference interface
|
||||
*
|
||||
|
@ -231,92 +212,9 @@ class Web extends ApplicationBootstrap
|
|||
private function setupUser()
|
||||
{
|
||||
$authenticationManager = AuthenticationManager::getInstance();
|
||||
|
||||
if ($authenticationManager->isAuthenticated() === true) {
|
||||
$user = $authenticationManager->getUser();
|
||||
|
||||
// Needed to update values in user session
|
||||
$sessionStore = new SessionStore($this->session);
|
||||
|
||||
// Performance: Do not ask provider if we've preferences
|
||||
// stored in session
|
||||
$initialPreferences = array();
|
||||
$preferencesLoaded = false;
|
||||
if (count($sessionStore->load())) {
|
||||
$initialPreferences = $sessionStore->load();
|
||||
$preferencesLoaded = true;
|
||||
}
|
||||
|
||||
$preferences = new Preferences($initialPreferences);
|
||||
|
||||
$preferences->attach($sessionStore);
|
||||
|
||||
if ($this->getConfig()->preferences !== null) {
|
||||
if (!$this->getConfig()->preferences->type) {
|
||||
Logger::info(
|
||||
'Preferences provider configuration error. No type was omitted. For convenience we enable '
|
||||
. 'file based ini provider for you.'
|
||||
);
|
||||
|
||||
$this->getConfig()->preferences->type = 'ini';
|
||||
}
|
||||
|
||||
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
||||
if (is_dir($path) === false) {
|
||||
Logger::warn(
|
||||
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
||||
$this->getConfig()->preferences->configPath,
|
||||
$this->getConfigDir('preferences')
|
||||
);
|
||||
|
||||
$this->getConfig()->preferences->configPath = $this->getConfigDir('preferences');
|
||||
}
|
||||
|
||||
$preferenceStore = null;
|
||||
|
||||
try {
|
||||
$preferenceStore = StoreFactory::create(
|
||||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
$preferences->attach($preferenceStore);
|
||||
} catch (Exception $e) {
|
||||
Logger::warn(
|
||||
'Could not create create preferences provider, preferences will be discarded: '
|
||||
. '"%s"',
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
if ($preferencesLoaded === false && $preferenceStore instanceof LoadInterface) {
|
||||
try {
|
||||
$initialPreferences = $preferenceStore->load();
|
||||
} catch (Exception $e) {
|
||||
Logger::warn(
|
||||
'%s::%s: Could not load preferences from provider. '
|
||||
. 'An exception during bootstrap was thrown: %s',
|
||||
__CLASS__,
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
$sessionStore->writeAll($initialPreferences);
|
||||
}
|
||||
} else {
|
||||
Logger::error(
|
||||
'Preferences are not configured. Refer to the documentation to setup a valid provider. '
|
||||
. 'We will use session store only. Preferences are not persisted after logout'
|
||||
);
|
||||
}
|
||||
|
||||
$user->setPreferences($preferences);
|
||||
|
||||
$this->user = $user;
|
||||
$this->user = $authenticationManager->getUser();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue