mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
More fixes
This commit is contained in:
parent
403ed682e7
commit
f63081a06b
@ -25,9 +25,13 @@ namespace OCA\Contacts\Backend;
|
||||
use OCA\Contacts\VObject\VCard;
|
||||
|
||||
/**
|
||||
* Subclass this class for address book backends
|
||||
*
|
||||
* 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())
|
||||
@ -45,8 +49,6 @@ use OCA\Contacts\VObject\VCard;
|
||||
* @method int lastModifiedContact(string $addressbookid)
|
||||
*/
|
||||
|
||||
abstract class AbstractBackend {
|
||||
|
||||
/**
|
||||
* 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,7 +449,7 @@ 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;
|
||||
|
@ -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;
|
||||
. $this->cardsTableName . '` WHERE ' . $whereQuery;
|
||||
$stmt = \OCP\DB::prepare($query);
|
||||
$result = $stmt->execute($ids);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user