Skip to content

Commit

Permalink
Empty system addressbook instead of removing it
Browse files Browse the repository at this point in the history
This makes Federated Cloud Sharing not fail when synching trusted
servers addressbooks (only synching an empty one, not bumping on an
non-existent one).

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Feb 4, 2019
1 parent a9002a2 commit 10caa17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,30 @@ function deleteAddressBook($addressBookId) {
$query->delete($this->dbCardsPropertiesTable)
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
}

/**
* Delete all the content from an addressbook
*
* @param mixed $addressBookId
* @return void
*/
public function emptyAddressBook($addressBookId): void
{
$query = $this->db->getQueryBuilder();
$query->delete('cards')
->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid')))
->setParameter('addressbookid', $addressBookId)
->execute();

$query->delete('addressbookchanges')
->where($query->expr()->eq('addressbookid', $query->createParameter('addressbookid')))
->setParameter('addressbookid', $addressBookId)
->execute();

$query->delete($this->dbCardsPropertiesTable)
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->execute();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,6 @@ public function syncInstance(\Closure $progressCallback = null) {
public function purgeSystemAddressBook(): void
{
$systemAddressBook = $this->getLocalSystemAddressBook();
$this->backend->deleteAddressBook($systemAddressBook['id']);
$this->backend->emptyAddressBook($systemAddressBook['id']);
}
}

0 comments on commit 10caa17

Please sign in to comment.