data = $data; } public function apply() { $success = $this->createGroupsIni(); if (isset($this->data['resourceConfig'])) { $success &= $this->createUserGroup(); if ($success) { $success &= $this->createMembership(); } } return $success; } protected function createGroupsIni() { $config = array(); if (isset($this->data['groupConfig'])) { $backendConfig = $this->data['groupConfig']; $backendName = $backendConfig['name']; unset($backendConfig['name']); $config[$backendName] = $backendConfig; } else { $backendConfig = array( 'backend' => $this->data['backendConfig']['backend'], // "db" or "msldap" 'resource' => $this->data['resourceName'] ); if ($backendConfig['backend'] === 'msldap') { $backendConfig['user_backend'] = $this->data['backendConfig']['name']; } $config[$this->data['backendConfig']['name']] = $backendConfig; } try { Config::fromArray($config) ->setConfigFile(Config::resolvePath('groups.ini')) ->saveIni(); } catch (Exception $e) { $this->groupIniError = $e; return false; } $this->groupIniError = false; return true; } protected function createUserGroup() { try { $backend = new DbUserGroupBackend( ResourceFactory::createResource(new ConfigObject($this->data['resourceConfig'])) ); $groupName = mt('setup', 'Administrators', 'setup.role.name'); if ($backend->select()->where('group_name', $groupName)->count() === 0) { $backend->insert('group', array( 'group_name' => $groupName )); $this->groupError = false; } } catch (Exception $e) { $this->groupError = $e; return false; } return true; } protected function createMembership() { try { $backend = new DbUserGroupBackend( ResourceFactory::createResource(new ConfigObject($this->data['resourceConfig'])) ); $groupName = mt('setup', 'Administrators', 'setup.role.name'); $userName = $this->data['username']; if ($backend ->select() ->from('group_membership') ->where('group_name', $groupName) ->where('user_name', $userName) ->count() === 0 ) { $backend->insert('group_membership', array( 'group_name' => $groupName, 'user_name' => $userName )); $this->memberError = false; } } catch (Exception $e) { $this->memberError = $e; return false; } return true; } public function getSummary() { if (! isset($this->data['groupConfig'])) { return; // It's not necessary to show the user something he didn't configure.. } $pageTitle = '
' . t('Backend Name') . ' | ' . '' . $this->data['groupConfig']['name'] . ' | ' . '
' . mt('setup', 'Group Object Class') . ' | ' . '' . $this->data['groupConfig']['group_class'] . ' | ' . '
' . mt('setup', 'Custom Filter') . ' | ' . '' . (trim($this->data['groupConfig']['group_filter']) ?: t('None', 'auth.ldap.filter')) . ' | ' . '
' . mt('setup', 'Group Name Attribute') . ' | ' . '' . $this->data['groupConfig']['group_name_attribute'] . ' | ' . '
' . mt('setup', 'Group Member Attribute') . ' | ' . '' . $this->data['groupConfig']['group_member_attribute'] . ' | ' . '