commit
ccfbc13a38
|
@ -33,7 +33,23 @@ class DbResourceForm extends Form
|
|||
if (Platform::hasPostgresqlSupport()) {
|
||||
$dbChoices['pgsql'] = 'PostgreSQL';
|
||||
}
|
||||
|
||||
if (Platform::hasMssqlSupport()) {
|
||||
$dbChoices['mssql'] = 'MSSQL';
|
||||
}
|
||||
if (Platform::hasOracleSupport()) {
|
||||
$dbChoices['oracle'] = 'Oracle';
|
||||
}
|
||||
if (Platform::hasOciSupport()) {
|
||||
$dbChoices['oci'] = 'Oracle (OCI8)';
|
||||
}
|
||||
$offerPostgres = false;
|
||||
if (isset($formData['db'])) {
|
||||
if ($formData['db'] === 'pgsql') {
|
||||
$offerPostgres = true;
|
||||
}
|
||||
} elseif (key($dbChoices) === 'pgsql') {
|
||||
$offerPostgres = true;
|
||||
}
|
||||
$this->addElement(
|
||||
'text',
|
||||
'name',
|
||||
|
@ -68,11 +84,11 @@ class DbResourceForm extends Form
|
|||
'number',
|
||||
'port',
|
||||
array(
|
||||
'required' => true,
|
||||
'preserveDefault' => true,
|
||||
'label' => $this->translate('Port'),
|
||||
'description' => $this->translate('The port to use'),
|
||||
'value' => ! array_key_exists('db', $formData) || $formData['db'] === 'mysql' ? 3306 : 5432
|
||||
'label' => $this->translate('Port'),
|
||||
'preserveDefault' => true,
|
||||
'required' => $offerPostgres,
|
||||
'value' => $offerPostgres ? 5432 : null
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
|
@ -103,6 +119,17 @@ class DbResourceForm extends Form
|
|||
'description' => $this->translate('The password to use for authentication')
|
||||
)
|
||||
);
|
||||
$this->addElement(
|
||||
'checkbox',
|
||||
'persistent',
|
||||
array(
|
||||
'description' => $this->translate(
|
||||
'Check this box for persistent database connections. Persistent connections are not closed at the'
|
||||
. ' end of a request, but are cached and re-used. This is experimental'
|
||||
),
|
||||
'label' => $this->translate('Persistent')
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -236,10 +236,10 @@ class ResourceConfigForm extends ConfigForm
|
|||
'livestatus' => 'Livestatus',
|
||||
'ssh' => $this->translate('SSH Identity'),
|
||||
);
|
||||
if ($resourceType === 'ldap' || Platform::extensionLoaded('ldap')) {
|
||||
if ($resourceType === 'ldap' || Platform::hasLdapSupport()) {
|
||||
$resourceTypes['ldap'] = 'LDAP';
|
||||
}
|
||||
if ($resourceType === 'db' || Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
|
||||
if ($resourceType === 'db' || Platform::hasDatabaseSupport()) {
|
||||
$resourceTypes['db'] = $this->translate('SQL Database');
|
||||
}
|
||||
|
||||
|
|
|
@ -318,6 +318,41 @@ class Platform
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a LDAP server
|
||||
*
|
||||
* Checks whether the ldap extension is loaded
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasLdapSupport()
|
||||
{
|
||||
return static::extensionLoaded('ldap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to any of the supported database servers
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDatabaseSupport()
|
||||
{
|
||||
return static::hasMssqlSupport() || static::hasMysqlSupport() || static::hasOciSupport()
|
||||
|| static::hasOracleSupport() || static::hasPostgresqlSupport();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a MSSQL database
|
||||
*
|
||||
* Checks whether the mssql pdo extension has been loaded and Zend framework adapter for MSSQL is available
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasMssqlSupport()
|
||||
{
|
||||
return static::extensionLoaded('mssql') && static::classExists('Zend_Db_Adapter_Pdo_Mssql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a MySQL database
|
||||
*
|
||||
|
@ -330,6 +365,30 @@ class Platform
|
|||
return static::extensionLoaded('mysql') && static::classExists('Zend_Db_Adapter_Pdo_Mysql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a Oracle database using OCI8
|
||||
*
|
||||
* Checks whether the OCI8 extension has been loaded and the Zend framework adapter for Oracle is available
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasOciSupport()
|
||||
{
|
||||
return static::extensionLoaded('oci8') && static::classExists('Zend_Db_Adapter_Oracle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a Oracle database using PDO_OCI
|
||||
*
|
||||
* Checks whether the OCI PDO extension has been loaded and the Zend framework adapter for Oci is available
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasOracleSupport()
|
||||
{
|
||||
return static::extensionLoaded('pdo_oci') && static::classExists('Zend_Db_Adapter_Pdo_Mysql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether it's possible to connect to a PostgreSQL database
|
||||
*
|
||||
|
|
|
@ -62,8 +62,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
private static $driverOptions = array(
|
||||
PDO::ATTR_TIMEOUT => 10,
|
||||
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
// TODO: allow configurable PDO::ATTR_PERSISTENT => true
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -131,11 +130,16 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
'username' => $this->config->username,
|
||||
'password' => $this->config->password,
|
||||
'dbname' => $this->config->dbname,
|
||||
'persistent' => (bool) $this->config->get('persistent', false),
|
||||
'options' => & $genericAdapterOptions,
|
||||
'driver_options' => & $driverOptions
|
||||
);
|
||||
$this->dbType = strtolower($this->config->get('db', 'mysql'));
|
||||
switch ($this->dbType) {
|
||||
case 'mssql':
|
||||
$adapter = 'Pdo_Mssql';
|
||||
$adapterParamaters['pdoType'] = $this->config->get('pdoType', 'dblib');
|
||||
break;
|
||||
case 'mysql':
|
||||
$adapter = 'Pdo_Mysql';
|
||||
/*
|
||||
|
@ -150,19 +154,21 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
. 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\';';
|
||||
$adapterParamaters['port'] = $this->config->get('port', 3306);
|
||||
break;
|
||||
case 'oci':
|
||||
$adapter = 'Oracle';
|
||||
unset($adapterParamaters['options']);
|
||||
unset($adapterParamaters['driver_options']);
|
||||
$adapterParamaters['driver_options'] = array(
|
||||
'lob_as_string' => true
|
||||
);
|
||||
break;
|
||||
case 'oracle':
|
||||
$adapter = 'Pdo_Oci';
|
||||
break;
|
||||
case 'pgsql':
|
||||
$adapter = 'Pdo_Pgsql';
|
||||
$adapterParamaters['port'] = $this->config->get('port', 5432);
|
||||
break;
|
||||
/*case 'oracle':
|
||||
if ($this->dbtype === 'oracle') {
|
||||
$attributes['persistent'] = true;
|
||||
}
|
||||
$this->db = ZfDb::factory($adapter, $attributes);
|
||||
if ($adapter === 'Oracle') {
|
||||
$this->db->setLobAsString(false);
|
||||
}
|
||||
break;*/
|
||||
default:
|
||||
throw new ConfigurationError(
|
||||
'Backend "%s" is not supported',
|
||||
|
|
|
@ -134,8 +134,8 @@ class Number extends FormElement
|
|||
{
|
||||
$this->setValue($value);
|
||||
$value = $this->getValue();
|
||||
if (! is_numeric($value)) {
|
||||
$this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value));
|
||||
if ($this->isRequired() && ! is_numeric($value)) {
|
||||
$this->addError(sprintf(t('\'%s\' is not a valid number'), $value));
|
||||
return false;
|
||||
}
|
||||
return parent::isValid($value, $context);
|
||||
|
|
Loading…
Reference in New Issue