Skip to content
Snippets Groups Projects
Commit e3559a56 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo
Browse files

Solve the problem in issue #594 in a backwards compatible way that doesn't break anything.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3358 44740490-163a-0410-bde0-09ae8108e29a
parent f4860459
No related branches found
No related tags found
No related merge requests found
...@@ -177,7 +177,6 @@ class SimpleSAML_Session { ...@@ -177,7 +177,6 @@ class SimpleSAML_Session {
$this->trackid = substr(md5(uniqid(rand(), true)), 0, 10); $this->trackid = substr(md5(uniqid(rand(), true)), 0, 10);
$this->dirty = TRUE; $this->dirty = TRUE;
$this->addShutdownFunction();
/* Initialize data for session check function if defined */ /* Initialize data for session check function if defined */
$globalConfig = SimpleSAML_Configuration::getInstance(); $globalConfig = SimpleSAML_Configuration::getInstance();
...@@ -189,6 +188,32 @@ class SimpleSAML_Session { ...@@ -189,6 +188,32 @@ class SimpleSAML_Session {
} }
/**
* Destructor for this class. It will save the session to the session handler
* in case the session has been marked as dirty. Do nothing otherwise.
*/
public function __destruct() {
if(!$this->dirty) {
/* Session hasn't changed - don't bother saving it. */
return;
}
$this->dirty = FALSE;
$sh = SimpleSAML_SessionHandler::getSessionHandler();
try {
$sh->saveSession($this);
} catch (Exception $e) {
if (!($e instanceof SimpleSAML_Error_Exception)) {
$e = new SimpleSAML_Error_UnserializableException($e);
}
SimpleSAML_Logger::error('Unable to save session.');
$e->logError();
}
}
/** /**
* Upgrade this session object to use the $authData property. * Upgrade this session object to use the $authData property.
* *
...@@ -247,7 +272,6 @@ class SimpleSAML_Session { ...@@ -247,7 +272,6 @@ class SimpleSAML_Session {
* This function is called after this class has been deserialized. * This function is called after this class has been deserialized.
*/ */
public function __wakeup() { public function __wakeup() {
$this->addShutdownFunction();
/* TODO: Remove for version 1.8. */ /* TODO: Remove for version 1.8. */
if ($this->authData === NULL) { if ($this->authData === NULL) {
...@@ -1166,42 +1190,6 @@ class SimpleSAML_Session { ...@@ -1166,42 +1190,6 @@ class SimpleSAML_Session {
} }
/**
* Save the session to the session handler.
*
* This function will check the dirty-flag to check if the session has changed.
*/
public function saveSession() {
if(!$this->dirty) {
/* Session hasn't changed - don't bother saving it. */
return;
}
$this->dirty = FALSE;
$sh = SimpleSAML_SessionHandler::getSessionHandler();
try {
$sh->saveSession($this);
} catch (Exception $e) {
if (!($e instanceof SimpleSAML_Error_Exception)) {
$e = new SimpleSAML_Error_UnserializableException($e);
}
SimpleSAML_Logger::error('Unable to save session.');
$e->logError();
}
}
/**
* Add a shutdown function for saving this session object on exit.
*/
private function addShutdownFunction() {
register_shutdown_function(array($this, 'saveSession'));
}
/** /**
* Set the logout state for this session. * Set the logout state for this session.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment