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

Some cleanups. cc @LEDfan

This commit is contained in:
Thomas Tanghus 2014-04-17 04:59:14 +02:00
parent fd2b7423a6
commit f75dee996e
3 changed files with 25 additions and 12 deletions

View File

@ -46,7 +46,7 @@ class AddressbookProvider implements \OCP\IAddressBook {
/**
* Constructor
* @param integer $id
* @param AddressBook $addressBook
*/
public function __construct($addressBook) {
$this->addressBook = $addressBook;

View File

@ -101,7 +101,8 @@ class LocalUsers extends AbstractBackend {
"id" => $addressBookId,
"displayname" => (string)self::$l10n->t('On this %s', array(self::$defaults->getName())),
"description" => (string)self::$l10n->t('On this %s', array(self::$defaults->getName())),
"ctag" => time(),
"lastmodified" => time(),
/* FIXME: we need on 'owner' here */
"permissions" => \OCP\PERMISSION_READ,
"backend" => $this->name,
"active" => 1
@ -124,7 +125,7 @@ class LocalUsers extends AbstractBackend {
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return true;
return $contacts;
} else {
while($row = $result->fetchRow()){
$row['permissions'] = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE;
@ -135,7 +136,7 @@ class LocalUsers extends AbstractBackend {
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return array();
return $contacts;
}
}
@ -156,7 +157,7 @@ class LocalUsers extends AbstractBackend {
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return array();
return null;
} else {
$row = $result->fetchRow();
$row['permissions'] = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE;
@ -165,7 +166,7 @@ class LocalUsers extends AbstractBackend {
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return array();
return null;
}
}
@ -182,7 +183,7 @@ class LocalUsers extends AbstractBackend {
$sql = 'INSERT INTO ' . $this->cardsTableName . ' ('
. 'id, '
. 'addressbookid, '
. 'fullname, '
. 'fullname, ' /* Change to displayname*/
. 'carddata, '
. 'lastmodified'
. ') VALUES ('
@ -308,8 +309,8 @@ class LocalUsers extends AbstractBackend {
* This is a hack so backends can have different search functions.
* @return \OCA\Contacts\LocalUsersAddressbookProvider
*/
public function getSearchProvider(){
return new LocalUsersAddressbookProvider($this);
public function getSearchProvider($addressBook) {
return new LocalUsersAddressbookProvider($addressBook);
}
/**
@ -408,4 +409,12 @@ class LocalUsers extends AbstractBackend {
return true;
}
}
/**
* Don't cache
*/
public function lastModifiedAddressBook($addressBookId) {
return time();
}
}

View File

@ -52,8 +52,12 @@ class LocalUsersAddressbookProvider implements \OCP\IAddressBook {
*/
private $backend;
public function __construct(LocalUsers $backend) {
$this->backend = $backend;
/**
* Constructor
* @param AddressBook $addressBook
*/
public function __construct(AddressBook $addressBook) {
$this->addressBook = $addressBook;
}
/**
@ -64,7 +68,7 @@ class LocalUsersAddressbookProvider implements \OCP\IAddressBook {
*/
public function search($pattern, $searchProperties, $options) {
// First make sure the database is updated
$this->backend->updateDatabase();
$this->addressBook->getBackend()->updateDatabase();
$ids = array();
$results = array();