1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-30 19:52:17 +01:00

it's been a long time

This commit is contained in:
babelouest 2014-02-07 15:55:55 -05:00
parent 5eadea76d4
commit 9d83e92cb0
4 changed files with 43 additions and 19 deletions

View File

@ -40,7 +40,7 @@ $principalBackend = new OC_Connector_Sabre_Principal();
$addressbookbackends = array();
$addressbookbackends[] = new OCA\Contacts\Backend\Database(\OCP\User::getUser());
$carddavBackend = new OCA\Contacts\CardDAV\Backend(array('local', 'shared'));
$carddavBackend = new OCA\Contacts\CardDAV\Backend(array('local', 'shared', 'ldap'));
$requestBackend = new OC_Connector_Sabre_Request();
// Root nodes

View File

@ -53,7 +53,7 @@ class App {
* @var array
*/
public static $backendClasses = array(
//'ldap' => 'OCA\Contacts\Backend\Ldap',
'ldap' => 'OCA\Contacts\Backend\Ldap',
'local' => 'OCA\Contacts\Backend\Database',
'shared' => 'OCA\Contacts\Backend\Shared',
);

View File

@ -313,8 +313,8 @@ abstract class AbstractBackend {
* @param VCard $contact
* @param array $options - Optional options
* @return string|bool The identifier for the new contact or false on error.
public function createContact($addressbookid, $contact, array $options = array());
*/
public abstract function createContact($addressbookid, $contact, array $options = array());
/**
* Updates a contact
@ -326,8 +326,8 @@ abstract class AbstractBackend {
* @param VCard $contact
* @param array $options - Optional options
* @return bool
public function updateContact($addressbookid, $id, $carddata, array $options = array());
*/
public abstract function updateContact($addressbookid, $id, $carddata, array $options = array());
/**
* Deletes a contact
@ -338,8 +338,8 @@ abstract class AbstractBackend {
* @param mixed $id
* @param array $options - Optional options
* @return bool
public function deleteContact($addressbookid, $id, array $options = array());
*/
public abstract function deleteContact($addressbookid, $id, array $options = array());
/**
* @brief Get the last modification time for a contact.
@ -414,7 +414,7 @@ abstract class AbstractBackend {
$key = 'prefs_' . $key;
$data = \OCP\Config::getUserValue($this->userid, 'contacts', $key, false);
return $data ? json_decode($data) : array();
return $data ? (array)json_decode($data) : array();
}
/**
@ -424,12 +424,34 @@ abstract class AbstractBackend {
* @return boolean
*/
public function setPreferences($addressbookid, array $params) {
$key = $this->combinedKey($addressBookId);
$key = $this->combinedKey($addressbookid);
$key = 'prefs_' . $key;
$addressbookList = $this->getAddressbookList($params);
if (!in_array($addressbookid, $addressbookList)) {
$addressbookList[] = $addressbookid;
$this->setAddressbookList($addressbookList, $params);
}
$data = json_encode($params);
return $data
? \OCP\Config::setUserValue($this->userid, 'contacts', $key, $data)
: false;
}
protected function setAddressbookList(array $addressbookList, array $params) {
$key = $this->name . "_list";
$data = json_encode($addressbookList);
return $data
? \OCP\Config::setUserValue($this->userid, 'contacts', $key, $data)
: false;
}
protected function getAddressbookList() {
$key = $this->name . "_list";
$data = \OCP\Config::getUserValue($this->userid, 'contacts', $key, false);
return $data ? json_decode($data) : array();
}
}

View File

@ -257,27 +257,28 @@ class Ldap extends AbstractBackend {
*/
public function getAddressBooksForUser(array $options = array()) {
try {
/*try {
if(!isset(self::$preparedQueries['addressbooksforuser'])) {
$sql = 'SELECT `configkey` from *PREFIX*preferences where `configkey` like ?';
$configkeyPrefix = $this->name . "_%_uri";
self::$preparedQueries['addressbooksforuser'] = \OCP\DB::prepare($sql);
error_log("ca farte ? ".$sql." ".$configkeyPrefix);
$result = self::$preparedQueries['addressbooksforuser']->execute(array($configkeyPrefix));
if (\OC_DB::isError($result)) {
\OCP\Util::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return $this->addressbooks;
}
$this->addressbooks = array();
while($row = $result->fetchRow()) {
$id = str_replace("_uri", "", str_replace($this->name."_", "", $row['configkey']));
$this->addressbooks[] = self::getAddressBook($id);
}
return $this->addressbooks;
}
} catch(\Exception $e) {
\OC_Log::write('contacts', __METHOD__.' exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return $this->addressbooks;
}*/
$addressbookidList = $this->getAddressbookList();
$this->addressbooks = array();
foreach($addressbookidList as $addressbookid) {
$this->addressbooks[] = self::getAddressBook($addressbookid);
}
return $this->addressbooks;
}
@ -304,11 +305,11 @@ class Ldap extends AbstractBackend {
$preferences = self::getPreferences($addressbookid);
if ($preferences != false) {
$current = array();
$current['id'] = $addressbookid;
$current['displayname'] = $preferences['displayname'];
$current['description'] = $preferences['description'];
$current['id'] = (string)$addressbookid;
$current['displayname'] = (string)$preferences['displayname'];
$current['description'] = (string)$preferences['description'];
$current['owner'] = $this->userid;
$current['uri'] = $preferences['uri'];
$current['uri'] = (string)$preferences['uri'];
$current['permissions'] = \OCP\PERMISSION_ALL;
$current['lastmodified'] = self::lastModifiedAddressBook($addressbookid);
return $current;
@ -431,7 +432,7 @@ class Ldap extends AbstractBackend {
//OCP\Util::writeLog('contacts_ldap', __METHOD__.' Connector OK', \OC_Log::DEBUG);
$info = self::ldapFindMultiple(
$this->ldapParams['ldapbasednsearch'],
'(objectclass=person)',
$this->ldapParams['ldapfilter'],
$this->connector->getLdapEntries(),
isset($options['offset']) ? $options['offset'] : null,
isset($options['limit']) ? $options['limit'] : null
@ -583,6 +584,7 @@ class Ldap extends AbstractBackend {
* @return bool
*/
public function updateContact($addressbookid, $id, $carddata, array $options = array()) {
error_log("goat power ! $addressbookid, $id, $carddata");
$vcard = \Sabre\VObject\Reader::read($carddata);
if (!is_array($id)) {