diff options
author | tailor <cygnus@janrain.com> | 2007-09-25 18:56:38 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2007-09-25 18:56:38 +0000 |
commit | b5e5cd7c3f57c915f16829c95a4cf681032885ee (patch) | |
tree | d604f2ef6dd10281d4c3019975a951f8d9bdfdb5 /Auth | |
parent | b914968d4fcb08550ef0ace91f99f7cd7e212ae0 (diff) | |
download | php-openid-b5e5cd7c3f57c915f16829c95a4cf681032885ee.zip php-openid-b5e5cd7c3f57c915f16829c95a4cf681032885ee.tar.gz php-openid-b5e5cd7c3f57c915f16829c95a4cf681032885ee.tar.bz2 |
[project @ Added store methods cleanupAssociations(), cleanup(), and concrete implementations]
Diffstat (limited to 'Auth')
-rw-r--r-- | Auth/OpenID/FileStore.php | 13 | ||||
-rw-r--r-- | Auth/OpenID/Interface.php | 28 | ||||
-rw-r--r-- | Auth/OpenID/MySQLStore.php | 3 | ||||
-rw-r--r-- | Auth/OpenID/PostgreSQLStore.php | 3 | ||||
-rw-r--r-- | Auth/OpenID/SQLStore.php | 12 | ||||
-rw-r--r-- | Auth/OpenID/SQLiteStore.php | 3 |
6 files changed, 61 insertions, 1 deletions
diff --git a/Auth/OpenID/FileStore.php b/Auth/OpenID/FileStore.php index b53b7d2..b312a66 100644 --- a/Auth/OpenID/FileStore.php +++ b/Auth/OpenID/FileStore.php @@ -612,6 +612,19 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { { return @unlink($filename); } + + function cleanupAssociations() + { + $removed = 0; + foreach ($this->_allAssocs() as $pair) { + list($assoc_filename, $assoc) = $pair; + if ($assoc->getExpiresIn() == 0) { + $this->_removeIfPresent($assoc_filename); + $removed += 1; + } + } + return $removed; + } } ?> diff --git a/Auth/OpenID/Interface.php b/Auth/OpenID/Interface.php index ae86637..c7bbe14 100644 --- a/Auth/OpenID/Interface.php +++ b/Auth/OpenID/Interface.php @@ -65,6 +65,34 @@ class Auth_OpenID_OpenIDStore { "not implemented", E_USER_ERROR); } + /* + * Remove expired associations from the store. + * + * This method is not called in the normal operation of the + * library. It provides a way for store admins to keep their + * storage from filling up with expired data. + * + * @return the number of associations expired. + */ + function cleanupAssociations() + { + trigger_error("Auth_OpenID_OpenIDStore::cleanupAssociations ". + "not implemented", E_USER_ERROR); + } + + /* + * Shortcut for cleanupNonces(), cleanupAssociations(). + * + * This method is not called in the normal operation of the + * library. It provides a way for store admins to keep their + * storage from filling up with expired data. + */ + function cleanup() + { + return array($this->cleanupNonces(), + $this->cleanupAssociations()); + } + /** * This method returns an Association object from storage that * matches the server URL and, if specified, handle. It returns diff --git a/Auth/OpenID/MySQLStore.php b/Auth/OpenID/MySQLStore.php index 04dded8..30e1f59 100644 --- a/Auth/OpenID/MySQLStore.php +++ b/Auth/OpenID/MySQLStore.php @@ -63,6 +63,9 @@ class Auth_OpenID_MySQLStore extends Auth_OpenID_SQLStore { $this->sql['clean_nonce'] = "DELETE FROM %s WHERE timestamp < ?"; + + $this->sql['clean_assoc'] = + "DELETE FROM %s WHERE issued + lifetime < ?"; } /** diff --git a/Auth/OpenID/PostgreSQLStore.php b/Auth/OpenID/PostgreSQLStore.php index 8babed4..15c69ce 100644 --- a/Auth/OpenID/PostgreSQLStore.php +++ b/Auth/OpenID/PostgreSQLStore.php @@ -64,6 +64,9 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore { $this->sql['clean_nonce'] = "DELETE FROM %s WHERE timestamp < ?"; + + $this->sql['clean_assoc'] = + "DELETE FROM %s WHERE issued + lifetime < ?"; } /** diff --git a/Auth/OpenID/SQLStore.php b/Auth/OpenID/SQLStore.php index 4192022..15f7971 100644 --- a/Auth/OpenID/SQLStore.php +++ b/Auth/OpenID/SQLStore.php @@ -265,7 +265,8 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { 'get_assoc', 'get_assocs', 'remove_assoc', - 'get_expired') + 'get_expired', + 'clean_assoc') ) ); @@ -570,6 +571,15 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { $this->connection->commit(); return $num; } + + function cleanupAssociations() + { + $this->connection->query($this->sql['clean_assoc'], + array(time())); + $num = $this->connection->affectedRows(); + $this->connection->commit(); + return $num; + } } ?> diff --git a/Auth/OpenID/SQLiteStore.php b/Auth/OpenID/SQLiteStore.php index a242f9b..b5fd48d 100644 --- a/Auth/OpenID/SQLiteStore.php +++ b/Auth/OpenID/SQLiteStore.php @@ -50,6 +50,9 @@ class Auth_OpenID_SQLiteStore extends Auth_OpenID_SQLStore { $this->sql['clean_nonce'] = "DELETE FROM %s WHERE timestamp < ?"; + + $this->sql['clean_assoc'] = + "DELETE FROM %s WHERE issued + lifetime < ?"; } /** |