commit
ccfbc13a38
|
@ -33,7 +33,23 @@ class DbResourceForm extends Form
|
||||||
if (Platform::hasPostgresqlSupport()) {
|
if (Platform::hasPostgresqlSupport()) {
|
||||||
$dbChoices['pgsql'] = 'PostgreSQL';
|
$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(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
'name',
|
'name',
|
||||||
|
@ -68,11 +84,11 @@ class DbResourceForm extends Form
|
||||||
'number',
|
'number',
|
||||||
'port',
|
'port',
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
|
||||||
'preserveDefault' => true,
|
|
||||||
'label' => $this->translate('Port'),
|
|
||||||
'description' => $this->translate('The port to use'),
|
'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(
|
$this->addElement(
|
||||||
|
@ -103,6 +119,17 @@ class DbResourceForm extends Form
|
||||||
'description' => $this->translate('The password to use for authentication')
|
'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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,10 +236,10 @@ class ResourceConfigForm extends ConfigForm
|
||||||
'livestatus' => 'Livestatus',
|
'livestatus' => 'Livestatus',
|
||||||
'ssh' => $this->translate('SSH Identity'),
|
'ssh' => $this->translate('SSH Identity'),
|
||||||
);
|
);
|
||||||
if ($resourceType === 'ldap' || Platform::extensionLoaded('ldap')) {
|
if ($resourceType === 'ldap' || Platform::hasLdapSupport()) {
|
||||||
$resourceTypes['ldap'] = 'LDAP';
|
$resourceTypes['ldap'] = 'LDAP';
|
||||||
}
|
}
|
||||||
if ($resourceType === 'db' || Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
|
if ($resourceType === 'db' || Platform::hasDatabaseSupport()) {
|
||||||
$resourceTypes['db'] = $this->translate('SQL Database');
|
$resourceTypes['db'] = $this->translate('SQL Database');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,6 +318,41 @@ class Platform
|
||||||
return false;
|
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
|
* 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 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
|
* 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(
|
private static $driverOptions = array(
|
||||||
PDO::ATTR_TIMEOUT => 10,
|
PDO::ATTR_TIMEOUT => 10,
|
||||||
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||||
// TODO: allow configurable PDO::ATTR_PERSISTENT => true
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,11 +130,16 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
||||||
'username' => $this->config->username,
|
'username' => $this->config->username,
|
||||||
'password' => $this->config->password,
|
'password' => $this->config->password,
|
||||||
'dbname' => $this->config->dbname,
|
'dbname' => $this->config->dbname,
|
||||||
|
'persistent' => (bool) $this->config->get('persistent', false),
|
||||||
'options' => & $genericAdapterOptions,
|
'options' => & $genericAdapterOptions,
|
||||||
'driver_options' => & $driverOptions
|
'driver_options' => & $driverOptions
|
||||||
);
|
);
|
||||||
$this->dbType = strtolower($this->config->get('db', 'mysql'));
|
$this->dbType = strtolower($this->config->get('db', 'mysql'));
|
||||||
switch ($this->dbType) {
|
switch ($this->dbType) {
|
||||||
|
case 'mssql':
|
||||||
|
$adapter = 'Pdo_Mssql';
|
||||||
|
$adapterParamaters['pdoType'] = $this->config->get('pdoType', 'dblib');
|
||||||
|
break;
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
$adapter = 'Pdo_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\';';
|
. 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\';';
|
||||||
$adapterParamaters['port'] = $this->config->get('port', 3306);
|
$adapterParamaters['port'] = $this->config->get('port', 3306);
|
||||||
break;
|
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':
|
case 'pgsql':
|
||||||
$adapter = 'Pdo_Pgsql';
|
$adapter = 'Pdo_Pgsql';
|
||||||
$adapterParamaters['port'] = $this->config->get('port', 5432);
|
$adapterParamaters['port'] = $this->config->get('port', 5432);
|
||||||
break;
|
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:
|
default:
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
'Backend "%s" is not supported',
|
'Backend "%s" is not supported',
|
||||||
|
|
|
@ -134,8 +134,8 @@ class Number extends FormElement
|
||||||
{
|
{
|
||||||
$this->setValue($value);
|
$this->setValue($value);
|
||||||
$value = $this->getValue();
|
$value = $this->getValue();
|
||||||
if (! is_numeric($value)) {
|
if ($this->isRequired() && ! is_numeric($value)) {
|
||||||
$this->addError(sprintf($this->translate('\'%s\' is not a valid number'), $value));
|
$this->addError(sprintf(t('\'%s\' is not a valid number'), $value));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return parent::isValid($value, $context);
|
return parent::isValid($value, $context);
|
||||||
|
|
Loading…
Reference in New Issue