From bc2765644db53afcc9b899297e0615af0eeba58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Tue, 17 Feb 2009 09:31:21 +0000 Subject: [PATCH] Add statistics and deleteall functions to consent storage git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1278 44740490-163a-0410-bde0-09ae8108e29a --- modules/consent/lib/Consent/Store/Cookie.php | 11 +++++ .../consent/lib/Consent/Store/Database.php | 44 +++++++++++++++++++ modules/consent/lib/Store.php | 16 +++++++ 3 files changed, 71 insertions(+) diff --git a/modules/consent/lib/Consent/Store/Cookie.php b/modules/consent/lib/Consent/Store/Cookie.php index e65c5ec10..3fbfe5fd5 100644 --- a/modules/consent/lib/Consent/Store/Cookie.php +++ b/modules/consent/lib/Consent/Store/Cookie.php @@ -110,6 +110,17 @@ class sspmod_consent_Consent_Store_Cookie extends sspmod_consent_Store { $this->setConsentCookie($name, NULL); } + + /** + * Delete consent. + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + assert('is_string($userId)'); + + throw new Exception('The cookie consent handler does not support to delete all consents...'); + } /** diff --git a/modules/consent/lib/Consent/Store/Database.php b/modules/consent/lib/Consent/Store/Database.php index 7138a9971..2b7ca8104 100644 --- a/modules/consent/lib/Consent/Store/Database.php +++ b/modules/consent/lib/Consent/Store/Database.php @@ -242,6 +242,25 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { } } + /** + * Delete all consents. + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + assert('is_string($userId)'); + + $st = $this->execute('DELETE FROM ' . $this->table . ' WHERE hashed_user_id = ?', array($userId)); + if ($st === FALSE) return; + + if ($st->rowCount() > 0) { + SimpleSAML_Logger::debug('consent:Database - Deleted (' . $st->rowCount() . ') consent(s).'); + return $st->rowCount(); + } else { + SimpleSAML_Logger::warning('consent:Database - Attempted to delete nonexistent consent'); + } + } + /** * Retrieve consents. @@ -307,6 +326,31 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { } + /** + * get statistics + * + */ + public function getStatistics() { + $ret = array(); + + $st = $this->execute('select count(*) as no from consent', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['total'] = $row[0]; + + $st = $this->execute('select count(*) as no from (select distinct hashed_user_id from consent ) as foo', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['users'] = $row[0]; + + $st = $this->execute('select count(*) as no from (select distinct service_id from consent ) as foo', array()); + if ($st === FALSE) return array(); + if($row = $st->fetch(PDO::FETCH_NUM)) $ret['services'] = $row[0]; + + return $ret; + } + + + + /** * Create consent table. * diff --git a/modules/consent/lib/Store.php b/modules/consent/lib/Store.php index c4ffe233f..a6ba0a795 100644 --- a/modules/consent/lib/Store.php +++ b/modules/consent/lib/Store.php @@ -60,6 +60,22 @@ abstract class sspmod_consent_Store { abstract public function deleteConsent($userId, $destinationId); + /** + * Delete all consents. + * + * Called when a user revokes all consents + * + * @param string $userId The hash identifying the user at an IdP. + */ + public function deleteAllConsents($userId) { + throw new Exception('Not implemented: deleteAllConsents()'); + } + + + public function getStatistics() { + throw new Exception('Not implemented: getStatistics()'); + } + /** * Retrieve consents. * -- GitLab