Skip to content

Commit

Permalink
Making Session.model the required setting and not Session.table. Sess…
Browse files Browse the repository at this point in the history
…ion.table can still be used to set the table name used when configuring sessions, but the default value is cake_session as before. Fixes #223
  • Loading branch information
markstory committed Jan 21, 2010
1 parent 913450d commit c5a5d1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 14 additions & 15 deletions cake/libs/cake_session.php
Expand Up @@ -138,17 +138,19 @@ function __construct($base = null, $start = true) {
if (empty($database)) {
$database = 'default';
}
if (empty($modelName)) {
ClassRegistry::init(array(
'class' => Inflector::classify($table),
'alias' => 'Session'
));
} else {
ClassRegistry::init(array(
'class' => $modelName,
'alias' => 'Session'
));
$settings = array(
'class' => 'Session',
'alias' => 'Session',
'table' => 'cake_sessions',
'ds' => $database
);
if (!empty($modelName)) {
$settings['class'] = $modelName;
}
if (!empty($table)) {
$settings['table'] = $table;
}
ClassRegistry::init($settings);
}
if ($start === true) {
if (!empty($base)) {
Expand Down Expand Up @@ -492,11 +494,9 @@ function __initSession() {
break;
case 'database':
if (empty($_SESSION)) {
if (Configure::read('Session.table') === null) {
if (Configure::read('Session.model') === null) {
trigger_error(__("You must set the all Configure::write('Session.*') in core.php to use database storage"), E_USER_WARNING);
exit();
} elseif (Configure::read('Session.database') === null) {
Configure::write('Session.database', 'default');
$this->_stop();
}
if ($iniSet) {
ini_set('session.use_trans_sid', 0);
Expand Down Expand Up @@ -763,7 +763,6 @@ function __write($id, $data) {

$model =& ClassRegistry::getObject('Session');
$return = $model->save(compact('id', 'data', 'expires'));

return $return;
}

Expand Down
4 changes: 3 additions & 1 deletion cake/tests/cases/libs/cake_session.test.php
Expand Up @@ -431,7 +431,8 @@ function testReadAndWriteWithDatabaseStorage() {
unset($_SESSION);
session_destroy();
Configure::write('Session.table', 'sessions');
Configure::write('Session.database', 'test');
Configure::write('Session.model', 'Session');
Configure::write('Session.database', 'test_suite');
Configure::write('Session.save', 'database');
$this->setUp();

Expand Down Expand Up @@ -463,5 +464,6 @@ function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.save', 'php');
$this->setUp();
}

}
?>

0 comments on commit c5a5d1d

Please sign in to comment.