add a shortcut - avoid costly (1sec) discover process if address book uri is known

This commit is contained in:
Alexey Shpakovsky 2021-05-29 16:49:45 +02:00
parent 65bcf54862
commit 94bf6c6fad
No known key found for this signature in database
GPG Key ID: 5797A726A2A4230A
1 changed files with 9 additions and 0 deletions

View File

@ -62,6 +62,13 @@ class abook_carddav extends addressbook_backend {
function open() {
// backend open function
$this->account = new Account(DISCOVERY_URI, USERNAME, PASSWORD);
// Use stored addressbook uri if it exists
if(defined('abook_uri')){
$this->abook = new AddressbookCollection(abook_uri, $this->account);
// TODO: check that it's valid
return true;
}
// Discover the addressbooks for that account
try {
$discover = new Discovery();
@ -73,6 +80,8 @@ class abook_carddav extends addressbook_backend {
return $this->set_error("Cannot proceed because no addressbooks were found - exiting");
}
$this->abook = $abooks[0];
// HINT: use this line to get your discovered addressbook URI
// echo "discovered: " . $this->abook->getUri();
return true;
}