diff --git a/modules/consent/docs/consent.txt b/modules/consent/docs/consent.txt index 092843e3ff46123d45e792e6483a8a442fbea6de..f156a10e4d428dba209566513783082dfe136f98 100644 --- a/modules/consent/docs/consent.txt +++ b/modules/consent/docs/consent.txt @@ -98,6 +98,9 @@ The `consent:Database` backend storage has the following options : Name of the table used for storing the consents. This option is optional and defaults to `consent`. +`timeout` +: The number of seconds to wait for a connection to the database server. This option is optional. If unset, it uses the default from the database-driver. + Example config using PostgreSQL database: 90 => array( diff --git a/modules/consent/lib/Consent/Store/Database.php b/modules/consent/lib/Consent/Store/Database.php index 5ec4a46586951263ff34131d658c8dbfa8b95390..ad69a911166acf201bdab7be60f2abc8ea8d69d7 100644 --- a/modules/consent/lib/Consent/Store/Database.php +++ b/modules/consent/lib/Consent/Store/Database.php @@ -39,6 +39,13 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store */ private $_table; + /** + * The timeout of the database connection. + * + * @var int|NULL + */ + private $_timeout = NULL; + /** * Database handle. * @@ -86,6 +93,15 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store $this->_table = 'consent'; } + if (isset($config['timeout'])) { + if (!is_int($config['timeout'])) { + throw new Exception( + 'consent:Database - \'timeout\' is supposed to be an integer.' + ); + } + $this->_timeout = $config['timeout']; + } + // @TODO Should be removed $db = $this->_getDB(); } @@ -447,9 +463,14 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store return $this->_db; } + $driver_options = array(); + if (isset($this->_timeout)) { + $driver_options[PDO::ATTR_TIMEOUT] = $this->_timeout; + } + // @TODO Cleanup this section //try { - $this->_db = new PDO($this->_dsn, $this->_username, $this->_password); + $this->_db = new PDO($this->_dsn, $this->_username, $this->_password, $driver_options); // } catch (PDOException $e) { // SimpleSAML_Logger::error('consent:Database - Failed to connect to \'' . // $this->_dsn . '\': '. $e->getMessage());