From db63c91869dac10777b5ed4daf99c86b23a84f5c Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 13 May 2009 09:04:32 +0200 Subject: [PATCH] Handling of the CN belongs into the parent class. --- .../lib/Horde/Kolab/Server/Object/Kolab/User.php | 116 --------------------- .../Kolab/Server/Object/Kolabinetorgperson.php | 84 +++++++++++++++ 2 files changed, 84 insertions(+), 116 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php index a9cfa3387..cbdc7f933 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolab/User.php @@ -59,36 +59,6 @@ class Horde_Kolab_Server_Object_Kolab_User extends Horde_Kolab_Server_Object_Kol ); /** - * Initialize the Kolab Object. Provide either the UID or a - * LDAP search result. - * - * @param Horde_Kolab_Server &$db The link into the Kolab db. - * @param string $dn UID of the object. - * @param array $data A possible array of data for the object - */ - public function __construct(&$db, $dn = null, $data = null) - { - global $conf; - - /** Allows to customize the supported user attributes. */ - if (isset($conf['kolab']['server']['user_supported_attrs'])) { - $this->supported_attributes = $conf['kolab']['server']['user_supported_attrs']; - } - - /** Allows to customize the required user attributes. */ - if (isset($conf['kolab']['server']['user_required_attrs'])) { - $this->required_attributes = $conf['kolab']['server']['user_required_attrs']; - } - - /** Allows to customize the user object classes. */ - if (isset($conf['kolab']['server']['user_objectclasses'])) { - $this->object_classes = $conf['kolab']['server']['user_object_classes']; - } - - parent::__construct($db, $dn, $data); - } - - /** * Return the filter string to retrieve this object type. * * @return string The filter to retrieve this object type from the server @@ -193,90 +163,4 @@ class Horde_Kolab_Server_Object_Kolab_User extends Horde_Kolab_Server_Object_Kol { return $this->server->getGroupAddresses($this->uid); } - - /** - * Generates an ID for the given information. - * - * @param array $info The data of the object. - * - * @static - * - * @return string|PEAR_Error The ID. - */ - public function generateId($info) - { - global $conf; - - /** The fields that should get mapped into the user ID. */ - if (isset($conf['kolab']['server']['user_id_mapfields'])) { - $id_mapfields = $conf['kolab']['server']['user_id_mapfields']; - } else { - $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, - self::ATTRIBUTE_SN); - } - - /** The user ID format. */ - if (isset($conf['kolab']['server']['user_id_format'])) { - $id_format = $conf['kolab']['server']['user_id_format']; - } else { - $id_format = self::ATTRIBUTE_CN . '=' . '%s %s'; - } - - $fieldarray = array(); - foreach ($id_mapfields as $mapfield) { - if (isset($info[$mapfield])) { - $id = $info[$mapfield]; - if (is_array($id)) { - $id = $id[0]; - } - $fieldarray[] = $this->server->structure->quoteForUid($id); - } else { - $fieldarray[] = ''; - } - } - return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); - } - - /** - * Saves object information. - * - * @param array $info The information about the object. - * - * @return boolean|PEAR_Error True on success. - * - * @throws Horde_Kolab_Server_Exception If the information to be saved is - * invalid. - */ - public function save($info = null) - { - if (!$this->exists()) { - if (!isset($info['cn'])) { - if (!isset($info['sn']) || !isset($info['givenName'])) { - throw new Horde_Kolab_Server_Exception(_("Either the last name or the given name is missing!")); - } else { - $info['cn'] = $this->generateId($info); - } - } - } - - if (isset($conf['kolab']['server']['user_mapping'])) { - $mapped = array(); - $map = $conf['kolab']['server']['user_mapping']; - foreach ($map as $key => $val) { - $mapped[$val] = $info[$key]; - } - $info = $mapped; - } - - if (isset($conf['kolab']['server']['user_mapping'])) { - $mapped = array(); - $map = $conf['kolab']['server']['user_mapping']; - foreach ($map as $key => $val) { - $mapped[$val] = $info[$key]; - } - $info = $mapped; - } - - return parent::save($info); - } }; diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php index f9d7e2c85..f345282cf 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php @@ -200,6 +200,90 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob ); /** + * Generates an ID for the given information. + * + * @param array $info The data of the object. + * + * @static + * + * @return string|PEAR_Error The ID. + */ + public function generateId(&$info) + { + /** + * Never rename the object, even if the components of the CN attribute + * changed + */ + if ($this->exists()) { + return false; + } + return self::ATTRIBUTE_CN . '=' . $this->generateCn($info); + } + + /** + * Generates the common name for the given information. + * + * @param array $info The data of the object. + * + * @return string The common name. + */ + public function generateCn($info) + { + global $conf; + + /** The fields that should get mapped into the user ID. */ + if (isset($conf['kolab']['server']['params']['user_cn_mapfields'])) { + $id_mapfields = $conf['kolab']['server']['params']['user_cn_mapfields']; + } else { + $id_mapfields = array(self::ATTRIBUTE_GIVENNAME, + self::ATTRIBUTE_SN); + } + + /** The user ID format. */ + if (isset($conf['kolab']['server']['params']['user_cn_format'])) { + $id_format = $conf['kolab']['server']['params']['user_cn_format']; + } else { + $id_format = '%s %s'; + } + + $fieldarray = array(); + foreach ($id_mapfields as $mapfield) { + if (isset($info[$mapfield])) { + $id = $info[$mapfield]; + if (is_array($id)) { + $id = $id[0]; + } + $fieldarray[] = $this->server->structure->quoteForUid($id); + } else { + $fieldarray[] = ''; + } + } + return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,"); + } + + /** + * Distill the server side object information to save. + * + * @param array $info The information about the object. + * + * @return NULL. + * + * @throws Horde_Kolab_Server_Exception If the given information contains errors. + */ + public function prepareObjectInformation(&$info) + { + if (!$this->exists()) { + if (!isset($info[self::ATTRIBUTE_CN])) { + if (!isset($info[self::ATTRIBUTE_SN]) || !isset($info[self::ATTRIBUTE_GIVENNAME])) { + throw new Horde_Kolab_Server_Exception(_("Either the last name or the given name is missing!")); + } else { + $info[self::ATTRIBUTE_CN] = $this->generateCn($info); + } + } + } + } + + /** * Return the filter string to retrieve this object type. * * @static -- 2.11.0