Drop unavailable PDO drivers in admin contacts

Based on good feedback in issue #11 by @phsc84
This commit is contained in:
djmaze 2020-09-24 09:58:35 +02:00
parent e174248463
commit 578131e22a
8 changed files with 15 additions and 59 deletions

View file

@ -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';
@ -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
}
const supportedTypes = settingsGet('supportedPdoDrivers') || [],
types = [{
id:'sqlite',
name:'SQLite'
},{
id:'mysql',
name:'MySQL'
},{
id:'pgsql',
name:'PostgreSQL'
}].filter(type => supportedTypes.includes(type.id));
return name;
};
this.contactsSupported = 0 < types.length;
if (settingsGet('SQLiteIsSupported')) {
supportedTypes.push('sqlite');
}
if (settingsGet('MySqlIsSupported')) {
supportedTypes.push('mysql');
}
if (settingsGet('PostgreSqlIsSupported')) {
supportedTypes.push('pgsql');
}
this.contactsTypesOptions = types;
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.contactsTypes(types);
this.contactsType = ko.observable('');
this.mainContactsType = ko
@ -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 {

View file

@ -1326,10 +1326,7 @@ NewThemeLink IncludeCss TemplatesLink LangLink IncludeBackground PluginsLink Aut
$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);

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"