1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

More fixes

This commit is contained in:
Thomas Tanghus 2014-03-08 17:37:05 +01:00
parent 403ed682e7
commit f63081a06b
2 changed files with 56 additions and 29 deletions

View File

@ -25,28 +25,30 @@ namespace OCA\Contacts\Backend;
use OCA\Contacts\VObject\VCard;
/**
* Subclass this class for address book backends
*
* The following methods MUST be implemented:
* @method array getAddressBooksForUser(array $options = array())
* @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:
* @method bool hasAddressBook(string $addressbookid)
* @method bool updateAddressBook(string $addressbookid, array $updates, array $options = array())
* @method string createAddressBook(array $properties, array $options = array())
* @method bool deleteAddressBook(string $addressbookid, array $options = array())
* @method int lastModifiedAddressBook(string $addressbookid)
* @method array numContacts(string $addressbookid)
* @method bool updateContact(string $addressbookid, string $id, VCard $contact, array $options = array())
* @method string createContact(string $addressbookid, VCard $contact, array $properties)
* @method bool deleteContact(string $addressbookid, string $id, array $options = array())
* @method int lastModifiedContact(string $addressbookid)
* Subclass this class for address book backends.
*/
abstract class AbstractBackend {
/**
* The following methods MUST be implemented:
*
* @method array getAddressBooksForUser(array $options = array())
* @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:
* @method bool hasAddressBook(string $addressbookid)
* @method bool updateAddressBook(string $addressbookid, array $updates, array $options = array())
* @method string createAddressBook(array $properties, array $options = array())
* @method bool deleteAddressBook(string $addressbookid, array $options = array())
* @method int lastModifiedAddressBook(string $addressbookid)
* @method array numContacts(string $addressbookid)
* @method bool updateContact(string $addressbookid, string $id, VCard $contact, array $options = array())
* @method string createContact(string $addressbookid, VCard $contact, array $properties)
* @method bool deleteContact(string $addressbookid, string $id, array $options = array())
* @method int lastModifiedContact(string $addressbookid)
*/
/**
* The name of the backend.
* @var string
@ -376,6 +378,7 @@ abstract class AbstractBackend {
*
* @param string $addressBookId.
* @param string $contactId.
* @throws \BadMethodCallException
* @return string
*/
protected function combinedKey($addressBookId = null, $contactId = null) {
@ -446,8 +449,8 @@ abstract class AbstractBackend {
* @param array the preferences, format array('param1' => 'value', 'param2' => 'value')
* @return boolean
*/
public function setPreferences($addressbookid, array $params) {
public function setPreferences($addressBookId, array $params) {
$key = $this->combinedKey($addressBookId);
$key = 'prefs_' . $key;

View File

@ -28,7 +28,7 @@ use OCA\Contacts\Contact,
Sabre\VObject\Reader;
/**
* Subclass this class for Contacts backends
* Subclass this class for Contacts backends.
*/
class Database extends AbstractBackend {
@ -36,6 +36,30 @@ class Database extends AbstractBackend {
public $name = 'local';
static private $preparedQueries = array();
/**
* The cached address books.
* @var array[]
*/
public $addressbooks;
/**
* The table that holds the address books.
* @var string
*/
public $addressBooksTableName;
/**
* The table that holds the contact vCards.
* @var string
*/
public $cardsTableName;
/**
* The table that holds the indexed vCard properties.
* @var string
*/
public $indexTableName;
/**
* Sets up the backend
*
@ -123,6 +147,7 @@ class Database extends AbstractBackend {
if (!$row) {
throw new \Exception('Address Book not found', 404);
}
$row['permissions'] = \OCP\PERMISSION_ALL;
$row['backend'] = $this->name;
$this->addressbooks[$addressbookid] = $row;
@ -478,31 +503,30 @@ class Database extends AbstractBackend {
$noCollection = isset($options['noCollection']) ? $options['noCollection'] : false;
$where_query = '`id` = ?';
$whereQuery = '`id` = ?';
if (is_array($id)) {
$where_query = '';
$whereQuery = '';
if (isset($id['id'])) {
$id = $id['id'];
} elseif (isset($id['uri'])) {
$where_query = '`uri` = ?';
$whereQuery = '`uri` = ?';
$id = $id['uri'];
} else {
throw new \Exception(
__METHOD__ . ' If second argument is an array, either \'id\' or \'uri\' has to be set.'
);
return null;
}
}
$ids = array($id);
if (!$noCollection) {
$where_query .= ' AND `addressbookid` = ?';
$whereQuery .= ' AND `addressbookid` = ?';
$ids[] = $addressbookid;
}
try {
$query = 'SELECT `id`, `uri`, `carddata`, `lastmodified`, `addressbookid` AS `parent`, `fullname` AS `displayname` FROM `'
. $this->cardsTableName . '` WHERE ' . $where_query;
$query = 'SELECT `id`, `uri`, `carddata`, `lastmodified`, `addressbookid` AS `parent`, `fullname` AS `displayname` FROM `'
. $this->cardsTableName . '` WHERE ' . $whereQuery;
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute($ids);