mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
rebase
This commit is contained in:
parent
f699812f69
commit
5e95953799
@ -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
|
||||
|
@ -36,9 +36,7 @@ abstract class AbstractBackend {
|
||||
* @method array|null getAddressBook(string $addressbookid, array $options = array())
|
||||
* @method array getContacts(string $addressbookid, array $options = array())
|
||||
* @method array|null getContact(string $addressbookid, mixed $id, array $options = array())
|
||||
*
|
||||
* The following methods MAY be implemented but ONLY if the backend can actually perform the action
|
||||
* as the existence of the methods is used to determine the backends capabilities:
|
||||
* The following methods MAY be implemented:
|
||||
* @method bool hasAddressBook(string $addressbookid)
|
||||
* @method bool updateAddressBook(string $addressbookid, array $updates, array $options = array())
|
||||
* @method string createAddressBook(array $properties, array $options = array())
|
||||
@ -53,26 +51,24 @@ abstract class AbstractBackend {
|
||||
|
||||
/**
|
||||
* The name of the backend.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* The current usert.
|
||||
* @var string
|
||||
*/
|
||||
public $userid;
|
||||
|
||||
protected $possibleContactCapabilities = array(
|
||||
protected $possibleContactPermissions = array(
|
||||
\OCP\PERMISSION_CREATE => 'createContact',
|
||||
\OCP\PERMISSION_READ => 'getContact',
|
||||
\OCP\PERMISSION_UPDATE => 'updateContact',
|
||||
\OCP\PERMISSION_DELETE => 'deleteContact',
|
||||
);
|
||||
|
||||
protected $possibleAddressBookCapabilities = array(
|
||||
protected $possibleAddressBookPermissions = array(
|
||||
\OCP\PERMISSION_CREATE => 'createAddressBook',
|
||||
\OCP\PERMISSION_READ => 'getAddressBook',
|
||||
\OCP\PERMISSION_UPDATE => 'updateAddressBook',
|
||||
@ -88,17 +84,16 @@ abstract class AbstractBackend {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all capabilities for contacts based on what the backend implements.
|
||||
* @brief Get all possible permissions for contacts based on what the backend implements.
|
||||
* @returns bitwise-or'ed actions
|
||||
*
|
||||
* Returns the supported actions as an int to be
|
||||
* compared with \OCP\PERMISSION_CREATE etc.
|
||||
* @see AbstractBackend::hasContactMethodFor()
|
||||
* @returns bitwise-or'ed actions
|
||||
*/
|
||||
protected function getContactCapacilities() {
|
||||
protected function getContactPermissions() {
|
||||
$permissions = 0;
|
||||
|
||||
foreach ($this->possibleContactCapabilities as $permission => $methodName) {
|
||||
foreach ($this->possibleContactPermissions as $permission => $methodName) {
|
||||
if(method_exists($this, $methodName)) {
|
||||
$permissions |= $permission;
|
||||
}
|
||||
@ -110,18 +105,17 @@ abstract class AbstractBackend {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all capabilities for address books based on what the backend implements.
|
||||
* @brief Get all permissions for address book based on what the backend implements.
|
||||
* @returns bitwise-or'ed actions
|
||||
*
|
||||
* Returns the supported actions as int to be
|
||||
* compared with \OCP\PERMISSION_CREATE etc.
|
||||
* @see AbstractBackend::hasAddressBookMethodFor()
|
||||
* @returns bitwise-or'ed actions
|
||||
*/
|
||||
protected function getAddressBookCapabilities() {
|
||||
protected function getAddressBookPermissions() {
|
||||
|
||||
$permissions = 0;
|
||||
|
||||
foreach ($this->possibleAddressBookCapabilities as $permission => $methodName) {
|
||||
foreach ($this->possibleAddressBookPermissions as $permission => $methodName) {
|
||||
if (method_exists($this, $methodName)) {
|
||||
$permissions |= $permission;
|
||||
}
|
||||
@ -134,36 +128,34 @@ abstract class AbstractBackend {
|
||||
|
||||
/**
|
||||
* @brief Check if backend implements action for contacts
|
||||
*
|
||||
* Returns true if the backend supports an action for a given permission
|
||||
* for example \OCP\PERMISSION_CREATE etc.
|
||||
*
|
||||
* @param $permission bitwise-or'ed actions
|
||||
* @param $actions bitwise-or'ed actions
|
||||
* @returns boolean
|
||||
*
|
||||
* Returns the supported actions as int to be
|
||||
* compared with \OCP\PERMISSION_CREATE etc.
|
||||
*/
|
||||
public function hasContactMethodFor($permission) {
|
||||
|
||||
return (bool)($this->getContactCapacilities() & $permission);
|
||||
return (bool)($this->getContactPermissions() & $permission);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if backend implements action for contacts
|
||||
*
|
||||
* Returns true if the backend supports an action for a given permission
|
||||
* for example \OCP\PERMISSION_CREATE etc.
|
||||
*
|
||||
* @param $permission bitwise-or'ed actions
|
||||
* @param $actions bitwise-or'ed actions
|
||||
* @returns boolean
|
||||
*
|
||||
* Returns the supported actions as int to be
|
||||
* compared with \OCP\PERMISSION_CREATE etc.
|
||||
*/
|
||||
public function hasAddressBookMethodFor($permission) {
|
||||
|
||||
return (bool)($this->getAddressBookCapabilities() & $permission);
|
||||
return (bool)($this->getAddressBookPermissions() & $permission);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the backend has the address book
|
||||
* Check if the backend has the address book
|
||||
*
|
||||
* This can be reimplemented in the backend to improve performance.
|
||||
*
|
||||
@ -177,8 +169,7 @@ abstract class AbstractBackend {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of contacts in an address book.
|
||||
*
|
||||
* Returns the number of contacts in an address book.
|
||||
* Implementations can choose to override this method to either
|
||||
* get the result more effectively or to return null if the backend
|
||||
* cannot determine the number.
|
||||
@ -193,13 +184,12 @@ abstract class AbstractBackend {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the list of addressbooks for a specific user.
|
||||
* Returns the list of addressbooks for a specific user.
|
||||
*
|
||||
* The returned arrays MUST contain a unique 'id' for the
|
||||
* backend a string 'displayname' and an integer
|
||||
* 'permissions', and it MAY contain a string 'description'.
|
||||
* backend and a 'displayname', and it MAY contain a
|
||||
* 'description'.
|
||||
*
|
||||
* @see AbstractBackend::getAddressBook()
|
||||
* @param array $options - Optional (backend specific options)
|
||||
* @return array
|
||||
*/
|
||||
@ -211,8 +201,8 @@ abstract class AbstractBackend {
|
||||
* The returned array MUST contain string: 'displayname',string: 'backend'
|
||||
* and integer: 'permissions' value using there ownCloud CRUDS constants
|
||||
* (which MUST be at least \OCP\PERMISSION_READ).
|
||||
* The backend MAY also add the optional entries 'description' and 'owner',
|
||||
* and can add additional entries if needed internally.
|
||||
* Currently the only ones supported are 'displayname' and
|
||||
* 'description', but backends can implement additional.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param array $options - Optional (backend specific options)
|
||||
@ -225,10 +215,9 @@ abstract class AbstractBackend {
|
||||
*
|
||||
* The $properties array contains the changes to be made.
|
||||
*
|
||||
* The backend MUST NOT implement this method if it doesn't support updating,
|
||||
* and the implementation is commented out here intentionally!
|
||||
* Currently the only ones supported are 'displayname' and
|
||||
* 'description', but backends can implement additional.
|
||||
*
|
||||
* @see AbstractBackend::getAddressBook()
|
||||
* @param string $addressBookId
|
||||
* @param array $properties
|
||||
* @param array $options - Optional (backend specific options)
|
||||
@ -239,7 +228,7 @@ abstract class AbstractBackend {
|
||||
/**
|
||||
* Creates a new address book
|
||||
*
|
||||
* Backends that doesn't support adding address books MUST NOT implement this method.
|
||||
* Classes that doesn't support adding address books MUST NOT implement this method.
|
||||
*
|
||||
* Currently the only ones supported are 'displayname' and
|
||||
* 'description', but backends can implement additional.
|
||||
@ -254,7 +243,7 @@ abstract class AbstractBackend {
|
||||
/**
|
||||
* Deletes an entire address book and all its contents
|
||||
*
|
||||
* Backends that doesn't support deleting address books MUST NOT implement this method.
|
||||
* Classes that doesn't support deleting address books MUST NOT implement this method.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param array $options - Optional (backend specific options)
|
||||
@ -290,18 +279,11 @@ abstract class AbstractBackend {
|
||||
* Returns all contacts for a specific addressbook id.
|
||||
*
|
||||
* The returned array MUST contain the unique ID a string value 'id', a string
|
||||
* value 'displayname' and an integer 'permissions' value using there
|
||||
* value 'displayname', a string value 'owner' and an integer 'permissions' value using there
|
||||
* ownCloud CRUDS constants (which MUST be at least \OCP\PERMISSION_READ), and SHOULD
|
||||
* contain the properties of the contact formatted as a vCard 3.0
|
||||
* https://tools.ietf.org/html/rfc2426 mapped to 'carddata' or as an
|
||||
* \OCA\Contacts\VObject\VCard object mapped to 'vcard'.
|
||||
* If the backend supports different ownerships it can add an 'owner' entry.
|
||||
*
|
||||
* NOTE: To improve performance $options can contain the boolean value 'omitdata'
|
||||
* that if true indicates that the backend SHOULD NOT add 'vcard' or 'carddata'.
|
||||
*
|
||||
* NOTE: If the backend doesn't support fetching in batches 'offset' and 'limit'
|
||||
* MUST be ignored and all contacts MUST be returned.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
@ -310,6 +292,9 @@ abstract class AbstractBackend {
|
||||
* 1 => array('id' => 'bbcca2d1535', 'owner' => 'bar', 'permissions' => 32, 'displayname' => 'Jane Doe', 'carddata' => $data)
|
||||
* );
|
||||
*
|
||||
* For contacts that contain loads of data, the 'carddata' or 'vcard' MAY be omitted
|
||||
* as it can be fetched later.
|
||||
*
|
||||
* The following options are supported in the $options array:
|
||||
*
|
||||
* - 'limit': An integer value for the number of contacts to fetch in each call.
|
||||
@ -343,7 +328,7 @@ 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 function createContact($addressbookid, $contact, array $options = array());
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -356,7 +341,7 @@ abstract class AbstractBackend {
|
||||
* @param VCard $contact
|
||||
* @param array $options - Optional options
|
||||
* @return bool
|
||||
public function updateContact($addressBookId, $id, $carddata, array $options = array());
|
||||
public function updateContact($addressbookid, $id, $carddata, array $options = array());
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -368,7 +353,7 @@ abstract class AbstractBackend {
|
||||
* @param mixed $id
|
||||
* @param array $options - Optional options
|
||||
* @return bool
|
||||
public function deleteContact($addressBookId, $id, array $options = array());
|
||||
public function deleteContact($addressbookid, $id, array $options = array());
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -449,11 +434,10 @@ abstract class AbstractBackend {
|
||||
*/
|
||||
public function getPreferences($addressBookId) {
|
||||
|
||||
$key = $this->combinedKey($addressBookId);
|
||||
$key = 'prefs_' . $key;
|
||||
$key = 'prefs_' . $this->combinedKey($addressBookId);
|
||||
|
||||
$data = \OCP\Config::getUserValue($this->userid, 'contacts', $key, false);
|
||||
return $data ? json_decode($data) : array();
|
||||
return $data ? json_decode($data, true) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,18 +446,20 @@ abstract class AbstractBackend {
|
||||
* @param array the preferences, format array('param1' => 'value', 'param2' => 'value')
|
||||
* @return boolean
|
||||
*/
|
||||
public function setPreferences($addressBookId, array $params) {
|
||||
|
||||
$key = $this->combinedKey($addressBookId);
|
||||
$key = 'prefs_' . $key;
|
||||
public function setPreferences($addressbookid, array $params) {
|
||||
$key = 'prefs_' . $this->combinedKey($addressbookid);
|
||||
|
||||
$data = json_encode($params);
|
||||
return $data
|
||||
? \OCP\Config::setUserValue($this->userid, 'contacts', $key, $data)
|
||||
: false;
|
||||
}
|
||||
|
||||
public function getSearchProvider($addressbook) {
|
||||
|
||||
public function removePreferences($addressbookid) {
|
||||
$key = $this->combinedKey($addressbookid);
|
||||
$key = 'prefs_' . $key;
|
||||
|
||||
\OC_Preferences::deleteKey( $this->userid, 'contacts', $key );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user