CreateMembershipForm: Properly handle errors when fetching groups
refs #8826
This commit is contained in:
parent
45fd1b78f1
commit
170379b743
|
@ -4,6 +4,7 @@
|
|||
namespace Icinga\Forms\Config\User;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Data\DataArray\ArrayDatasource;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Notification;
|
||||
|
@ -153,8 +154,9 @@ class CreateMembershipForm extends Form
|
|||
*/
|
||||
protected function createDataSource()
|
||||
{
|
||||
$groups = array();
|
||||
$groups = $failures = array();
|
||||
foreach ($this->backends as $backend) {
|
||||
try {
|
||||
$memberships = $backend
|
||||
->select()
|
||||
->from('group_membership', array('group_name'))
|
||||
|
@ -166,6 +168,22 @@ class CreateMembershipForm extends Form
|
|||
$groups[] = $row;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$failures[] = array($backend->getName(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($groups) && !empty($failures)) {
|
||||
// In case there are only failures, throw the very first exception again
|
||||
throw $failures[0][1];
|
||||
} elseif (! empty($failures)) {
|
||||
foreach ($failures as $failure) {
|
||||
Logger::error($failure[1]);
|
||||
Notification::warning(sprintf(
|
||||
$this->translate('Failed to fetch any groups from backend %s. Please check your log'),
|
||||
$failure[0]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayDatasource($groups);
|
||||
|
|
Loading…
Reference in New Issue