Backend: Better implementation for createBackend
Thanks eric! fixes #7043
This commit is contained in:
parent
63cb357d48
commit
1c24273c9b
|
@ -69,36 +69,31 @@ class Backend implements Selectable, Queryable, ConnectionInterface
|
||||||
*/
|
*/
|
||||||
public static function createBackend($backendName = null)
|
public static function createBackend($backendName = null)
|
||||||
{
|
{
|
||||||
$allBackends = array();
|
$config = IcingaConfig::module('monitoring', 'backends');
|
||||||
$defaultBackend = null;
|
if ($config->count() === 0) {
|
||||||
foreach (IcingaConfig::module('monitoring', 'backends') as $name => $config) {
|
throw new ConfigurationError(t('No backend has been configured'));
|
||||||
if (!(bool) $config->get('disabled', false) && $defaultBackend === null) {
|
|
||||||
$defaultBackend = $config;
|
|
||||||
if ($backendName === null) {
|
|
||||||
$backendName = $name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$allBackends[$name] = $config;
|
|
||||||
}
|
}
|
||||||
if (empty($allBackends)) {
|
if ($backendName !== null) {
|
||||||
throw new ConfigurationError('No backend has been configured');
|
$backendConfig = $config->get($backendName);
|
||||||
}
|
if ($backendConfig === null) {
|
||||||
if ($defaultBackend === null) {
|
|
||||||
throw new ConfigurationError('All backends are disabled');
|
|
||||||
}
|
|
||||||
if ($backendName === null) {
|
|
||||||
$backendConfig = $defaultBackend;
|
|
||||||
} else {
|
|
||||||
if (!array_key_exists($backendName, $allBackends)) {
|
|
||||||
throw new ConfigurationError('No configuration for backend %s', $backendName);
|
throw new ConfigurationError('No configuration for backend %s', $backendName);
|
||||||
}
|
}
|
||||||
$backendConfig = $allBackends[$backendName];
|
if ((bool) $backendConfig->get('disabled', false) === true) {
|
||||||
if ((bool) $backendConfig->get('disabled', false)) {
|
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'Configuration for backend %s available but backend is disabled',
|
t('Configuration for backend %s available but backend is disabled'),
|
||||||
$backendName
|
$backendName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($config as $name => $backendConfig) {
|
||||||
|
if ((bool) $config->get('disabled', false) === false) {
|
||||||
|
$backendName = $name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($backendName === null) {
|
||||||
|
throw new ConfigurationError(t('All backends are disabled'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$resource = ResourceFactory::create($backendConfig->resource);
|
$resource = ResourceFactory::create($backendConfig->resource);
|
||||||
if ($backendConfig->type === 'ido' && $resource->getDbType() !== 'oracle') {
|
if ($backendConfig->type === 'ido' && $resource->getDbType() !== 'oracle') {
|
||||||
|
|
Loading…
Reference in New Issue