fix PHP 8.1 Error: Serialization of 'LDAP\Connection' is not allowed

This commit is contained in:
ralf 2022-04-27 13:00:10 +02:00
parent f6ec680901
commit 68f7437cd0
3 changed files with 51 additions and 3 deletions

View File

@ -1445,6 +1445,22 @@ class adLDAP extends \adLDAP
parent::__construct($options);
}
/**
* Magic method called when object gets serialized
*
* We do NOT store ldapConnection, as we need to reconnect anyway.
* PHP 8.1 gives an error when trying to serialize LDAP\Connection object!
*
* @return array
*/
function __sleep()
{
$vars = get_object_vars($this);
unset($vars['ldapConnection']);
unset($this->ldapConnection);
return array_keys($vars);
}
/**
* Convert 8bit characters e.g. accented characters to UTF8 encoded characters
*
@ -1851,4 +1867,4 @@ class adLDAPUtils extends \adLDAPUtils
$str
);
}
}
}

View File

@ -1299,6 +1299,22 @@ class Ldap
return $id;
}
/**
* Magic method called when object gets serialized
*
* We do NOT store ldapConnection, as we need to reconnect anyway.
* PHP 8.1 gives an error when trying to serialize LDAP\Connection object!
*
* @return array
*/
function __sleep()
{
$vars = get_object_vars($this);
unset($vars['ds']);
unset($this->ds);
return array_keys($vars);
}
/**
* __wakeup function gets called by php while unserializing the object to reconnect with the ldap server
*/
@ -1307,4 +1323,4 @@ class Ldap
$this->ds = Api\Ldap::factory(true, $this->frontend->config['ldap_host'],
$this->frontend->config['ldap_root_dn'],$this->frontend->config['ldap_root_pw']);
}
}
}

View File

@ -360,6 +360,22 @@ class Ldap
$this->accountsFilter = "(&$this->accountsFilter$accounts_filter)";
}
/**
* Magic method called when object gets serialized
*
* We do NOT store ldapConnection, as we need to reconnect anyway.
* PHP 8.1 gives an error when trying to serialize LDAP\Connection object!
*
* @return array
*/
function __sleep()
{
$vars = get_object_vars($this);
unset($vars['ds']);
unset($this->ds);
return array_keys($vars);
}
/**
* __wakeup function gets called by php while unserializing the object to reconnect with the ldap server
*/
@ -1623,4 +1639,4 @@ class Ldap
{
error_log(__METHOD__."($account_id,$new_owner) not yet implemented");
}
}
}