$this->_conn = $connection;
$this->_base_dn = $base_dn;
- $this->_handleError(
- Horde_Ldap::checkLDAPExtension(),
- Horde_Kolab_Server_Exception::MISSING_LDAP_EXTENSION
- );
+ try {
+ Horde_Ldap::checkLDAPExtension();
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ $e->getMessage(),
+ Horde_Kolab_Server_Exception::MISSING_LDAP_EXTENSION,
+ $e
+ );
+ }
}
/**
} else {
throw new Horde_Kolab_Server_Exception(
'Bind failed!',
- Horde_Kolab_Server_Exception::BIND_FAILED,
+ Horde_Kolab_Server_Exception::SYSTEM,
$e
);
}
array $data
) {
$changes = new Horde_Kolab_Server_Ldap_Changes($object, $data);
- $entry = $this->_conn->getWrite()->getEntry(
- $object->getGuid(), array_keys($data)
- );
- $this->_handleError($entry, Horde_Kolab_Server_Exception::SYSTEM);
- $this->_handleError(
- $this->_conn->getWrite()->modify($entry, $changes->getChangeset()),
- Horde_Kolab_Server_Exception::SYSTEM
- );
+ try {
+ $entry = $this->_conn->getWrite()->getEntry(
+ $object->getGuid(), array_keys($data)
+ );
+ $this->_conn->getWrite()->modify($entry, $changes->getChangeset());
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Saving failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
}
/**
Horde_Kolab_Server_Object_Interface $object,
array $data
) {
- $entry = Horde_Ldap_Entry::createFresh($object->getGuid(), $data);
- $this->_handleError($entry, Horde_Kolab_Server_Exception::SYSTEM);
- $this->_handleError(
- $this->_conn->getWrite()->add($entry),
- Horde_Kolab_Server_Exception::SYSTEM
- );
+ try {
+ $entry = Horde_Ldap_Entry::createFresh($object->getGuid(), $data);
+ $this->_conn->getWrite()->add($entry);
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Adding object failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
}
/**
*/
public function delete($guid)
{
- $this->_handleError(
- $this->_conn->getWrite()->delete($guid),
- Horde_Kolab_Server_Exception::SYSTEM
- );
+ try {
+ $this->_conn->getWrite()->delete($guid);
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Deleting object failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
}
/**
*/
public function rename($guid, $new)
{
- $this->_handleError(
- $this->_conn->getWrite()->move($guid, $new),
- Horde_Kolab_Server_Exception::SYSTEM
- );
+ try {
+ $this->_conn->getWrite()->move($guid, $new);
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Renaming object failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
}
/**
*/
public function getSchema()
{
- $result = $this->_conn->getRead()->schema();
- $this->_handleError($result, Horde_Kolab_Server_Exception::SYSTEM);
- return $result;
+ try {
+ return $this->_conn->getRead()->schema();
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Retrieving the schema failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
}
/**
*/
public function getParentGuid($guid)
{
- $base = Horde_Ldap_Util::ldap_explode_dn(
- $guid,
- array(
- 'casefold' => 'none',
- 'reverse' => false,
- 'onlyvalues' => false
- )
- );
- $this->_handleError($base);
- $id = array_shift($base);
- $parent = Horde_Ldap_Util::canonical_dn(
- $base, array('casefold' => 'none')
- );
- $this->_handleError($parent);
- return $parent;
- }
-
- /**
- * Check for a PEAR Error and convert it to an exception if necessary.
- *
- * @param mixed $result The result to be tested.
- * @param code $code The error code to use in case the result is an error.
- *
- * @return NULL.
- *
- * @throws Horde_Kolab_Server_Exception If the connection failed.
- */
- private function _handleError(
- $result,
- $code = Horde_Kolab_Server_Exception::SYSTEM
- ) {
- if ($result instanceOf PEAR_Error) {
- if ($code == Horde_Kolab_Server_Exception::BIND_FAILED
- && $result->getCode() == 49) {
- throw new Horde_Kolab_Server_Exception_Bindfailed($result, $code);
- } else {
- throw new Horde_Kolab_Server_Exception($result, $code);
- }
+ try {
+ $base = Horde_Ldap_Util::ldap_explode_dn(
+ $guid,
+ array(
+ 'casefold' => 'none',
+ 'reverse' => false,
+ 'onlyvalues' => false
+ )
+ );
+ $id = array_shift($base);
+ $parent = Horde_Ldap_Util::canonical_dn(
+ $base, array('casefold' => 'none')
+ );
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Retrieving the parent object failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
}
+ return $parent;
}
/**
*/
protected function _search($filter, array $params, $base)
{
- $search = $this->_conn->getRead()->search($base, $filter, $params);
- $this->_handleError($search, Horde_Kolab_Server_Exception::SYSTEM);
+ try {
+ $search = $this->_conn->getRead()->search($base, $filter, $params);
+ } catch (Horde_Ldap_Exception $e) {
+ throw new Horde_Kolab_Server_Exception(
+ 'Search failed!',
+ Horde_Kolab_Server_Exception::SYSTEM,
+ $e
+ );
+ }
return new Horde_Kolab_Server_Result_Ldap($search);
}
}
{
public function setUp()
{
- $this->skipIfNoLdap();
-
$this->ldap_read = $this->getMock('Horde_Ldap');
$this->ldap_write = $this->getMock('Horde_Ldap');
$connection = new Horde_Kolab_Server_Connection_Splittedldap(
$this->fail('No exception!');
} catch (Exception $e) {
$this->assertEquals('Bind failed!', $e->getMessage());
- $this->assertEquals(Horde_Kolab_Server_Exception::BIND_FAILED, $e->getCode());
+ $this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode());
}
}
{
$this->ldap_read->expects($this->exactly(1))
->method('search')
- ->will($this->returnValue(new PEAR_Error('Search failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Search failed!')));
try {
$this->assertEquals(array('dn' => 'test'), $this->server->find('(equals=equals)'));
$this->fail('No exception!');
$object = $this->getMock('Horde_Kolab_Server_Object_Interface');
$this->ldap_write->expects($this->exactly(1))
->method('modify')
- ->will($this->returnValue(new PEAR_Error('Saving failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Saving failed!')));
$object->expects($this->exactly(1))
->method('readInternal')
->will($this->returnValue(array()));
$object = $this->getMock('Horde_Kolab_Server_Object_Interface');
$this->ldap_write->expects($this->exactly(1))
->method('add')
- ->will($this->returnValue(new PEAR_Error('Saving failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Saving failed!')));
try {
$this->server->add($object, array('add' => array('dn' => 'test')));
$this->fail('No exception!');
} catch (Exception $e) {
- $this->assertEquals('Saving failed!', $e->getMessage());
+ $this->assertEquals('Adding object failed!', $e->getMessage());
$this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode());
}
}
{
$this->ldap_write->expects($this->exactly(1))
->method('delete')
- ->will($this->returnValue(new PEAR_Error('Deleting failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Deleting failed!')));
try {
$this->server->delete('test');
$this->fail('No exception!');
} catch (Exception $e) {
- $this->assertEquals('Deleting failed!', $e->getMessage());
+ $this->assertEquals('Deleting object failed!', $e->getMessage());
$this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode());
}
}
{
$this->ldap_write->expects($this->exactly(1))
->method('move')
- ->will($this->returnValue(new PEAR_Error('Renaming failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Renaming failed!')));
try {
$this->server->rename('test', 'new');
$this->fail('No exception!');
} catch (Exception $e) {
- $this->assertEquals('Renaming failed!', $e->getMessage());
+ $this->assertEquals('Renaming object failed!', $e->getMessage());
$this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode());
}
}
{
$this->ldap_read->expects($this->exactly(1))
->method('schema')
- ->will($this->returnValue(new PEAR_Error('Schema failed!')));
+ ->will($this->throwException(new Horde_Ldap_Exception('Schema failed!')));
try {
$this->server->getSchema();
$this->fail('No exception!');
} catch (Exception $e) {
- $this->assertEquals('Schema failed!', $e->getMessage());
+ $this->assertEquals('Retrieving the schema failed!', $e->getMessage());
$this->assertEquals(Horde_Kolab_Server_Exception::SYSTEM, $e->getCode());
}
}