From: Gunnar Wrobel
Date: Mon, 23 Mar 2009 10:27:58 +0000 (+0000)
Subject: Started cleaning up the object class hierarchy. The object classes should not have...
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=cd105f7f137284fd7725ee9aa03274b604f884b1;p=horde.git
Started cleaning up the object class hierarchy. The object classes should not have more knowledge than they need.
---
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
index 500f3bc8e..71eef4eb6 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
@@ -31,36 +31,18 @@ class Horde_Kolab_Server_Object
{
/** Define attributes specific to this object type */
+
+ /** The global ID of this object on the server */
const ATTRIBUTE_UID = 'dn';
+
+ /** The ID part of the UID */
const ATTRIBUTE_ID = 'id';
- const ATTRIBUTE_SID = 'uid';
- const ATTRIBUTE_CN = 'cn';
- const ATTRIBUTE_SN = 'sn';
- const ATTRIBUTE_GIVENNAME = 'givenName';
- const ATTRIBUTE_FN = 'fn';
- const ATTRIBUTE_MAIL = 'mail';
- const ATTRIBUTE_DELEGATE = 'kolabDelegate';
- const ATTRIBUTE_MEMBER = 'member';
- const ATTRIBUTE_VISIBILITY = 'visible';
- const ATTRIBUTE_LNFN = 'lnfn';
- const ATTRIBUTE_FNLN = 'fnln';
- const ATTRIBUTE_DOMAIN = 'domain';
- const ATTRIBUTE_DELETED = 'kolabDeleteFlag';
- const ATTRIBUTE_FBPAST = 'kolabFreeBusyPast';
- const ATTRIBUTE_FBFUTURE = 'kolabFreeBusyFuture';
- const ATTRIBUTE_FOLDERTYPE = 'kolabFolderType';
- const ATTRIBUTE_HOMESERVER = 'kolabHomeServer';
- const ATTRIBUTE_FREEBUSYHOST = 'kolabFreeBusyServer';
- const ATTRIBUTE_IMAPHOST = 'kolabImapServer';
- const ATTRIBUTE_IPOLICY = 'kolabInvitationPolicy';
+
+ /** The attribute holding the object classes */
+ const ATTRIBUTE_OC = 'objectClass';
/** Define the possible Kolab object classes */
- const OBJECTCLASS_TOP = 'top';
- const OBJECTCLASS_INETORGPERSON = 'inetOrgPerson';
- const OBJECTCLASS_KOLABINETORGPERSON = 'kolabInetOrgPerson';
- const OBJECTCLASS_HORDEPERSON = 'hordePerson';
- const OBJECTCLASS_KOLABGROUPOFNAMES = 'kolabGroupOfNames';
- const OBJECTCLASS_KOLABSHAREDFOLDER = 'kolabSharedFolder';
+ const OBJECTCLASS_TOP = 'top';
/**
* Link into the Kolab server.
@@ -88,21 +70,6 @@ class Horde_Kolab_Server_Object
/** FIXME: Add an attribute cache for the get() function */
/**
- * The LDAP filter to retrieve this object type.
- *
- * @var string
- */
- public static $filter = '';
-
- /**
- * The group the UID must be member of so that this object really
- * matches this class type. This may not include the root UID.
- *
- * @var string
- */
- protected $required_group;
-
- /**
* The LDAP attributes supported by this class.
*
* @var array
@@ -110,7 +77,7 @@ class Horde_Kolab_Server_Object
public $supported_attributes = false;
/**
- * Attributes derived from the LDAP values.
+ * Attributes derived from other object attributes.
*
* @var array
*/
@@ -130,14 +97,16 @@ class Horde_Kolab_Server_Object
*
* @var array
*/
- protected $object_classes = array();
+ protected $object_classes = array(
+ self::OBJECTCLASS_TOP
+ );
/**
* Sort by this attributes (must be a LDAP attribute).
*
* @var string
*/
- var $sort_by = self::ATTRIBUTE_SN;
+ var $sort_by = self::ATTRIBUTE_UID;
/**
* Initialize the Kolab Object. Provide either the UID or a
@@ -209,6 +178,19 @@ class Horde_Kolab_Server_Object
}
/**
+ * Return the filter string to retrieve this object type.
+ *
+ * @static
+ *
+ * @return string The filter to retrieve this object type from the server
+ * database.
+ */
+ public static function getFilter()
+ {
+ return '(&(' . self::ATTRIBUTE_OC . '=' . self::OBJECTCLASS_TOP . '))';
+ }
+
+ /**
* Does the object exist?
*
* @return NULL
@@ -231,7 +213,7 @@ class Horde_Kolab_Server_Object
protected function read()
{
$this->_cache = $this->db->read($this->uid,
- $this->supported_attributes);
+ $this->supported_attributes);
}
/**
@@ -247,6 +229,7 @@ class Horde_Kolab_Server_Object
public function get($attr, $single = true)
{
if ($attr != self::ATTRIBUTE_UID) {
+ // FIXME: This wont work this way.
if ($this->supported_attributes !== false
&& !in_array($attr, $this->supported_attributes)
&& !in_array($attr, $this->derived_attributes)) {
@@ -265,8 +248,6 @@ class Horde_Kolab_Server_Object
switch ($attr) {
case self::ATTRIBUTE_UID:
return $this->uid;
- case self::ATTRIBUTE_FN:
- return $this->getFn();
default:
return $this->_get($attr, $single);
}
@@ -304,22 +285,8 @@ class Horde_Kolab_Server_Object
{
switch ($attr) {
case self::ATTRIBUTE_ID:
- $result = split(',', $this->uid);
- if (substr($result[0], 0, 3) == 'cn=') {
- return substr($result[0], 3);
- } else {
- return $result[0];
- }
- case self::ATTRIBUTE_LNFN:
- $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
- $sn = $this->_get(self::ATTRIBUTE_SN, true);
- return sprintf('%s, %s', $sn, $gn);
- case self::ATTRIBUTE_FNLN:
- $gn = $this->_get(self::ATTRIBUTE_GIVENNAME, true);
- $sn = $this->_get(self::ATTRIBUTE_SN, true);
- return sprintf('%s %s', $gn, $sn);
- default:
- return false;
+ return substr($this->uid, 0,
+ strlen($this->uid) - strlen($this->db->getBaseUid()) - 1);
}
}
@@ -355,68 +322,17 @@ class Horde_Kolab_Server_Object
}
/**
- * Get the "first name" attribute of this object
- *
- * FIXME: This should get refactored to be combined with the Id value.
- *
- * @return string the "first name" of this object
- */
- protected function getFn()
- {
- $sn = $this->_get(self::ATTRIBUTE_SN, true);
- $cn = $this->_get(self::ATTRIBUTE_CN, true);
- return trim(substr($cn, 0, strlen($cn) - strlen($sn)));
- }
-
- /**
- * Get the groups for this object
- *
- * @return mixed An array of group ids or a PEAR Error in case of
- * an error.
- */
- public function getGroups()
- {
- return array();
- }
-
- /**
- * Returns the server url of the given type for this user.
- *
- * This method can be used to encapsulate multidomain support.
- *
- * @param string $server_type The type of server URL that should be returned.
- *
- * @return string|PEAR_Error The server url or empty.
- */
- public function getServer($server_type)
- {
- throw new Horde_Kolab_Server_Exception('Not implemented!');
- }
-
- /**
* Generates an ID for the given information.
*
* @param array $info The data of the object.
*
* @static
*
- * @return string|PEAR_Error The ID.
+ * @return string The ID.
*/
public static function generateId($info)
{
- $id_mapfields = array('givenName', 'sn');
- $id_format = '%s %s';
-
- $fieldarray = array();
- foreach ($id_mapfields as $mapfield) {
- if (isset($info[$mapfield])) {
- $fieldarray[] = $info[$mapfield];
- } else {
- $fieldarray[] = '';
- }
- }
-
- return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,");
+ return hash('sha256', uniqid(mt_rand(), true));
}
/**
@@ -437,7 +353,7 @@ class Horde_Kolab_Server_Object
}
}
- $info['objectClass'] = $this->object_classes;
+ $info[self::ATTRIBUTE_OC] = $this->object_classes;
$result = $this->db->save($this->uid, $info);
if ($result === false || is_a($result, 'PEAR_Error')) {
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/address.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/address.php
index e4d8ec6f2..99fb8519b 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/address.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/address.php
@@ -26,24 +26,17 @@
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Server
*/
-class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object_base
{
/**
- * The LDAP filter to retrieve this object type
- *
- * @var string
- */
- public static $filter = '(&(objectclass=inetOrgPerson)(!(uid=*))(sn=*))';
-
- /**
* Attributes derived from the LDAP values.
*
* @var array
*/
public $derived_attributes = array(
- Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
- Horde_Kolab_Server_Object::ATTRIBUTE_FNLN,
+ self::ATTRIBUTE_LNFN,
+ self::ATTRIBUTE_FNLN,
);
/**
@@ -52,12 +45,25 @@ class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
* @var array
*/
protected $object_classes = array(
- Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
- Horde_Kolab_Server_Object::OBJECTCLASS_INETORGPERSON,
- Horde_Kolab_Server_Object::OBJECTCLASS_KOLABINETORGPERSON,
+ self::OBJECTCLASS_TOP,
+ self::OBJECTCLASS_INETORGPERSON,
+ self::OBJECTCLASS_KOLABINETORGPERSON,
);
/**
+ * Return the filter string to retrieve this object type.
+ *
+ * @static
+ *
+ * @return string The filter to retrieve this object type from the server
+ * database.
+ */
+ public static function getFilter()
+ {
+ return '(&(objectclass=inetOrgPerson)(!(uid=*))(sn=*))';
+ }
+
+ /**
* Convert the object attributes to a hash.
*
* @param string $attrs The attributes to return.
@@ -68,7 +74,7 @@ class Horde_Kolab_Server_Object_address extends Horde_Kolab_Server_Object
{
if (!isset($attrs)) {
$attrs = array(
- Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+ self::ATTRIBUTE_LNFN,
);
}
return parent::toHash($attrs);
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/adminrole.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/adminrole.php
index 5230e9180..ade18c1be 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/adminrole.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/adminrole.php
@@ -25,24 +25,17 @@
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Server
*/
-class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
+class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object_base
{
/**
- * The LDAP filter to retrieve this object type
- *
- * @var string
- */
- public static $filter = '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))';
-
- /**
* Attributes derived from the LDAP values.
*
* @var array
*/
public $derived_attributes = array(
- Horde_Kolab_Server_Object::ATTRIBUTE_ID,
- Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+ self::ATTRIBUTE_ID,
+ self::ATTRIBUTE_LNFN,
);
/**
@@ -51,9 +44,9 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
* @var array
*/
protected $object_classes = array(
- Horde_Kolab_Server_Object::OBJECTCLASS_TOP,
- Horde_Kolab_Server_Object::OBJECTCLASS_INETORGPERSON,
- Horde_Kolab_Server_Object::OBJECTCLASS_KOLABINETORGPERSON,
+ self::OBJECTCLASS_TOP,
+ self::OBJECTCLASS_INETORGPERSON,
+ self::OBJECTCLASS_KOLABINETORGPERSON,
);
/**
@@ -65,6 +58,19 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
protected $required_group;
/**
+ * Return the filter string to retrieve this object type.
+ *
+ * @static
+ *
+ * @return string The filter to retrieve this object type from the server
+ * database.
+ */
+ public static function getFilter()
+ {
+ return '(&(cn=*)(objectClass=inetOrgPerson)(!(uid=manager))(sn=*))';
+ }
+
+ /**
* Convert the object attributes to a hash.
*
* @param string $attrs The attributes to return.
@@ -75,8 +81,8 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
{
if (!isset($attrs)) {
$attrs = array(
- Horde_Kolab_Server_Object::ATTRIBUTE_SID,
- Horde_Kolab_Server_Object::ATTRIBUTE_LNFN,
+ self::ATTRIBUTE_SID,
+ self::ATTRIBUTE_LNFN,
);
}
return parent::toHash($attrs);
@@ -111,10 +117,10 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
$parts = split(',', $this->required_group);
list($groupname) = sscanf($parts[0], 'cn=%s');
- $result = $this->db->add(array(Horde_Kolab_Server_Object::ATTRIBUTE_CN => $groupname,
+ $result = $this->db->add(array(self::ATTRIBUTE_CN => $groupname,
'type' => 'Horde_Kolab_Server_Object_group',
- Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members,
- Horde_Kolab_Server_Object::ATTRIBUTE_VISIBILITY => false));
+ self::ATTRIBUTE_MEMBER => $members,
+ self::ATTRIBUTE_VISIBILITY => false));
if (is_a($result, 'PEAR_Error')) {
return $result;
}
@@ -126,7 +132,7 @@ class Horde_Kolab_Server_Object_adminrole extends Horde_Kolab_Server_Object
if ($result === false) {
$members = $admin_group->getMembers();
$members[] = $this->uid;
- $admin_group->save(array(Horde_Kolab_Server_Object::ATTRIBUTE_MEMBER => $members));
+ $admin_group->save(array(self::ATTRIBUTE_MEMBER => $members));
}
}
return parent::save($info);
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php
new file mode 100644
index 000000000..9b59e5982
--- /dev/null
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/base.php
@@ -0,0 +1,124 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Server
+ */
+
+/**
+ * This class provides basic methods common to all Kolab server objects.
+ *
+ * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Server
+ * @author Gunnar Wrobel