Skip to content

Commit

Permalink
Drop unavailable PDO drivers in admin contacts
Browse files Browse the repository at this point in the history
Based on good feedback in issue #11 by @phsc84
  • Loading branch information
djmaze committed Sep 24, 2020
1 parent e174248 commit 578131e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 59 deletions.
57 changes: 14 additions & 43 deletions dev/Settings/Admin/Contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ko from 'ko';
import { settingsSaveHelperSimpleFunction, defautOptionsAfterRender } from 'Common/Utils';

import { SaveSettingsStep, StorageResultType } from 'Common/Enums';
import { i18n } from 'Common/Translator';
import Remote from 'Remote/Admin/Fetch';
import { command } from 'Knoin/Knoin';

Expand All @@ -15,50 +14,22 @@ class ContactsAdminSettings {
this.enableContacts = ko.observable(!!settingsGet('ContactsEnable'));
this.contactsSync = ko.observable(!!settingsGet('ContactsSync'));

const supportedTypes = [],
types = ['sqlite', 'mysql', 'pgsql'],
getTypeName = (name) => {
switch (name) {
case 'sqlite':
name = 'SQLite';
break;
case 'mysql':
name = 'MySQL';
break;
case 'pgsql':
name = 'PostgreSQL';
break;
// no default
}

return name;
};
const supportedTypes = settingsGet('supportedPdoDrivers') || [],
types = [{
id:'sqlite',
name:'SQLite'
},{
id:'mysql',
name:'MySQL'
},{
id:'pgsql',
name:'PostgreSQL'
}].filter(type => supportedTypes.includes(type.id));

if (settingsGet('SQLiteIsSupported')) {
supportedTypes.push('sqlite');
}
if (settingsGet('MySqlIsSupported')) {
supportedTypes.push('mysql');
}
if (settingsGet('PostgreSqlIsSupported')) {
supportedTypes.push('pgsql');
}
this.contactsSupported = 0 < types.length;

this.contactsSupported = 0 < supportedTypes.length;

this.contactsTypes = ko.observableArray([]);
this.contactsTypesOptions = ko.computed(() =>
this.contactsTypes().map(value => {
const disabled = !supportedTypes.includes(value);
return {
'id': value,
'name': getTypeName(value) + (disabled ? ' (' + i18n('HINTS/NOT_SUPPORTED') + ')' : ''),
'disabled': disabled
};
})
);
this.contactsTypesOptions = types;

this.contactsTypes(types);
this.contactsType = ko.observable('');

this.mainContactsType = ko
Expand All @@ -68,7 +39,7 @@ class ContactsAdminSettings {
if (value !== this.contactsType()) {
if (supportedTypes.includes(value)) {
this.contactsType(value);
} else if (supportedTypes.length) {
} else if (types.length) {
this.contactsType('');
}
} else {
Expand Down
5 changes: 1 addition & 4 deletions rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,7 @@ public function AppData(bool $bAdmin, bool $bMobile = false, bool $bMobileDevice
$aResult['VerifySslCertificate'] = (bool) $oConfig->Get('ssl', 'verify_certificate', false);
$aResult['AllowSelfSigned'] = (bool) $oConfig->Get('ssl', 'allow_self_signed', true);

$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : null;
$aResult['MySqlIsSupported'] = \is_array($aDrivers) ? \in_array('mysql', $aDrivers) : false;
$aResult['SQLiteIsSupported'] = \is_array($aDrivers) ? \in_array('sqlite', $aDrivers) : false;
$aResult['PostgreSqlIsSupported'] = \is_array($aDrivers) ? \in_array('pgsql', $aDrivers) : false;
$aResult['supportedPdoDrivers'] = \class_exists('PDO') ? \PDO::getAvailableDrivers() : [];

$aResult['ContactsEnable'] = (bool) $oConfig->Get('contacts', 'enable', false);
$aResult['ContactsSync'] = (bool) $oConfig->Get('contacts', 'allow_sync', false);
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/_source.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ en:
BETA: "beta"
UNSTABLE: "unstable"
WARNING: "Warning!"
NOT_SUPPORTED: "not supported"
REQUIRES_PHP_54: "requires PHP 5.4 or greater"
ERRORS:
DOMAIN_ALREADY_EXISTS: "Domain already exists"
UNKNOWN_ERROR: "Unknown error"
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/de_DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ de_DE:
BETA: "Beta"
UNSTABLE: "Nicht stabil"
WARNING: "Warnung!"
NOT_SUPPORTED: "Nicht unterstützt"
REQUIRES_PHP_54: "PHP 5.4 oder höher ist erforderlich"
ERRORS:
DOMAIN_ALREADY_EXISTS: "Domain existiert bereits"
UNKNOWN_ERROR: "Unbekannter Fehler"
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ en_US:
BETA: "beta"
UNSTABLE: "unstable"
WARNING: "Warning!"
NOT_SUPPORTED: "not supported"
REQUIRES_PHP_54: "requires PHP 5.4 or greater"
ERRORS:
DOMAIN_ALREADY_EXISTS: "Domain already exists"
UNKNOWN_ERROR: "Unknown error"
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/es_ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ es_ES:
BETA: "beta"
UNSTABLE: "inestable"
WARNING: "¡Atención!"
NOT_SUPPORTED: "no soportado"
REQUIRES_PHP_54: "requiere PHP 5.4 o superior"
ERRORS:
DOMAIN_ALREADY_EXISTS: "El Dominio ya existe"
UNKNOWN_ERROR: "Error desconocido"
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ fr_FR:
BETA: "bêta"
UNSTABLE: "instable"
WARNING: "ATTENTION !"
NOT_SUPPORTED: "non supporté"
REQUIRES_PHP_54: "nécessite PHP 5.4 ou supérieur"
ERRORS:
DOMAIN_ALREADY_EXISTS: "Le domaine existe déjà"
UNKNOWN_ERROR: "Erreur inconnue"
Expand Down
2 changes: 0 additions & 2 deletions rainloop/v/0.0.0/app/localization/admin/nl_NL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ nl_NL:
BETA: "bèta"
UNSTABLE: "onstabiel"
WARNING: "Waarschuwing!"
NOT_SUPPORTED: "niet ondersteund"
REQUIRES_PHP_54: "vereist PHP 5.4 of hoger"
ERRORS:
DOMAIN_ALREADY_EXISTS: "Domein bestaat al"
UNKNOWN_ERROR: "Onbekende fout"
Expand Down

0 comments on commit 578131e

Please sign in to comment.