performance improvements
This commit is contained in:
parent
695f94e322
commit
752417f355
|
@ -614,49 +614,56 @@ class LAMConfig {
|
||||||
$line = trim($line); // remove spaces at the beginning and end
|
$line = trim($line); // remove spaces at the beginning and end
|
||||||
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
|
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
|
||||||
// search keywords
|
// search keywords
|
||||||
for ($i = 0; $i < sizeof($this->settings); $i++) {
|
$parts = explode(': ', $line);
|
||||||
$keyword = $this->settings[$i];
|
$keyword = $parts[0];
|
||||||
$keylen = strlen($keyword);
|
if (!in_array($keyword, $this->settings)) {
|
||||||
if (strtolower(substr($line, 0, $keylen + 2)) == strtolower($keyword . ": ")) {
|
continue;
|
||||||
|
}
|
||||||
|
$startIndex = strlen($keyword) + 2;
|
||||||
|
if (sizeof($parts) == 1) {
|
||||||
|
// empty global settings
|
||||||
|
$this->$keyword = '';
|
||||||
|
}
|
||||||
|
elseif (sizeof($parts) == 2) {
|
||||||
|
// global setting with value
|
||||||
|
$this->$keyword = substr($line, $startIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subKeyword = $parts[1];
|
||||||
|
$startIndex = $startIndex + strlen($subKeyword) + 2;
|
||||||
// module settings
|
// module settings
|
||||||
if (strtolower(substr($line, 0, $keylen + 2)) == "modules: ") {
|
if ($keyword == 'modules') {
|
||||||
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
|
$option = substr($line, $startIndex);
|
||||||
$pos = strpos($option, ":");
|
$this->moduleSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
|
||||||
$this->moduleSettings[substr($option, 0, $pos)] = explode(LAMConfig::LINE_SEPARATOR, substr($option, $pos + 2));
|
|
||||||
}
|
}
|
||||||
// type settings
|
// type settings
|
||||||
elseif (strtolower(substr($line, 0, $keylen + 2)) == "types: ") {
|
if ($keyword == 'types') {
|
||||||
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
|
$option = substr($line, $startIndex);
|
||||||
$pos = strpos($option, ":");
|
$this->typeSettings[$subKeyword] = $option;
|
||||||
$this->typeSettings[substr($option, 0, $pos)] = substr($option, $pos + 2);
|
|
||||||
}
|
}
|
||||||
// tool settings
|
// tool settings
|
||||||
elseif (strtolower(substr($line, 0, $keylen + 2)) == "tools: ") {
|
if ($keyword == 'tools') {
|
||||||
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
|
$option = substr($line, $startIndex);
|
||||||
$pos = strpos($option, ":");
|
$this->toolSettings[$subKeyword] = $option;
|
||||||
$this->toolSettings[substr($option, 0, $pos)] = substr($option, $pos + 2);
|
|
||||||
}
|
}
|
||||||
// job settings
|
// job settings
|
||||||
elseif (strtolower(substr($line, 0, $keylen + 2)) == "jobs: ") {
|
if ($keyword == 'jobs') {
|
||||||
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
|
$option = substr($line, $startIndex);
|
||||||
$pos = strpos($option, ":");
|
$this->jobSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
|
||||||
$this->jobSettings[substr($option, 0, $pos)] = explode(LAMConfig::LINE_SEPARATOR, substr($option, $pos + 2));
|
|
||||||
}
|
|
||||||
// general settings
|
|
||||||
else {
|
|
||||||
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
elseif (strtolower($line) == strtolower($keyword . ":")) {
|
|
||||||
// set empty options
|
|
||||||
$this->$keyword = '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($file);
|
fclose($file);
|
||||||
}
|
}
|
||||||
// check types
|
$this->removeInvalidTypes();
|
||||||
|
$this->removeInvalidModules();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes any non-existing types from the configuration.
|
||||||
|
*/
|
||||||
|
private function removeInvalidTypes() {
|
||||||
$allTypes = LAM\TYPES\getTypes();
|
$allTypes = LAM\TYPES\getTypes();
|
||||||
$activeTypes = $this->get_ActiveTypes();
|
$activeTypes = $this->get_ActiveTypes();
|
||||||
for ($i = 0; $i < sizeof($activeTypes); $i++) {
|
for ($i = 0; $i < sizeof($activeTypes); $i++) {
|
||||||
|
@ -666,14 +673,23 @@ class LAMConfig {
|
||||||
}
|
}
|
||||||
$activeTypes = array_values($activeTypes);
|
$activeTypes = array_values($activeTypes);
|
||||||
$this->set_ActiveTypes($activeTypes);
|
$this->set_ActiveTypes($activeTypes);
|
||||||
// check modules
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes any non-existing modules from the configuration.
|
||||||
|
*/
|
||||||
|
private function removeInvalidModules() {
|
||||||
$types = $this->get_ActiveTypes();
|
$types = $this->get_ActiveTypes();
|
||||||
|
$availableByScope = array();
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
$scope = \LAM\TYPES\getScopeFromTypeId($type);
|
$scope = \LAM\TYPES\getScopeFromTypeId($type);
|
||||||
$moduleVar = "modules_" . $type;
|
$moduleVar = "modules_" . $type;
|
||||||
if (isset($this->typeSettings[$moduleVar])){
|
if (isset($this->typeSettings[$moduleVar])){
|
||||||
$modules = explode(",", $this->typeSettings[$moduleVar]);
|
$modules = explode(",", $this->typeSettings[$moduleVar]);
|
||||||
$available = getAvailableModules($scope);
|
if (empty($availableByScope[$scope])) {
|
||||||
|
$availableByScope[$scope] = getAvailableModules($scope);
|
||||||
|
}
|
||||||
|
$available = $availableByScope[$scope];
|
||||||
// only return available modules
|
// only return available modules
|
||||||
$ret = array();
|
$ret = array();
|
||||||
for ($i = 0; $i < sizeof($modules); $i++) {
|
for ($i = 0; $i < sizeof($modules); $i++) {
|
||||||
|
@ -682,7 +698,6 @@ class LAMConfig {
|
||||||
$this->typeSettings[$moduleVar] = implode(",", $ret);
|
$this->typeSettings[$moduleVar] = implode(",", $ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves preferences to config file */
|
/** Saves preferences to config file */
|
||||||
|
|
|
@ -160,15 +160,15 @@ class ConfiguredType {
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
private $suffix;
|
private $suffix = null;
|
||||||
|
|
||||||
private $attributes;
|
private $attributes = null;
|
||||||
|
|
||||||
private $alias;
|
private $alias = null;
|
||||||
|
|
||||||
private $additionalLdapFilter;
|
private $additionalLdapFilter = null;
|
||||||
|
|
||||||
private $hidden;
|
private $hidden = null;
|
||||||
|
|
||||||
private $baseType;
|
private $baseType;
|
||||||
|
|
||||||
|
@ -180,22 +180,11 @@ class ConfiguredType {
|
||||||
* @param TypeManager $typeManager type manager
|
* @param TypeManager $typeManager type manager
|
||||||
* @param string $scope account type
|
* @param string $scope account type
|
||||||
* @param string $id unique ID for this configuration
|
* @param string $id unique ID for this configuration
|
||||||
* @param string $suffix LDAP base suffix
|
|
||||||
* @param array $attributes list of ListAttribute
|
|
||||||
* @param string $alias alias name for display
|
|
||||||
* @param string $ldapFilter additional LDAP filter
|
|
||||||
* @param boolean $hidden hidden in GUI
|
|
||||||
*/
|
*/
|
||||||
public function __construct(&$typeManager, $scope, $id, $suffix, $attributes, $alias,
|
public function __construct(&$typeManager, $scope, $id) {
|
||||||
$ldapFilter, $hidden) {
|
|
||||||
$this->typeManager = &$typeManager;
|
$this->typeManager = &$typeManager;
|
||||||
$this->scope = $scope;
|
$this->scope = $scope;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->suffix = $suffix;
|
|
||||||
$this->attributes = $attributes;
|
|
||||||
$this->alias = $alias;
|
|
||||||
$this->additionalLdapFilter = $ldapFilter;
|
|
||||||
$this->hidden = $hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,6 +220,10 @@ class ConfiguredType {
|
||||||
* @return string LDAP suffix
|
* @return string LDAP suffix
|
||||||
*/
|
*/
|
||||||
public function getSuffix() {
|
public function getSuffix() {
|
||||||
|
if ($this->suffix !== null) {
|
||||||
|
return $this->suffix;
|
||||||
|
}
|
||||||
|
$this->suffix = $this->typeManager->getConfig()->get_Suffix($this->id);
|
||||||
return $this->suffix;
|
return $this->suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +233,16 @@ class ConfiguredType {
|
||||||
* @return ListAttribute[] list of ListAttribute
|
* @return ListAttribute[] list of ListAttribute
|
||||||
*/
|
*/
|
||||||
public function getAttributes() {
|
public function getAttributes() {
|
||||||
|
if ($this->attributes !== null) {
|
||||||
|
return $this->attributes;
|
||||||
|
}
|
||||||
|
$attributeString = $this->typeManager->getConfig()->get_listAttributes($this->id);
|
||||||
|
$attributeSpecs = explode(';', $attributeString);
|
||||||
|
$attributes = array();
|
||||||
|
foreach ($attributeSpecs as $attributeSpec) {
|
||||||
|
$attributes[] = new ListAttribute($attributeSpec, $this->scope);
|
||||||
|
}
|
||||||
|
$this->attributes = $attributes;
|
||||||
return $this->attributes;
|
return $this->attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +252,10 @@ class ConfiguredType {
|
||||||
* @return string alias name
|
* @return string alias name
|
||||||
*/
|
*/
|
||||||
public function getAlias() {
|
public function getAlias() {
|
||||||
|
if ($this->alias !== null) {
|
||||||
|
return $this->alias;
|
||||||
|
}
|
||||||
|
$this->alias = getTypeAlias($this->id, $this->typeManager->getConfig());
|
||||||
return $this->alias;
|
return $this->alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +265,10 @@ class ConfiguredType {
|
||||||
* @return string LDAP filter
|
* @return string LDAP filter
|
||||||
*/
|
*/
|
||||||
public function getAdditionalLdapFilter() {
|
public function getAdditionalLdapFilter() {
|
||||||
|
if ($this->additionalLdapFilter !== null) {
|
||||||
|
return $this->additionalLdapFilter;
|
||||||
|
}
|
||||||
|
$this->additionalLdapFilter = $this->typeManager->getConfig()->get_Suffix($typeId);
|
||||||
return $this->additionalLdapFilter;
|
return $this->additionalLdapFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +278,10 @@ class ConfiguredType {
|
||||||
* @return boolean hidden
|
* @return boolean hidden
|
||||||
*/
|
*/
|
||||||
public function isHidden() {
|
public function isHidden() {
|
||||||
|
if ($this->hidden !== null) {
|
||||||
|
return $this->hidden;
|
||||||
|
}
|
||||||
|
$this->hidden = isAccountTypeHidden($this->id);
|
||||||
return $this->hidden;
|
return $this->hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +308,7 @@ class ConfiguredType {
|
||||||
$connection = $_SESSION["ldap"]->server();
|
$connection = $_SESSION["ldap"]->server();
|
||||||
$ret = array();
|
$ret = array();
|
||||||
$filter = $this->getBaseType()->getSuffixFilter();
|
$filter = $this->getBaseType()->getSuffixFilter();
|
||||||
$sr = @ldap_search($connection, escapeDN($this->suffix), $filter, array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
|
$sr = @ldap_search($connection, escapeDN($this->getSuffix()), $filter, array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||||
if ($sr) {
|
if ($sr) {
|
||||||
$units = ldap_get_entries($connection, $sr);
|
$units = ldap_get_entries($connection, $sr);
|
||||||
cleanLDAPResult($units);
|
cleanLDAPResult($units);
|
||||||
|
@ -312,13 +327,13 @@ class ConfiguredType {
|
||||||
// add root suffix if needed
|
// add root suffix if needed
|
||||||
$found = false;
|
$found = false;
|
||||||
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive
|
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive
|
||||||
if (strtolower($this->suffix) == strtolower($ret[$i])) {
|
if (strtolower($this->getSuffix()) == strtolower($ret[$i])) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
$ret[] = $this->suffix;
|
$ret[] = $this->getSuffix();
|
||||||
}
|
}
|
||||||
usort($ret, 'compareDN');
|
usort($ret, 'compareDN');
|
||||||
return $ret;
|
return $ret;
|
||||||
|
@ -466,29 +481,7 @@ class TypeManager {
|
||||||
*/
|
*/
|
||||||
private function buildConfiguredType($typeId) {
|
private function buildConfiguredType($typeId) {
|
||||||
$scope = getScopeFromTypeId($typeId);
|
$scope = getScopeFromTypeId($typeId);
|
||||||
$suffix = $this->config->get_Suffix($typeId);
|
return new ConfiguredType($this, $scope, $typeId);
|
||||||
$attributes = $this->getAttributes($typeId, $scope);
|
|
||||||
$alias = getTypeAlias($typeId, $this->config);
|
|
||||||
$ldapFilter = $this->config->get_Suffix($typeId);
|
|
||||||
$hidden = isAccountTypeHidden($typeId);
|
|
||||||
return new ConfiguredType($this, $scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the list of account list attributes.
|
|
||||||
*
|
|
||||||
* @param string $typeId type id
|
|
||||||
* @param string $scope account type
|
|
||||||
* @return \LAM\TYPES\ListAttribute[] list attributes
|
|
||||||
*/
|
|
||||||
private function getAttributes($typeId, $scope) {
|
|
||||||
$attributeString = $this->config->get_listAttributes($typeId);
|
|
||||||
$attributeSpecs = explode(';', $attributeString);
|
|
||||||
$attributes = array();
|
|
||||||
foreach ($attributeSpecs as $attributeSpec) {
|
|
||||||
$attributes[] = new ListAttribute($attributeSpec, $scope);
|
|
||||||
}
|
|
||||||
return $attributes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -252,6 +252,12 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
||||||
$this->doSave();
|
$this->doSave();
|
||||||
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
||||||
|
// empty script
|
||||||
|
$val = '';
|
||||||
|
$this->lAMConfig->set_scriptPath($val);
|
||||||
|
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
||||||
|
$this->doSave();
|
||||||
|
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue