* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Server
*/
-class Horde_Kolab_Server_Exception extends Exception
+class Horde_Kolab_Server_Exception extends Horde_Exception
{
+ /**
+ * Constants to define the error type.
+ */
+ const SYSTEM = 1;
+ const EMPTY_RESULT = 2;
+
+ /**
+ * The array of available error messages. These are connected to the error
+ * codes used above and might be used to differentiate between what we show
+ * the user in the frontend and what we actually log in the backend.
+ *
+ * @var array
+ */
+ protected $messages;
+
+ /**
+ * Exception constructor
+ *
+ * @param mixed $message The exception message, a PEAR_Error object, or an
+ * Exception object.
+ * @param mixed $code A numeric error code, or
+ * an array from error_get_last().
+ */
+ public function __construct($message = null, $code = null)
+ {
+ $this->setMessages();
+
+ parent::__construct($message, $code);
+ }
+
+ /**
+ * Initialize the messages handled by this exception.
+ *
+ * @return NULL
+ */
+ protected function setMessages()
+ {
+ $this->messages = array(
+ self::SYSTEM => _("An internal error occured."),
+ self::EMPTY_RESULT => _("No result was found."),
+ );
+ }
}
'options' => array(),
'auto_reconnect' => true);
-
$config = array_merge($base_config, $params);
$this->_base_dn = $config['basedn'];
{
$this->_ldap = Net_LDAP2::connect($this->_config);
if (is_a($this->_ldap, 'PEAR_Error')) {
- throw new Horde_Kolab_Server_Exception($this->_ldap);
+ throw new Horde_Kolab_Server_Exception($this->_ldap,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
}
$result = $this->search(null, $params, $dn);
$data = $result->as_struct();
if (is_a($data, 'PEAR_Error')) {
- throw new Horde_Kolab_Server_Exception($data->getMessage());
+ throw new Horde_Kolab_Server_Exception($data,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
if (empty($data)) {
- throw new Horde_Kolab_Server_Exception(_("Empty result!"));
+ throw new Horde_Kolab_Server_Exception(_("Empty result!"),
+ Horde_Kolab_Server_Exception::EMPTY_RESULT);
}
if (!isset($data[$dn])) {
throw new Horde_Kolab_Server_Exception(sprintf(_("No result found for %s"),
- $dn));
+ $dn),
+ Horde_Kolab_Server_Exception::EMPTY_RESULT);
}
if (is_a($data[$dn], 'PEAR_Error')) {
- throw new Horde_Kolab_Server_Exception($data[$dn]);
+ throw new Horde_Kolab_Server_Exception($data[$dn],
+ Horde_Kolab_Server_Exception::SYSTEM);
}
return $data[$dn];
}
$entry = Net_LDAP2_Entry::createFresh($uid, $data);
$result = $this->_ldap->add($entry);
if ($result instanceOf PEAR_Error) {
- throw new Horde_Kolab_Server_Exception($result->getMessage());
+ throw new Horde_Kolab_Server_Exception($result,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
} else {
$deletes = array();
$result = $this->_ldap->modify($uid, array('delete' => $deletes,
'replace' => $data));
if ($result instanceOf PEAR_Error) {
- throw new Horde_Kolab_Server_Exception($result->getMessage());
+ throw new Horde_Kolab_Server_Exception($result,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
}
+ Horde::logMessage(sprintf('The object \"%s\" has been successfully saved!',
+ $uid),
+ __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ return true;
+ }
+
+ /**
+ * Delete an object.
+ *
+ * @param string $uid The UID of the object to be deleted.
+ *
+ * @return boolean True if saving succeeded.
+ *
+ * @throws Horde_Kolab_Server_Exception
+ */
+ public function delete($uid)
+ {
+ $result = $this->_ldap->delete($uid);
+ if ($result instanceOf PEAR_Error) {
+ throw new Horde_Kolab_Server_Exception($result,
+ Horde_Kolab_Server_Exception::SYSTEM);
+ }
+ Horde::logMessage(sprintf('The object \"%s\" has been successfully deleted!',
+ $uid),
+ __FILE__, __LINE__, PEAR_LOG_DEBUG);
return true;
}
$result = $this->search($filter, $options, $base);
$data = $result->as_struct();
if (is_a($data, 'PEAR_Error')) {
- throw new Horde_Kolab_Server_Exception($data->getMessage());
+ throw new Horde_Kolab_Server_Exception($data,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
if (empty($data)) {
return array();
if (!isset($this->_schema)) {
$result = $this->_ldap->schema();
if ($result instanceOf PEAR_Error) {
- throw new Horde_Kolab_Server_Exception($result->getMessage());
+ throw new Horde_Kolab_Server_Exception($result,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
$this->_schema = &$result;
}
$schema = $this->_getSchema();
$info = $schema->get('objectclass', $objectclass);
if ($info instanceOf PEAR_Error) {
- throw new Horde_Kolab_Server_Exception($info->getMessage());
+ throw new Horde_Kolab_Server_Exception($info,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
return $info;
}
$schema = $this->_getSchema();
$info = $schema->get('attribute', $attribute);
if ($info instanceOf PEAR_Error) {
- throw new Horde_Kolab_Server_Exception($info->getMessage());
+ throw new Horde_Kolab_Server_Exception($info,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
return $info;
}
}
$result = $this->_ldap->search($base, $filter, $params);
if (is_a($result, 'PEAR_Error')) {
- throw new Horde_Kolab_Server_Exception($result->getMessage());
+ throw new Horde_Kolab_Server_Exception($result,
+ Horde_Kolab_Server_Exception::SYSTEM);
}
return $result;
}
{
$object = $this->read($dn, array(Horde_Kolab_Server_Object::ATTRIBUTE_OC));
if (!isset($object[Horde_Kolab_Server_Object::ATTRIBUTE_OC])) {
- throw new Horde_Kolab_Server_Exception(sprintf(_("The object %s has no %s attribute!"),
- $dn, Horde_Kolab_Server_Object::ATTRIBUTE_OC));
+ throw new Horde_Kolab_Server_Exception(sprintf("The object %s has no %s attribute!",
+ $dn, Horde_Kolab_Server_Object::ATTRIBUTE_OC),
+ Horde_Kolab_Server_Exception::SYSTEM);
}
$result = array_map('strtolower',
$object[Horde_Kolab_Server_Object::ATTRIBUTE_OC]);