From f70d2c688495ac91799105c4427400a420b87e98 Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 24 Sep 2020 10:22:23 +0200 Subject: [PATCH] Solved more problems of issues #4 --- .../Providers/AddressBook/Classes/Contact.php | 4 +- .../Providers/AddressBook/Classes/Tag.php | 2 +- .../Providers/AddressBook/PdoAddressBook.php | 39 +++++++------------ .../libraries/SabreForRainLoop/DAV/Client.php | 5 +-- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php index e5999be76..7a355f5ec 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Contact.php @@ -479,7 +479,7 @@ class Contact /** * @param mixed $oProp */ - private function addArrayPropertyHelper(array &$aProperties, $oArrayProp, int $iType) : string + private function addArrayPropertyHelper(array &$aProperties, $oArrayProp, int $iType) : void { foreach ($oArrayProp as $oProp) { @@ -501,7 +501,7 @@ class Contact } } - public function PopulateByVCard(string $sUid, string $sVCard, string $sEtag = '', $oLogger = null) + public function PopulateByVCard(string $sUid, string $sVCard, string $sEtag = '', $oLogger = null) : bool { if ("\xef\xbb\xbf" === \substr($sVCard, 0, 3)) { diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Tag.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Tag.php index d417e0963..83c2b7cc1 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Tag.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/Classes/Tag.php @@ -24,7 +24,7 @@ class Tag $this->Clear(); } - public function Clear() + public function Clear() : void { $this->IdContactTag = ''; $this->Name = ''; diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php index 9bc268f95..1fba18443 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php @@ -41,7 +41,7 @@ class PdoAddressBook public function IsSupported() : bool { $aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array(); - return \is_array($aDrivers) ? \in_array($this->sDsnType, $aDrivers) : false; + return \is_array($aDrivers) && \in_array($this->sDsnType, $aDrivers); } public function IsSharingAllowed() : bool @@ -49,14 +49,14 @@ class PdoAddressBook return $this->IsSupported() && false; // TODO } - private function flushDeletedContacts(int $iUserID) + private function flushDeletedContacts(int $iUserID) : bool { return !!$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user AND deleted = 1', array( ':id_user' => array($iUserID, \PDO::PARAM_INT) )); } - private function updateContactEtagAndTime(int $iUserID, int $iID, string $sEtag, int $iChanged) + private function updateContactEtagAndTime(int $iUserID, int $iID, string $sEtag, int $iChanged) : bool { return !!$this->prepareAndExecute('UPDATE rainloop_ab_contacts SET changed = :changed, etag = :etag '. 'WHERE id_user = :id_user AND id_contact = :id_contact', array( @@ -68,7 +68,7 @@ class PdoAddressBook ); } - private function prepearDatabaseSyncData(int $iUserID) + private function prepearDatabaseSyncData(int $iUserID) : array { $aResult = array(); $oStmt = $this->prepareAndExecute('SELECT id_contact, id_contact_str, changed, deleted, etag FROM rainloop_ab_contacts WHERE id_user = :id_user', array( @@ -175,7 +175,7 @@ class PdoAddressBook return $mResult; } - private function davClientRequest($oClient, string $sCmd, string $sUrl, $mData = null) + private function davClientRequest($oClient, string $sCmd, string $sUrl, $mData = null) : ?array { \MailSo\Base\Utils::ResetTimeLimit(); @@ -187,23 +187,23 @@ class PdoAddressBook // $this->oLogger->Write($mData, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); // } - $oResponse = false; + $aResponse = null; try { if (('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData) { - $oResponse = $oClient->request($sCmd, $sUrl, $mData, array( + $aResponse = $oClient->request($sCmd, $sUrl, $mData, array( 'Content-Type' => 'text/vcard; charset=utf-8' )); } else { - $oResponse = $oClient->request($sCmd, $sUrl); + $aResponse = $oClient->request($sCmd, $sUrl); } // if ('GET' === $sCmd) // { -// $this->oLogger->WriteDump($oResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); +// $this->oLogger->WriteDump($aResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); // } } catch (\Throwable $oException) @@ -211,10 +211,10 @@ class PdoAddressBook $this->oLogger->WriteException($oException); } - return $oResponse; + return $aResponse; } - private function detectionPropFind(\SabreForRainLoop\DAV\Client $oClient, string $sPath) : bool + private function detectionPropFind(\SabreForRainLoop\DAV\Client $oClient, string $sPath) : ?array { $aResponse = null; @@ -543,10 +543,9 @@ class PdoAddressBook return null; } - $bGood = false; $sPath = $oClient->__UrlPath__; - $bGood = false; + $bGood = true; if ('' === $sPath || '/' === $sPath || !$this->checkContactsPath($oClient, $sPath)) { $sNewPath = ''; @@ -599,17 +598,8 @@ class PdoAddressBook $bGood = $this->checkContactsPath($oClient, $sPath); } - else - { - $bGood = true; - } - if (!$bGood) - { - $oClient = false; - } - - return $oClient; + return $bGood ? $oClient : null; } public function Sync(string $sEmail, string $sUrl, string $sUser, string $sPassword, string $sProxy = '') : bool @@ -1645,7 +1635,7 @@ class PdoAddressBook return $sResult; } - private function getInitialTablesArray(string $sDbType) + private function getInitialTablesArray(string $sDbType) : array { switch ($sDbType) { @@ -1753,6 +1743,7 @@ SQLITEINITIAL; break; } + $aResult = array(); if (0 < \strlen($sInitial)) { $aList = \explode(';', \trim($sInitial)); diff --git a/rainloop/v/0.0.0/app/libraries/SabreForRainLoop/DAV/Client.php b/rainloop/v/0.0.0/app/libraries/SabreForRainLoop/DAV/Client.php index 37d51d01f..b751993e8 100644 --- a/rainloop/v/0.0.0/app/libraries/SabreForRainLoop/DAV/Client.php +++ b/rainloop/v/0.0.0/app/libraries/SabreForRainLoop/DAV/Client.php @@ -149,7 +149,7 @@ class Client { * @param int $depth * @return array */ - public function propFind($url, array $properties, $depth = 0) { + public function propFind($url, array $properties, $depth = 0) : array { $body = '' . "\n"; $body.= '' . "\n"; @@ -304,9 +304,8 @@ class Client { * @param string $url * @param string $body * @param array $headers - * @return array */ - public function request($method, $url = '', $body = null, $headers = array()) { + public function request($method, $url = '', $body = null, $headers = array()) : array { $url = $this->getAbsoluteUrl($url);