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;
|
namespace Icinga\Forms\Config\User;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Data\DataArray\ArrayDatasource;
|
use Icinga\Data\DataArray\ArrayDatasource;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
@ -153,18 +154,35 @@ class CreateMembershipForm extends Form
|
||||||
*/
|
*/
|
||||||
protected function createDataSource()
|
protected function createDataSource()
|
||||||
{
|
{
|
||||||
$groups = array();
|
$groups = $failures = array();
|
||||||
foreach ($this->backends as $backend) {
|
foreach ($this->backends as $backend) {
|
||||||
$memberships = $backend
|
try {
|
||||||
->select()
|
$memberships = $backend
|
||||||
->from('group_membership', array('group_name'))
|
->select()
|
||||||
->where('user_name', $this->userName)
|
->from('group_membership', array('group_name'))
|
||||||
->fetchColumn();
|
->where('user_name', $this->userName)
|
||||||
foreach ($backend->select(array('group_name')) as $row) {
|
->fetchColumn();
|
||||||
if (! in_array($row->group_name, $memberships)) { // TODO(jom): Apply this as native query filter
|
foreach ($backend->select(array('group_name')) as $row) {
|
||||||
$row->backend_name = $backend->getName();
|
if (! in_array($row->group_name, $memberships)) { // TODO(jom): Apply this as native query filter
|
||||||
$groups[] = $row;
|
$row->backend_name = $backend->getName();
|
||||||
|
$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]
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue