mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
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)
This commit is contained in:
parent
f32045787f
commit
cde13daed4
3 changed files with 17 additions and 23 deletions
|
@ -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';
|
||||
}
|
||||
if (empty($modelName)) {
|
||||
$settings = array(
|
||||
'class' => 'Session',
|
||||
'class' =>'Session',
|
||||
'alias' => 'Session',
|
||||
'table' => 'cake_sessions',
|
||||
'ds' => $database
|
||||
);
|
||||
if (!empty($modelName)) {
|
||||
$settings['class'] = $modelName;
|
||||
}
|
||||
if (!empty($table)) {
|
||||
$settings['table'] = $table;
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue