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() {
|
public function __construct() {
|
||||||
$modelName = Configure::read('Session.handler.model');
|
$modelName = Configure::read('Session.handler.model');
|
||||||
$database = Configure::read('Session.handler.database');
|
|
||||||
$table = Configure::read('Session.handler.table');
|
if (empty($modelName)) {
|
||||||
|
$settings = array(
|
||||||
if (empty($database)) {
|
'class' =>'Session',
|
||||||
$database = 'default';
|
'alias' => 'Session',
|
||||||
}
|
'table' => 'cake_sessions',
|
||||||
$settings = array(
|
);
|
||||||
'class' => 'Session',
|
} else {
|
||||||
'alias' => 'Session',
|
$settings = array(
|
||||||
'table' => 'cake_sessions',
|
'class' =>$modelName,
|
||||||
'ds' => $database
|
'alias' => 'Session',
|
||||||
);
|
);
|
||||||
if (!empty($modelName)) {
|
|
||||||
$settings['class'] = $modelName;
|
|
||||||
}
|
|
||||||
if (!empty($table)) {
|
|
||||||
$settings['table'] = $table;
|
|
||||||
}
|
}
|
||||||
ClassRegistry::init($settings);
|
ClassRegistry::init($settings);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +66,7 @@ class DatabaseSession implements CakeSessionHandlerInterface {
|
||||||
public function close() {
|
public function close() {
|
||||||
$probability = mt_rand(1, 150);
|
$probability = mt_rand(1, 150);
|
||||||
if ($probability <= 3) {
|
if ($probability <= 3) {
|
||||||
DatabaseSession::gc();
|
$this->gc();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ App::uses('DatabaseSession', 'Model/Datasource/Session');
|
||||||
class_exists('CakeSession');
|
class_exists('CakeSession');
|
||||||
|
|
||||||
class SessionTestModel extends Model {
|
class SessionTestModel extends Model {
|
||||||
var $name = 'SessionTestModel';
|
public $name = 'SessionTestModel';
|
||||||
var $useTable = 'sessions';
|
public $useTable = 'sessions';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +52,6 @@ class DatabaseSessionTest extends CakeTestCase {
|
||||||
self::$_sessionBackup = Configure::read('Session');
|
self::$_sessionBackup = Configure::read('Session');
|
||||||
Configure::write('Session.handler', array(
|
Configure::write('Session.handler', array(
|
||||||
'model' => 'SessionTestModel',
|
'model' => 'SessionTestModel',
|
||||||
'database' => 'test',
|
|
||||||
'table' => 'sessions'
|
|
||||||
));
|
));
|
||||||
Configure::write('Session.timeout', 100);
|
Configure::write('Session.timeout', 100);
|
||||||
}
|
}
|
||||||
|
@ -99,6 +97,7 @@ class DatabaseSessionTest extends CakeTestCase {
|
||||||
$this->assertInstanceOf('SessionTestModel', $session);
|
$this->assertInstanceOf('SessionTestModel', $session);
|
||||||
$this->assertEquals('Session', $session->alias);
|
$this->assertEquals('Session', $session->alias);
|
||||||
$this->assertEquals('test', $session->useDbConfig);
|
$this->assertEquals('test', $session->useDbConfig);
|
||||||
|
$this->assertEquals('sessions', $session->useTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SessionFixture extends CakeTestFixture {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $fields = array(
|
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),
|
'data' => array('type' => 'text','null' => true),
|
||||||
'expires' => array('type' => 'integer', 'length' => 11, 'null' => true)
|
'expires' => array('type' => 'integer', 'length' => 11, 'null' => true)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue