Bugfix: TypeError: Return value of PdoAddressBook::davClientRequest()

For #79
This commit is contained in:
djmaze 2021-04-16 11:57:06 +02:00
parent 31bc2850de
commit f36ef03c1e
2 changed files with 12 additions and 14 deletions

View file

@ -79,7 +79,7 @@ trait CardDAV
return $mResult; return $mResult;
} }
protected function davClientRequest(DAVClient $oClient, string $sCmd, string $sUrl, $mData = null) : ?array protected function davClientRequest(DAVClient $oClient, string $sCmd, string $sUrl, $mData = null) : ?\SnappyMail\HTTP\Response
{ {
\MailSo\Base\Utils::ResetTimeLimit(); \MailSo\Base\Utils::ResetTimeLimit();
@ -91,18 +91,17 @@ trait CardDAV
// $this->oLogger->Write($mData, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); // $this->oLogger->Write($mData, \MailSo\Log\Enumerations\Type::INFO, 'DAV');
// } // }
$aResponse = null;
try try
{ {
if (('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData) if (('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData)
{ {
$aResponse = $oClient->request($sCmd, $sUrl, $mData, array( return $oClient->request($sCmd, $sUrl, $mData, array(
'Content-Type' => 'text/vcard; charset=utf-8' 'Content-Type' => 'text/vcard; charset=utf-8'
)); ));
} }
else else
{ {
$aResponse = $oClient->request($sCmd, $sUrl); return $oClient->request($sCmd, $sUrl);
} }
// if ('GET' === $sCmd) // if ('GET' === $sCmd)
@ -115,7 +114,7 @@ trait CardDAV
$this->oLogger->WriteException($oException); $this->oLogger->WriteException($oException);
} }
return $aResponse; return null;
} }
private function detectionPropFind(DAVClient $oClient, string $sPath) : ?array private function detectionPropFind(DAVClient $oClient, string $sPath) : ?array

View file

@ -185,9 +185,9 @@ class PdoAddressBook
if (0 < \strlen($mExsistenRemoteID)) if (0 < \strlen($mExsistenRemoteID))
{ {
$oResponse = $this->davClientRequest($oClient, 'GET', $sPath.$mExsistenRemoteID); $oResponse = $this->davClientRequest($oClient, 'GET', $sPath.$mExsistenRemoteID);
if ($oResponse && isset($oResponse['headers'], $oResponse['body'])) if ($oResponse)
{ {
$sExsistensBody = \trim($oResponse['body']); $sExsistensBody = \trim($oResponse->body);
} }
// $this->oLogger->WriteDump($sExsistensBody); // $this->oLogger->WriteDump($sExsistensBody);
@ -196,11 +196,10 @@ class PdoAddressBook
$oResponse = $this->davClientRequest($oClient, 'PUT', $oResponse = $this->davClientRequest($oClient, 'PUT',
$sPath.(0 < \strlen($mExsistenRemoteID) ? $mExsistenRemoteID : $oContact->CardDavNameUri()), $sPath.(0 < \strlen($mExsistenRemoteID) ? $mExsistenRemoteID : $oContact->CardDavNameUri()),
$oContact->ToVCard($sExsistensBody, $this->oLogger)."\r\n\r\n"); $oContact->ToVCard($sExsistensBody, $this->oLogger)."\r\n\r\n");
if ($oResponse)
if ($oResponse && isset($oResponse['headers'], $oResponse['headers']['etag']))
{ {
$sEtag = \trim(\trim($oResponse['headers']['etag']), '"\''); $sEtag = \trim(\trim($oResponse->getHeader('etag')), '"\'');
$sDate = !empty($oResponse['headers']['date']) ? \trim($oResponse['headers']['date']) : ''; $sDate = \trim($oResponse->getHeader('date'));
if (!empty($sEtag)) if (!empty($sEtag))
{ {
$iChanged = empty($sDate) ? \time() : \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDate); $iChanged = empty($sDate) ? \time() : \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDate);
@ -227,9 +226,9 @@ class PdoAddressBook
$aDatabaseSyncData[$sKey]['id_contact'] : ''; $aDatabaseSyncData[$sKey]['id_contact'] : '';
$oResponse = $this->davClientRequest($oClient, 'GET', $sPath.$aData['vcf']); $oResponse = $this->davClientRequest($oClient, 'GET', $sPath.$aData['vcf']);
if ($oResponse && isset($oResponse['headers'], $oResponse['body'])) if ($oResponse)
{ {
$sBody = \trim($oResponse['body']); $sBody = \trim($oResponse->body);
if (!empty($sBody)) if (!empty($sBody))
{ {
$oContact = null; $oContact = null;
@ -244,7 +243,7 @@ class PdoAddressBook
} }
$oContact->PopulateByVCard($aData['uid'], $sBody, $oContact->PopulateByVCard($aData['uid'], $sBody,
!empty($oResponse['headers']['etag']) ? \trim(\trim($oResponse['headers']['etag']), '"\'') : '', \trim(\trim($oResponse->getHeader('etag')), '"\''),
$this->oLogger); $this->oLogger);
$this->ContactSave($sEmail, $oContact); $this->ContactSave($sEmail, $oContact);