From cde13daed4008042f0217f051109d3462cd4c209 Mon Sep 17 00:00:00 2001 From: Majna Date: Mon, 11 Jul 2011 00:16:41 +0200 Subject: [PATCH] Refactored DatabaseSession to use only 'Session.handler.model' config. Fixed static call on non-static method DatabaseSession::gc(). Fix for SessionFixture -primary key too long (MySQL Error: 1071) --- .../Datasource/Session/DatabaseSession.php | 31 ++++++++----------- .../Session/DatabaseSessionTest.php | 7 ++--- lib/Cake/Test/Fixture/SessionFixture.php | 2 +- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Model/Datasource/Session/DatabaseSession.php b/lib/Cake/Model/Datasource/Session/DatabaseSession.php index 5b5def3e2..927800d7e 100644 --- a/lib/Cake/Model/Datasource/Session/DatabaseSession.php +++ b/lib/Cake/Model/Datasource/Session/DatabaseSession.php @@ -31,23 +31,18 @@ class DatabaseSession implements CakeSessionHandlerInterface { */ public function __construct() { $modelName = Configure::read('Session.handler.model'); - $database = Configure::read('Session.handler.database'); - $table = Configure::read('Session.handler.table'); - - if (empty($database)) { - $database = 'default'; - } - $settings = array( - 'class' => 'Session', - 'alias' => 'Session', - 'table' => 'cake_sessions', - 'ds' => $database - ); - if (!empty($modelName)) { - $settings['class'] = $modelName; - } - if (!empty($table)) { - $settings['table'] = $table; + + if (empty($modelName)) { + $settings = array( + 'class' =>'Session', + 'alias' => 'Session', + 'table' => 'cake_sessions', + ); + } else { + $settings = array( + 'class' =>$modelName, + 'alias' => 'Session', + ); } ClassRegistry::init($settings); } @@ -71,7 +66,7 @@ class DatabaseSession implements CakeSessionHandlerInterface { public function close() { $probability = mt_rand(1, 150); if ($probability <= 3) { - DatabaseSession::gc(); + $this->gc(); } return true; } diff --git a/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php b/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php index da7a2af7c..824f31c51 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Session/DatabaseSessionTest.php @@ -23,8 +23,8 @@ App::uses('DatabaseSession', 'Model/Datasource/Session'); class_exists('CakeSession'); class SessionTestModel extends Model { - var $name = 'SessionTestModel'; - var $useTable = 'sessions'; + public $name = 'SessionTestModel'; + public $useTable = 'sessions'; } /** @@ -52,8 +52,6 @@ class DatabaseSessionTest extends CakeTestCase { self::$_sessionBackup = Configure::read('Session'); Configure::write('Session.handler', array( 'model' => 'SessionTestModel', - 'database' => 'test', - 'table' => 'sessions' )); Configure::write('Session.timeout', 100); } @@ -99,6 +97,7 @@ class DatabaseSessionTest extends CakeTestCase { $this->assertInstanceOf('SessionTestModel', $session); $this->assertEquals('Session', $session->alias); $this->assertEquals('test', $session->useDbConfig); + $this->assertEquals('sessions', $session->useTable); } /** diff --git a/lib/Cake/Test/Fixture/SessionFixture.php b/lib/Cake/Test/Fixture/SessionFixture.php index b13b5a4b7..655a24042 100644 --- a/lib/Cake/Test/Fixture/SessionFixture.php +++ b/lib/Cake/Test/Fixture/SessionFixture.php @@ -46,7 +46,7 @@ class SessionFixture extends CakeTestFixture { * @access public */ public $fields = array( - 'id' => array('type' => 'string', 'length' => 255, 'key' => 'primary'), + 'id' => array('type' => 'string', 'length' => 128, 'key' => 'primary'), 'data' => array('type' => 'text','null' => true), 'expires' => array('type' => 'integer', 'length' => 11, 'null' => true) );