DbResourceForm: make the encryption selection a checkbox

refs #11115
This commit is contained in:
Alexander A. Klimov 2016-12-08 17:52:07 +01:00
parent eafb066024
commit e10384770d
3 changed files with 11 additions and 15 deletions

View File

@ -43,7 +43,7 @@ class DbResourceForm extends Form
$dbChoices['oci'] = 'Oracle (OCI8)'; $dbChoices['oci'] = 'Oracle (OCI8)';
} }
$encryptionChoices = array(); $offerSsl = false;
$offerPostgres = false; $offerPostgres = false;
$offerMysql = false; $offerMysql = false;
$dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices); $dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices);
@ -52,7 +52,7 @@ class DbResourceForm extends Form
} elseif ($dbChoice === 'mysql') { } elseif ($dbChoice === 'mysql') {
$offerMysql = true; $offerMysql = true;
if (version_compare(Platform::getPhpVersion(), '5.4.0', '>=')) { if (version_compare(Platform::getPhpVersion(), '5.4.0', '>=')) {
$encryptionChoices['ssl'] = 'SSL'; $offerSsl = true;
} }
} }
@ -156,23 +156,19 @@ class DbResourceForm extends Form
'label' => $this->translate('Persistent') 'label' => $this->translate('Persistent')
) )
); );
if (! empty($encryptionChoices)) { if ($offerSsl) {
$this->addElement( $this->addElement(
'select', 'checkbox',
'encryption', 'use_ssl',
array( array(
'autosubmit' => true, 'autosubmit' => true,
'label' => $this->translate('Encryption'), 'label' => $this->translate('Use SSL'),
'description' => $this->translate( 'description' => $this->translate(
'Whether to encrypt the connection or to authenticate using certificates' 'Whether to encrypt the connection or to authenticate using certificates'
),
'multiOptions' => array_merge(
array('none' => $this->translate('None', 'db connection encryption')),
$encryptionChoices
) )
) )
); );
if (isset($formData['encryption']) && $formData['encryption'] === 'ssl') { if (isset($formData['use_ssl']) && $formData['use_ssl']) {
$this->addElement( $this->addElement(
'text', 'text',
'ssl_key', 'ssl_key',

View File

@ -143,7 +143,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
break; break;
case 'mysql': case 'mysql':
$adapter = 'Pdo_Mysql'; $adapter = 'Pdo_Mysql';
if ($this->config->encryption === 'ssl') { if ($this->config->use_ssl) {
# The presence of these keys as empty strings or null cause non-ssl connections to fail # The presence of these keys as empty strings or null cause non-ssl connections to fail
if ($this->config->ssl_key) { if ($this->config->ssl_key) {
$adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_KEY] = $this->config->ssl_key; $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_KEY] = $this->config->ssl_key;

View File

@ -262,7 +262,7 @@ class DbTool
); );
if ($this->config['db'] === 'mysql') { if ($this->config['db'] === 'mysql') {
if (isset($this->config['encryption']) && $this->config['encryption'] === 'ssl') { if (isset($this->config['use_ssl']) && $this->config['use_ssl']) {
$this->config['driver_options'] = array(); $this->config['driver_options'] = array();
# The presence of these keys as empty strings or null cause non-ssl connections to fail # The presence of these keys as empty strings or null cause non-ssl connections to fail
if ($this->config['ssl_key']) { if ($this->config['ssl_key']) {
@ -312,8 +312,8 @@ class DbTool
if ( if (
$this->config['db'] === 'mysql' $this->config['db'] === 'mysql'
&& isset($this->config['encryption']) && isset($this->config['use_ssl'])
&& $this->config['encryption'] === 'ssl' && $this->config['use_ssl']
) { ) {
# The presence of these keys as empty strings or null cause non-ssl connections to fail # The presence of these keys as empty strings or null cause non-ssl connections to fail
if ($this->config['ssl_key']) { if ($this->config['ssl_key']) {