forked from andig/carddav2fb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
204 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
use Sabre\VObject\Reader; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\RequestException; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @author Christian Putzke <[email protected]> | ||
|
@@ -50,23 +51,26 @@ class Backend | |
*/ | ||
private $client; | ||
|
||
/** @var OutputInterface */ | ||
private $output; | ||
|
||
/** | ||
* Constructor | ||
* Sets the CardDAV server url | ||
* | ||
* @param string $url CardDAV server url | ||
*/ | ||
public function __construct(string $url=null) | ||
public function __construct(OutputInterface $output, string $url = null) | ||
{ | ||
if ($url) { | ||
$this->setUrl($url); | ||
} | ||
|
||
$this->setClientOptions([ | ||
'headers' => [ | ||
'Depth' => 1 | ||
] | ||
]); | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
|
@@ -152,7 +156,7 @@ public function getVcards(): array | |
]); | ||
} catch (RequestException $e) { | ||
if ($e->hasResponse() && 404 == $e->getResponse()->getStatusCode()) { | ||
error_log('Ignoring empty response from carddav REPORT request'); | ||
$this->output->writeln('<comment>Ignoring empty response from carddav REPORT request</comment>'); | ||
return []; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Andig\CardDav\Backend; | ||
use Sabre\VObject\Document; | ||
use Sabre\VObject\Splitter\VCard; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @author Volker Püschel <[email protected]> | ||
|
@@ -19,9 +20,9 @@ class VcardFile extends Backend | |
*/ | ||
private $fullpath; | ||
|
||
public function __construct(string $fullpath = null) | ||
public function __construct(OutputInterface $output, string $fullpath = null) | ||
{ | ||
parent::__construct(); | ||
parent::__construct($output); | ||
$this->fullpath = $fullpath; | ||
} | ||
|
||
|
@@ -36,12 +37,16 @@ public function getVcards(): array | |
return []; | ||
} | ||
if (!file_exists($this->fullpath)) { | ||
error_log(sprintf('File %s not found!', $this->fullpath)); | ||
$error = sprintf('File %s not found!', $this->fullpath); | ||
$this->output->writeln('<error>' . $error . '</error>'); | ||
|
||
return []; | ||
} | ||
$vcf = fopen($this->fullpath, 'r'); | ||
if (!$vcf) { | ||
error_log(sprintf('File %s open failed!', $this->fullpath)); | ||
$error = sprintf('File %s open failed!', $this->fullpath); | ||
$this->output->writeln('<error>' . $error . '</error>'); | ||
|
||
return []; | ||
} | ||
$cards = []; | ||
|
@@ -50,7 +55,8 @@ public function getVcards(): array | |
if ($vCard instanceof Document) { | ||
$cards[] = $this->enrichVcard($vCard); | ||
} else { | ||
error_log('Unexpected type: ' . get_class($vCard)); | ||
$error = 'Unexpected type: ' . get_class($vCard); | ||
$this->output->writeln('<error>' . $error . '</error>'); | ||
} | ||
|
||
$this->progress(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.