Skip to content
Snippets Groups Projects
Commit bc276564 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Add statistics and deleteall functions to consent storage

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1278 44740490-163a-0410-bde0-09ae8108e29a
parent 768ed01a
No related branches found
No related tags found
No related merge requests found
...@@ -111,6 +111,17 @@ class sspmod_consent_Consent_Store_Cookie extends sspmod_consent_Store { ...@@ -111,6 +111,17 @@ class sspmod_consent_Consent_Store_Cookie extends sspmod_consent_Store {
} }
/**
* 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...');
}
/** /**
* Retrieve consents. * Retrieve consents.
......
...@@ -242,6 +242,25 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { ...@@ -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. * Retrieve consents.
...@@ -307,6 +326,31 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store { ...@@ -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. * Create consent table.
* *
......
...@@ -60,6 +60,22 @@ abstract class sspmod_consent_Store { ...@@ -60,6 +60,22 @@ abstract class sspmod_consent_Store {
abstract public function deleteConsent($userId, $destinationId); 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. * Retrieve consents.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment