mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
Fix AddressBook structure
This commit is contained in:
parent
aa69772127
commit
733a96a987
3 changed files with 76 additions and 57 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue