Skip to content

Commit

Permalink
Added destroy() to Session_Database, see http://github.com/shadowhand…
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Jul 26, 2009
1 parent bcb3edc commit 5f8a4a4
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions classes/kohana/session/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class Kohana_Session_Database extends Session {
// Update the session?
protected $_update = FALSE;

/**
* Loads database-specific configuration data.
*
* @param array configuration
* @return void
*/
public function __construct(array $config = NULL)
{
if ( ! isset($config['group']))
Expand All @@ -50,12 +44,6 @@ public function __construct(array $config = NULL)
parent::__construct($config);
}

/**
* Loads the session contents from the database.
*
* @param string session id
* @return string
*/
public function _read($id = NULL)
{
if ($id OR $id = Cookie::get($this->_name))
Expand All @@ -80,11 +68,6 @@ public function _read($id = NULL)
return NULL;
}

/**
* Generates a new unique session id.
*
* @return string
*/
protected function _regenerate()
{
// Create the query to find an ID
Expand All @@ -104,9 +87,6 @@ protected function _regenerate()
return $this->_session_id = $id;
}

/**
* Inserts or updates the session in the database.
*/
protected function _write()
{
if ($this->_update_id === NULL)
Expand Down Expand Up @@ -154,4 +134,33 @@ protected function _write()
return TRUE;
}

protected function _destroy()
{
if ($this->_update_id === NULL)
{
// Session has not been created yet
return TRUE;
}

// Delete the current session
$query = DB::query(Database::DELETE, "DELETE FROM {$this->_table} WHERE session_id = :id")
->param(':id', $this->_update_id);

try
{
// Execute the query
$query->execute($this->_db);

// Delete the cookie
Cookie::delete($this->_name);
}
catch (Exception $e)
{
// An error occurred, the session has not been deleted
return FALSE;
}

return TRUE;
}

} // End Session_Database

0 comments on commit 5f8a4a4

Please sign in to comment.