From 03099756d73c05359f031538f52aae3224a1b504 Mon Sep 17 00:00:00 2001 From: ralf Date: Wed, 27 Apr 2022 13:00:10 +0200 Subject: [PATCH] fix PHP 8.1 Error: Serialization of 'LDAP\Connection' is not allowed --- api/src/Accounts/Ads.php | 18 +++++++++++++++++- api/src/Accounts/Ldap.php | 18 +++++++++++++++++- api/src/Contacts/Ldap.php | 18 +++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/api/src/Accounts/Ads.php b/api/src/Accounts/Ads.php index 91efee4b1b..dbfe9424ab 100644 --- a/api/src/Accounts/Ads.php +++ b/api/src/Accounts/Ads.php @@ -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 ); } -} +} \ No newline at end of file diff --git a/api/src/Accounts/Ldap.php b/api/src/Accounts/Ldap.php index a7359d2bbd..bd183b677e 100644 --- a/api/src/Accounts/Ldap.php +++ b/api/src/Accounts/Ldap.php @@ -1294,6 +1294,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 */ @@ -1302,4 +1318,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']); } -} +} \ No newline at end of file diff --git a/api/src/Contacts/Ldap.php b/api/src/Contacts/Ldap.php index 0c2166d4da..af40afb50c 100644 --- a/api/src/Contacts/Ldap.php +++ b/api/src/Contacts/Ldap.php @@ -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"); } -} +} \ No newline at end of file