From: Gunnar Wrobel Date: Fri, 1 May 2009 06:44:42 +0000 (+0200) Subject: Simplify the check for existence of an object. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e22534b956ef34aa2cc8a95f1aa6b8be1f695717;p=horde.git Simplify the check for existence of an object. --- diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php index 4709ccd87..4301f2d73 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php @@ -65,8 +65,6 @@ class Horde_Kolab_Server_Object /** * The cached LDAP result * - * FIXME: Include _ldap here - * * @var mixed */ private $_cache = false; @@ -84,7 +82,7 @@ class Horde_Kolab_Server_Object * * @var boolean */ - private $_exists; + private $_exists = false; /** FIXME: Add an attribute cache for the get() function */ @@ -268,18 +266,11 @@ class Horde_Kolab_Server_Object */ public function exists() { - if (empty($this->uid)) { + try { + return $this->read(); + } catch (Horde_Kolab_Server_Exception $e) { return false; } - if (!isset($this->_exists)) { - try { - $this->read(); - $this->_exists = true; - } catch (Horde_Kolab_Server_Exception $e) { - $this->_exists = false; - } - } - return $this->_exists; } /** @@ -289,13 +280,20 @@ class Horde_Kolab_Server_Object */ protected function read() { - if (!empty($this->attributes)) { - $attributes = array_keys($this->attributes); - } else { - $attributes = null; + if (empty($this->uid)) { + return false; + } + if (empty($this->_exists)) { + if (!empty($this->attributes)) { + $attributes = array_keys($this->attributes); + } else { + $attributes = null; + } + $this->_cache = $this->server->read($this->uid, + $attributes); + $this->_exists = true; } - $this->_cache = $this->server->read($this->uid, - $attributes); + return $this->_exists; } /** @@ -317,9 +315,8 @@ class Horde_Kolab_Server_Object throw new Horde_Kolab_Server_Exception(sprintf(_("Attribute \"%s\" not supported!"), $attr)); } - if (!$this->_cache) { - $this->read(); - } + + $this->exists(); if (!empty($this->attribute_map['derived']) && in_array($attr, $this->attribute_map['derived'])) {