You cannot use static that way - using another approach to save reuse the default ldap connection
This commit is contained in:
parent
6d69d89cfe
commit
a00141a180
@ -159,24 +159,21 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ldap_get_connection($config = null){
|
function ldap_get_connection($config = null){
|
||||||
if($config == null){
|
if($config == null && isset($this->default_ldap)){
|
||||||
static $ldap = null;
|
return $this->default_ldap;
|
||||||
if($ldap != null){
|
|
||||||
return $ldap;
|
|
||||||
}
|
|
||||||
$config = $this->ldap_get_config();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//cannot use Net_LDAP2::connect() as StatusNet uses
|
//cannot use Net_LDAP2::connect() as StatusNet uses
|
||||||
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
||||||
//PEAR handling can be overridden on instance objects, so we do that.
|
//PEAR handling can be overridden on instance objects, so we do that.
|
||||||
$ldap = new Net_LDAP2($config);
|
$ldap = new Net_LDAP2(isset($config)?$config:$this->ldap_get_config());
|
||||||
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
|
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$err=$ldap->bind();
|
$err=$ldap->bind();
|
||||||
if (Net_LDAP2::isError($err)) {
|
if (Net_LDAP2::isError($err)) {
|
||||||
common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage());
|
common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if($config == null) $this->default_ldap=$ldap;
|
||||||
return $ldap;
|
return $ldap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,24 +158,21 @@ class LdapAuthorizationPlugin extends AuthorizationPlugin
|
|||||||
|
|
||||||
//-----the below function were copied from LDAPAuthenticationPlugin. They will be moved to a utility class soon.----\\
|
//-----the below function were copied from LDAPAuthenticationPlugin. They will be moved to a utility class soon.----\\
|
||||||
function ldap_get_connection($config = null){
|
function ldap_get_connection($config = null){
|
||||||
if($config == null){
|
if($config == null && isset($this->default_ldap)){
|
||||||
static $ldap = null;
|
return $this->default_ldap;
|
||||||
if($ldap != null){
|
|
||||||
return $ldap;
|
|
||||||
}
|
|
||||||
$config = $this->ldap_get_config();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//cannot use Net_LDAP2::connect() as StatusNet uses
|
//cannot use Net_LDAP2::connect() as StatusNet uses
|
||||||
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
//PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
|
||||||
//PEAR handling can be overridden on instance objects, so we do that.
|
//PEAR handling can be overridden on instance objects, so we do that.
|
||||||
$ldap = new Net_LDAP2($config);
|
$ldap = new Net_LDAP2(isset($config)?$config:$this->ldap_get_config());
|
||||||
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
|
$ldap->setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$err=$ldap->bind();
|
$err=$ldap->bind();
|
||||||
if (Net_LDAP2::isError($err)) {
|
if (Net_LDAP2::isError($err)) {
|
||||||
common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage());
|
common_log(LOG_WARNING, 'Could not connect to LDAP server: '.$err->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if($config == null) $this->default_ldap=$ldap;
|
||||||
return $ldap;
|
return $ldap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user