diff --git a/lib/backend/abstractbackend.php b/lib/backend/abstractbackend.php index 609b5db1..1dc186b9 100644 --- a/lib/backend/abstractbackend.php +++ b/lib/backend/abstractbackend.php @@ -248,6 +248,18 @@ abstract class AbstractBackend { public function lastModifiedAddressBook($addressbookid) { } + /** + * @brief 'touch' an address book. + * + * If implemented this method must mark the address books + * modification date so lastModifiedAddressBook() can be + * used to invalidate the cache. + * + * @param string $addressbookid + */ + public function setModifiedAddressBook($addressbookid) { + } + /** * Returns all contacts for a specific addressbook id. * @@ -375,7 +387,7 @@ abstract class AbstractBackend { $key = $this->combinedKey($addressBookId); $key = 'active_' . $key; - return (\OCP\Config::getUserValue($this->userid, 'contacts', $key, 'true') === 'true'); + return !!(\OCP\Config::getUserValue($this->userid, 'contacts', $key, 1)); } /** @@ -388,7 +400,8 @@ abstract class AbstractBackend { $key = $this->combinedKey($addressBookId); $key = 'active_' . $key; - return \OCP\Config::setUserValue($this->userid, 'contacts', $key, $active); + $this->setModifiedAddressBook($addressBookId); + return \OCP\Config::setUserValue($this->userid, 'contacts', $key, (int)$active); } /** diff --git a/lib/backend/database.php b/lib/backend/database.php index e9d029f4..7ad7f892 100644 --- a/lib/backend/database.php +++ b/lib/backend/database.php @@ -324,7 +324,7 @@ class Database extends AbstractBackend { * @param integer $id * @return boolean */ - public function touchAddressBook($id) { + public function setModifiedAddressBook($id) { $query = 'UPDATE `' . $this->addressBooksTableName . '` SET `ctag` = ? + 1 WHERE `id` = ?'; if(!isset(self::$preparedQueries['touchaddressbook'])) { @@ -552,7 +552,7 @@ class Database extends AbstractBackend { } $newid = \OCP\DB::insertid($this->cardsTableName); - $this->touchAddressBook($addressbookid); + $this->setModifiedAddressBook($addressbookid); \OCP\Util::emitHook('OCA\Contacts', 'post_createContact', array('id' => $newid, 'parent' => $addressbookid, 'backend' => $this->name, 'contact' => $contact) ); @@ -636,7 +636,7 @@ class Database extends AbstractBackend { return false; } - $this->touchAddressBook($addressbookid); + $this->setModifiedAddressBook($addressbookid); if(!$isBatch) { \OCP\Util::emitHook('OCA\Contacts', 'post_updateContact', array( @@ -714,7 +714,7 @@ class Database extends AbstractBackend { . $id, \OCP\Util::DEBUG); return false; } - $this->touchAddressBook($addressbookid); + $this->setModifiedAddressBook($addressbookid); return true; }