Introduce SQLite resource type

refs #3381

Signed-off-by: Eric Lippmann <eric.lippmann@icinga.com>
This commit is contained in:
Uwe Ebel 2018-05-23 19:50:31 +02:00 committed by Eric Lippmann
parent c633c86db7
commit 4b5cf47cce
3 changed files with 122 additions and 90 deletions

View File

@ -45,6 +45,9 @@ class DbResourceForm extends Form
if (Platform::hasOciSupport()) { if (Platform::hasOciSupport()) {
$dbChoices['oci'] = 'Oracle (OCI8)'; $dbChoices['oci'] = 'Oracle (OCI8)';
} }
if (Platform::hasSqliteSupport()) {
$dbChoices['sqlite'] = 'SQLite';
}
$offerPostgres = false; $offerPostgres = false;
$offerIbm = false; $offerIbm = false;
@ -89,117 +92,130 @@ class DbResourceForm extends Form
'multiOptions' => $dbChoices 'multiOptions' => $dbChoices
) )
); );
$this->addElement( if ($dbChoice === 'sqlite') {
'text',
'host',
array (
'required' => true,
'label' => $this->translate('Host'),
'description' => $this->translate('The hostname of the database')
. ($socketInfo ? '. ' . $socketInfo : ''),
'value' => 'localhost'
)
);
$this->addElement(
'number',
'port',
array(
'description' => $this->translate('The port to use'),
'label' => $this->translate('Port'),
'preserveDefault' => true,
'required' => $offerPostgres,
'value' => $offerPostgres ? 5432 : null
)
);
$this->addElement(
'text',
'dbname',
array(
'required' => true,
'label' => $this->translate('Database Name'),
'description' => $this->translate('The name of the database to use')
)
);
$this->addElement(
'text',
'username',
array (
'required' => true,
'label' => $this->translate('Username'),
'description' => $this->translate('The user name to use for authentication')
)
);
$this->addElement(
'password',
'password',
array(
'renderPassword' => true,
'label' => $this->translate('Password'),
'description' => $this->translate('The password to use for authentication')
)
);
$this->addElement(
'text',
'charset',
array (
'description' => $this->translate('The character set for the database'),
'label' => $this->translate('Character Set')
)
);
$this->addElement(
'checkbox',
'use_ssl',
array(
'autosubmit' => true,
'label' => $this->translate('Use SSL'),
'description' => $this->translate(
'Whether to encrypt the connection or to authenticate using certificates'
)
)
);
if (isset($formData['use_ssl']) && $formData['use_ssl']) {
$this->addElement( $this->addElement(
'text', 'text',
'ssl_key', 'dbname',
array( array(
'label' => $this->translate('SSL Key'), 'required' => true,
'description' => $this->translate('The client key file path') 'label' => $this->translate('Database Name'),
'description' => $this->translate('The name of the database to use')
)
);
} else {
$this->addElement(
'text',
'host',
array (
'required' => true,
'label' => $this->translate('Host'),
'description' => $this->translate('The hostname of the database')
. ($socketInfo ? '. ' . $socketInfo : ''),
'value' => 'localhost'
)
);
$this->addElement(
'number',
'port',
array(
'description' => $this->translate('The port to use'),
'label' => $this->translate('Port'),
'preserveDefault' => true,
'required' => $offerPostgres,
'value' => $offerPostgres ? 5432 : null
) )
); );
$this->addElement( $this->addElement(
'text', 'text',
'ssl_cert', 'dbname',
array( array(
'label' => $this->translate('SSL Certificate'), 'required' => true,
'description' => $this->translate('The certificate file path') 'label' => $this->translate('Database Name'),
'description' => $this->translate('The name of the database to use')
) )
); );
$this->addElement( $this->addElement(
'text', 'text',
'ssl_ca', 'username',
array (
'required' => true,
'label' => $this->translate('Username'),
'description' => $this->translate('The user name to use for authentication')
)
);
$this->addElement(
'password',
'password',
array( array(
'label' => $this->translate('SSL CA'), 'required' => true,
'description' => $this->translate('The CA certificate file path') 'renderPassword' => true,
'label' => $this->translate('Password'),
'description' => $this->translate('The password to use for authentication')
) )
); );
$this->addElement( $this->addElement(
'text', 'text',
'ssl_capath', 'charset',
array (
'description' => $this->translate('The character set for the database'),
'label' => $this->translate('Character Set')
)
);
$this->addElement(
'checkbox',
'use_ssl',
array( array(
'label' => $this->translate('SSL CA Path'), 'autosubmit' => true,
'description' => $this->translate( 'label' => $this->translate('Use SSL'),
'The trusted CA certificates in PEM format directory path' 'description' => $this->translate(
'Whether to encrypt the connection or to authenticate using certificates'
) )
) )
); );
$this->addElement( if (isset($formData['use_ssl']) && $formData['use_ssl']) {
'text', $this->addElement(
'ssl_cipher', 'text',
array( 'ssl_key',
'label' => $this->translate('SSL Cipher'), array(
'description' => $this->translate('The list of permissible ciphers') 'label' => $this->translate('SSL Key'),
) 'description' => $this->translate('The client key file path')
); )
);
$this->addElement(
'text',
'ssl_cert',
array(
'label' => $this->translate('SSL Certificate'),
'description' => $this->translate('The certificate file path')
)
);
$this->addElement(
'text',
'ssl_ca',
array(
'label' => $this->translate('SSL CA'),
'description' => $this->translate('The CA certificate file path')
)
);
$this->addElement(
'text',
'ssl_capath',
array(
'label' => $this->translate('SSL CA Path'),
'description' => $this->translate(
'The trusted CA certificates in PEM format directory path'
)
)
);
$this->addElement(
'text',
'ssl_cipher',
array(
'label' => $this->translate('SSL Cipher'),
'description' => $this->translate('The list of permissible ciphers')
)
);
}
} }
return $this; return $this;

View File

@ -420,4 +420,16 @@ class Platform
{ {
return static::extensionLoaded('pdo_pgsql') && static::classExists('Zend_Db_Adapter_Pdo_Pgsql'); return static::extensionLoaded('pdo_pgsql') && static::classExists('Zend_Db_Adapter_Pdo_Pgsql');
} }
/**
* Return whether it's possible to connect to a SQLite database
*
* Checks whether the sqlite pdo extension has been loaded and the Zend framework adapter for SQLite is available
*
* @return bool
*/
public static function hasSqliteSupport()
{
return static::extensionLoaded('pdo_sqlite') && static::classExists('Zend_Db_Adapter_Pdo_Sqlite');
}
} }

View File

@ -224,6 +224,10 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
$adapter = 'Pdo_Ibm'; $adapter = 'Pdo_Ibm';
$defaultPort = 50000; $defaultPort = 50000;
break; break;
case 'sqlite':
$adapter = 'Pdo_Sqlite';
$defaultPort = 0; // Dummy port because a value is required
break;
default: default:
throw new ConfigurationError( throw new ConfigurationError(
'Backend "%s" is not supported', 'Backend "%s" is not supported',