Bugfix: Admin -> Contacts PDO test failed when using different AddressBookInterface

This commit is contained in:
the-djmaze 2023-01-03 10:37:28 +01:00
parent 27b19ef29d
commit 083b6988ee
2 changed files with 20 additions and 13 deletions

View file

@ -465,13 +465,13 @@ class Actions
return $this->oDomainProvider; return $this->oDomainProvider;
} }
public function AddressBookProvider(?Model\Account $oAccount = null, bool $bForceEnable = false): Providers\AddressBook public function AddressBookProvider(?Model\Account $oAccount = null): Providers\AddressBook
{ {
if (null === $this->oAddressBookProvider) { if (null === $this->oAddressBookProvider) {
$oDriver = null; $oDriver = null;
try { try {
// if ($bForceEnable || $this->oConfig->Get('contacts', 'enable', false)) { // if ($this->oConfig->Get('contacts', 'enable', false)) {
if ($bForceEnable || $this->GetCapa(Enumerations\Capa::CONTACTS)) { if ($this->GetCapa(Enumerations\Capa::CONTACTS)) {
$oDriver = $this->fabrica('address-book', $oAccount); $oDriver = $this->fabrica('address-book', $oAccount);
} }
if ($oAccount && $oDriver) { if ($oAccount && $oDriver) {
@ -479,8 +479,9 @@ class Actions
$oDriver->setDAVClientConfig($this->getContactsSyncData($oAccount)); $oDriver->setDAVClientConfig($this->getContactsSyncData($oAccount));
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
\SnappyMail\LOG::error('AddressBook', $e->getMessage()."\n".$e->getTraceAsString());
$oDriver = null; $oDriver = null;
\SnappyMail\LOG::error('AddressBook', $e->getMessage()); // $oDriver = new Providers\AddressBook\PdoAddressBook();
} }
$this->oAddressBookProvider = new Providers\AddressBook($oDriver); $this->oAddressBookProvider = new Providers\AddressBook($oDriver);
$this->oAddressBookProvider->SetLogger($this->oLogger); $this->oAddressBookProvider->SetLogger($this->oLogger);

View file

@ -75,7 +75,7 @@ class ActionsAdmin extends Actions
$this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy'); $this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy');
$this->setConfigFromParams($oConfig, 'ContactsPdoType', 'contacts', 'type', 'string', function ($sType) use ($self) { $this->setConfigFromParams($oConfig, 'ContactsPdoType', 'contacts', 'type', 'string', function ($sType) use ($self) {
return \RainLoop\Providers\AddressBook\PdoAddressBook::validPdoType($sType); return Providers\AddressBook\PdoAddressBook::validPdoType($sType);
}); });
$this->setConfigFromParams($oConfig, 'CapaAdditionalAccounts', 'webmail', 'allow_additional_accounts', 'bool'); $this->setConfigFromParams($oConfig, 'CapaAdditionalAccounts', 'webmail', 'allow_additional_accounts', 'bool');
@ -141,17 +141,23 @@ class ActionsAdmin extends Actions
$this->IsAdminLoggined(); $this->IsAdminLoggined();
$oConfig = $this->Config(); $oConfig = $this->Config();
$this->setConfigFromParams($oConfig, 'ContactsPdoDsn', 'contacts', 'pdo_dsn', 'string'); $this->setConfigFromParams($oConfig, 'ContactsPdoDsn', 'contacts', 'pdo_dsn', 'string');
$this->setConfigFromParams($oConfig, 'ContactsPdoUser', 'contacts', 'pdo_user', 'string'); $this->setConfigFromParams($oConfig, 'ContactsPdoUser', 'contacts', 'pdo_user', 'string');
$this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy'); $this->setConfigFromParams($oConfig, 'ContactsPdoPassword', 'contacts', 'pdo_password', 'dummy');
$this->setConfigFromParams($oConfig, 'ContactsPdoType', 'contacts', 'type', 'string', function ($sType) {
$self = $this; return Providers\AddressBook\PdoAddressBook::validPdoType($sType);
$this->setConfigFromParams($oConfig, 'ContactsPdoType', 'contacts', 'type', 'string', function ($sType) use ($self) {
return \RainLoop\Providers\AddressBook\PdoAddressBook::validPdoType($sType);
}); });
$sTestMessage = $this->AddressBookProvider(null, true)->Test(); $sTestMessage = '';
try {
$AddressBook = new Providers\AddressBook(new Providers\AddressBook\PdoAddressBook());
$AddressBook->SetLogger($this->oLogger);
$sTestMessage = $AddressBook->Test();
} catch (\Throwable $e) {
\SnappyMail\LOG::error('AddressBook', $e->getMessage()."\n".$e->getTraceAsString());
$sTestMessage = $e->getMessage();
}
return $this->DefaultResponse(array( return $this->DefaultResponse(array(
'Result' => '' === $sTestMessage, 'Result' => '' === $sTestMessage,
'Message' => \MailSo\Base\Utils::Utf8Clear($sTestMessage) 'Message' => \MailSo\Base\Utils::Utf8Clear($sTestMessage)
@ -300,7 +306,7 @@ class ActionsAdmin extends Actions
{ {
$user = (string) $this->GetActionParam('username', ''); $user = (string) $this->GetActionParam('username', '');
$secret = (string) $this->GetActionParam('TOTP', ''); $secret = (string) $this->GetActionParam('TOTP', '');
$issuer = \rawurlencode(\RainLoop\API::Config()->Get('webmail', 'title', 'SnappyMail')); $issuer = \rawurlencode(API::Config()->Get('webmail', 'title', 'SnappyMail'));
$QR = \SnappyMail\QRCode::getMinimumQRCode( $QR = \SnappyMail\QRCode::getMinimumQRCode(
"otpauth://totp/{$issuer}:{$user}?secret={$secret}&issuer={$issuer}", "otpauth://totp/{$issuer}:{$user}?secret={$secret}&issuer={$issuer}",
// "otpauth://totp/{$user}?secret={$secret}", // "otpauth://totp/{$user}?secret={$secret}",
@ -323,7 +329,7 @@ class ActionsAdmin extends Actions
return $sToken; return $sToken;
} }
private function setConfigFromParams(\RainLoop\Config\Application $oConfig, string $sParamName, string $sConfigSector, string $sConfigName, string $sType = 'string', ?callable $mStringCallback = null): void private function setConfigFromParams(Config\Application $oConfig, string $sParamName, string $sConfigSector, string $sConfigName, string $sType = 'string', ?callable $mStringCallback = null): void
{ {
if ($this->HasActionParam($sParamName)) { if ($this->HasActionParam($sParamName)) {
$sValue = $this->GetActionParam($sParamName, ''); $sValue = $this->GetActionParam($sParamName, '');