Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed implementation of SessionHandlerInterface in Mage_Core_Model_Resource_Session #3499

Merged
merged 9 commits into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions app/code/core/Mage/Core/Model/Resource/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ public function __construct()
$this->_write = $resource->getConnection('core_write');
}

/**
* Destrucor
*
*/
public function __destruct()
{
session_write_close();
Expand Down Expand Up @@ -162,8 +158,7 @@ public static function setStaticSaveHandler()
* @param string $sessName ignored
* @return bool
*/
#[\ReturnTypeWillChange]
public function open($savePath, $sessName)
public function open($savePath, $sessName): bool
{
return true;
}
Expand All @@ -173,8 +168,7 @@ public function open($savePath, $sessName)
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function close()
public function close(): bool
{
$this->gc($this->getLifeTime());

Expand All @@ -187,21 +181,18 @@ public function close()
* @param string $sessId
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessId)
public function read($sessId): string|false
fballiano marked this conversation as resolved.
Show resolved Hide resolved
{
$select = $this->_read->select()
->from($this->_sessionTable, ['session_data'])
->where('session_id = :session_id')
->where('session_expires > :session_expires');
->from($this->_sessionTable, ['session_data'])
->where('session_id = :session_id')
->where('session_expires > :session_expires');
$bind = [
'session_id' => $sessId,
'session_expires' => Varien_Date::toTimestamp(true)
];

$data = $this->_read->fetchOne($select, $bind);

return (string)$data;
return $this->_read->fetchOne($select, $bind);
}

/**
Expand All @@ -211,15 +202,14 @@ public function read($sessId)
* @param string $sessData
* @return bool
*/
#[\ReturnTypeWillChange]
public function write($sessId, $sessData)
public function write($sessId, $sessData): bool
{
$bindValues = [
'session_id' => $sessId
];
$select = $this->_write->select()
->from($this->_sessionTable)
->where('session_id = :session_id');
->from($this->_sessionTable)
->where('session_id = :session_id');
$exists = $this->_read->fetchOne($select, $bindValues);

$bind = [
Expand All @@ -245,8 +235,7 @@ public function write($sessId, $sessData)
* @param string $sessId
* @return bool
*/
#[\ReturnTypeWillChange]
public function destroy($sessId)
public function destroy($sessId): bool
{
$where = ['session_id = ?' => $sessId];
$this->_write->delete($this->_sessionTable, $where);
Expand All @@ -257,19 +246,16 @@ public function destroy($sessId)
* Garbage collection
*
* @param int $sessMaxLifeTime ignored
* @return bool
* @return int|false
*/
#[\ReturnTypeWillChange]
public function gc($sessMaxLifeTime)
public function gc($sessMaxLifeTime): int|false
{
if ($this->_automaticCleaningFactor > 0) {
if ($this->_automaticCleaningFactor == 1 ||
rand(1, $this->_automaticCleaningFactor) == 1
) {
if ($this->_automaticCleaningFactor == 1 || rand(1, $this->_automaticCleaningFactor) == 1) {
$where = ['session_expires < ?' => Varien_Date::toTimestamp(true)];
$this->_write->delete($this->_sessionTable, $where);
return $this->_write->delete($this->_sessionTable, $where);
}
}
return true;
return 0;
}
}
Loading