From 59808793445c3725cf0030a241d2e4aea57e9552 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 3 Dec 2013 13:22:04 +0000 Subject: [PATCH] consent: Add selftest()-function to database backend. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3308 44740490-163a-0410-bde0-09ae8108e29a --- .../consent/lib/Consent/Store/Database.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/consent/lib/Consent/Store/Database.php b/modules/consent/lib/Consent/Store/Database.php index a7dcec3a0..e0b44616d 100644 --- a/modules/consent/lib/Consent/Store/Database.php +++ b/modules/consent/lib/Consent/Store/Database.php @@ -511,4 +511,24 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store return $error[0] . ' - ' . $error[2] . ' (' . $error[1] . ')'; } + + /** + * A quick selftest of the consent database. + * + * @return boolen TRUE if OK, FALSE if not. Will throw an exception on connection errors. + */ + public function selftest() + { + $st = $this->_execute( + 'SELECT * FROM ' . $this->_table . ' WHERE hashed_user_id = ? AND service_id = ? AND attribute = ?', + array('test', 'test', 'test') + ); + + if ($st === FALSE) { + /* Normally, the test will fail by an exception, so we won't reach this code. */ + return FALSE; + } + + return TRUE; + } } -- GitLab