From 733a96a987a85f1321f2c957c4e08939dd8521c8 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 11 May 2022 13:35:05 +0200 Subject: [PATCH] Fix AddressBook structure --- .../libraries/RainLoop/Common/PdoAbstract.php | 51 ---------------- .../AddressBook/AddressBookInterface.php | 22 +++++++ .../Providers/AddressBook/PdoAddressBook.php | 60 +++++++++++++++++-- 3 files changed, 76 insertions(+), 57 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php index 54de31b80..e3d3cf0f7 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php @@ -237,57 +237,6 @@ abstract class PdoAbstract } } - protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int - { - static $aCache = array(); - if ($bCache && isset($aCache[$sEmail])) - { - return $aCache[$sEmail]; - } - - $sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true); - if (empty($sEmail)) - { - throw new \InvalidArgumentException('Empty Email argument'); - } - - $oStmt = $this->prepareAndExecute('SELECT id_user FROM rainloop_users WHERE rl_email = :rl_email', - array( - ':rl_email' => array($sEmail, \PDO::PARAM_STR) - ) - ); - - $mRow = $oStmt->fetch(\PDO::FETCH_ASSOC); - if ($mRow && isset($mRow['id_user']) && \is_numeric($mRow['id_user'])) - { - $iResult = (int) $mRow['id_user']; - if (0 >= $iResult) - { - throw new \Exception('id_user <= 0'); - } - - if ($bCache) - { - $aCache[$sEmail] = $iResult; - } - - return $iResult; - } - - if (!$bSkipInsert) - { - $oStmt->closeCursor(); - - $oStmt = $this->prepareAndExecute('INSERT INTO rainloop_users (rl_email) VALUES (:rl_email)', - array(':rl_email' => array($sEmail, \PDO::PARAM_STR)) - ); - - return $this->getUserId($sEmail, true); - } - - throw new \Exception('id_user = 0'); - } - public function quoteValue(string $sValue) : string { $oPdo = $this->getPDO(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/AddressBookInterface.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/AddressBookInterface.php index bc4519c7d..7bce55794 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/AddressBookInterface.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/AddressBookInterface.php @@ -5,4 +5,26 @@ namespace RainLoop\Providers\AddressBook; interface AddressBookInterface { public function IsSupported() : bool; + + public function IsSharingAllowed() : bool; + + public function Sync(array $oConfig) : bool; + + public function Export(string $sEmail, string $sType = 'vcf') : bool; + + public function ContactSave(string $sEmail, Classes\Contact $oContact) : bool; + + public function DeleteContacts(string $sEmail, array $aContactIds, bool $bSyncDb = true) : bool; + + public function DeleteAllContacts(string $sEmail, bool $bSyncDb = true) : bool; + + public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array; + + public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false) : ?Classes\Contact; + + public function GetSuggestions(string $sEmail, string $sSearch, int $iLimit = 20) : array; + + public function IncFrec(string $sEmail, array $aEmails, bool $bCreateAuto = true) : bool; + + public function Test() : string; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php index 2a4148df9..1055a9aca 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php @@ -334,12 +334,9 @@ class PdoAddressBook return true; } - public function ContactSave(string $sEmail, Classes\Contact $oContact, bool $bSyncDb = true) : bool + public function ContactSave(string $sEmail, Classes\Contact $oContact) : bool { - if ($bSyncDb) - { - $this->SyncDatabase(); - } + $this->SyncDatabase(); $iUserID = $this->getUserId($sEmail); @@ -1298,7 +1295,7 @@ SQLITEINITIAL; return $aResult; } - public function SyncDatabase() : bool + private function SyncDatabase() : bool { static $mCache = null; if (null !== $mCache) @@ -1398,4 +1395,55 @@ SQLITEINITIAL; { return array($this->sDsnType, $this->sDsn, $this->sUser, $this->sPassword); } + + protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int + { + static $aCache = array(); + if ($bCache && isset($aCache[$sEmail])) + { + return $aCache[$sEmail]; + } + + $sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true); + if (empty($sEmail)) + { + throw new \InvalidArgumentException('Empty Email argument'); + } + + $oStmt = $this->prepareAndExecute('SELECT id_user FROM rainloop_users WHERE rl_email = :rl_email', + array( + ':rl_email' => array($sEmail, \PDO::PARAM_STR) + ) + ); + + $mRow = $oStmt->fetch(\PDO::FETCH_ASSOC); + if ($mRow && isset($mRow['id_user']) && \is_numeric($mRow['id_user'])) + { + $iResult = (int) $mRow['id_user']; + if (0 >= $iResult) + { + throw new \Exception('id_user <= 0'); + } + + if ($bCache) + { + $aCache[$sEmail] = $iResult; + } + + return $iResult; + } + + if (!$bSkipInsert) + { + $oStmt->closeCursor(); + + $oStmt = $this->prepareAndExecute('INSERT INTO rainloop_users (rl_email) VALUES (:rl_email)', + array(':rl_email' => array($sEmail, \PDO::PARAM_STR)) + ); + + return $this->getUserId($sEmail, true); + } + + throw new \Exception('id_user = 0'); + } }