From 69ac82e5b262a2e03d25bb2011c989bbef51126d Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 7 Sep 2023 12:31:45 +0100 Subject: [PATCH 1/7] test interface --- .../core/Mage/Core/Model/Resource/Session.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 0acc6d1228e..e444bb2478e 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -19,7 +19,7 @@ * @category Mage * @package Mage_Core */ -class Mage_Core_Model_Resource_Session implements Zend_Session_SaveHandler_Interface +class Mage_Core_Model_Resource_Session implements SessionHandlerInterface { /** * Session maximum cookie lifetime @@ -162,7 +162,7 @@ public static function setStaticSaveHandler() * @param string $sessName ignored * @return bool */ - public function open($savePath, $sessName) + public function open($savePath, $sessName): bool { return true; } @@ -172,7 +172,7 @@ public function open($savePath, $sessName) * * @return bool */ - public function close() + public function close(): bool { $this->gc($this->getLifeTime()); @@ -183,9 +183,9 @@ public function close() * Fetch session data * * @param string $sessId - * @return string + * @return string|false */ - public function read($sessId) + public function read($sessId): string|false { $select = $this->_read->select() ->from($this->_sessionTable, ['session_data']) @@ -208,7 +208,7 @@ public function read($sessId) * @param string $sessData * @return bool */ - public function write($sessId, $sessData) + public function write($sessId, $sessData): bool { $bindValues = [ 'session_id' => $sessId @@ -241,7 +241,7 @@ public function write($sessId, $sessData) * @param string $sessId * @return bool */ - public function destroy($sessId) + public function destroy($sessId): bool { $where = ['session_id = ?' => $sessId]; $this->_write->delete($this->_sessionTable, $where); @@ -252,18 +252,18 @@ public function destroy($sessId) * Garbage collection * * @param int $sessMaxLifeTime ignored - * @return bool + * @return int|false */ - public function gc($sessMaxLifeTime) + public function gc($sessMaxLifeTime): int|false { if ($this->_automaticCleaningFactor > 0) { 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 false; } } From 6e788cb38203cf0d3a99444ad18977ede14244e2 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:17:33 +0100 Subject: [PATCH 2/7] return 0 for gc() --- app/code/core/Mage/Core/Model/Resource/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index e444bb2478e..059c8793dae 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -264,6 +264,6 @@ public function gc($sessMaxLifeTime): int|false return $this->_write->delete($this->_sessionTable, $where); } } - return false; + return 0; } } From 841abe17681c37a10de554e54977ee01b311e667 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:24:26 +0100 Subject: [PATCH 3/7] not casting read() anymore --- .../core/Mage/Core/Model/Resource/Session.php | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 059c8793dae..5172ad5005a 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -19,7 +19,7 @@ * @category Mage * @package Mage_Core */ -class Mage_Core_Model_Resource_Session implements SessionHandlerInterface +class Mage_Core_Model_Resource_Session implements Zend_Session_SaveHandler_Interface { /** * Session maximum cookie lifetime @@ -162,7 +162,7 @@ public static function setStaticSaveHandler() * @param string $sessName ignored * @return bool */ - public function open($savePath, $sessName): bool + public function open($savePath, $sessName) { return true; } @@ -172,7 +172,7 @@ public function open($savePath, $sessName): bool * * @return bool */ - public function close(): bool + public function close() { $this->gc($this->getLifeTime()); @@ -183,22 +183,20 @@ public function close(): bool * Fetch session data * * @param string $sessId - * @return string|false + * @return string */ - public function read($sessId): string|false + public function read($sessId) { $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); } /** @@ -208,14 +206,14 @@ public function read($sessId): string|false * @param string $sessData * @return bool */ - public function write($sessId, $sessData): bool + public function write($sessId, $sessData) { $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 = [ @@ -241,7 +239,7 @@ public function write($sessId, $sessData): bool * @param string $sessId * @return bool */ - public function destroy($sessId): bool + public function destroy($sessId) { $where = ['session_id = ?' => $sessId]; $this->_write->delete($this->_sessionTable, $where); @@ -252,18 +250,18 @@ public function destroy($sessId): bool * Garbage collection * * @param int $sessMaxLifeTime ignored - * @return int|false + * @return bool */ - public function gc($sessMaxLifeTime): int|false + public function gc($sessMaxLifeTime) { if ($this->_automaticCleaningFactor > 0) { if ($this->_automaticCleaningFactor == 1 || rand(1, $this->_automaticCleaningFactor) == 1 ) { $where = ['session_expires < ?' => Varien_Date::toTimestamp(true)]; - return $this->_write->delete($this->_sessionTable, $where); + $this->_write->delete($this->_sessionTable, $where); } } - return 0; + return true; } } From aeb16a60ac8f9c9c527fd1983e6491560b623d5c Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:30:46 +0100 Subject: [PATCH 4/7] the right class --- app/code/core/Mage/Core/Model/Resource/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 5172ad5005a..0156a437c04 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -19,7 +19,7 @@ * @category Mage * @package Mage_Core */ -class Mage_Core_Model_Resource_Session implements Zend_Session_SaveHandler_Interface +class Mage_Core_Model_Resource_Session implements SessionHandlerInterface { /** * Session maximum cookie lifetime From eccda3d5df2f2d15660b54d390e1ab81b52f2ccb Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:32:22 +0100 Subject: [PATCH 5/7] return types --- app/code/core/Mage/Core/Model/Resource/Session.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 0156a437c04..940a9049362 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -162,7 +162,7 @@ public static function setStaticSaveHandler() * @param string $sessName ignored * @return bool */ - public function open($savePath, $sessName) + public function open($savePath, $sessName): bool { return true; } @@ -172,7 +172,7 @@ public function open($savePath, $sessName) * * @return bool */ - public function close() + public function close(): bool { $this->gc($this->getLifeTime()); @@ -185,7 +185,7 @@ public function close() * @param string $sessId * @return string */ - public function read($sessId) + public function read($sessId): string|false { $select = $this->_read->select() ->from($this->_sessionTable, ['session_data']) @@ -206,7 +206,7 @@ public function read($sessId) * @param string $sessData * @return bool */ - public function write($sessId, $sessData) + public function write($sessId, $sessData): bool { $bindValues = [ 'session_id' => $sessId @@ -239,7 +239,7 @@ public function write($sessId, $sessData) * @param string $sessId * @return bool */ - public function destroy($sessId) + public function destroy($sessId): bool { $where = ['session_id = ?' => $sessId]; $this->_write->delete($this->_sessionTable, $where); @@ -252,7 +252,7 @@ public function destroy($sessId) * @param int $sessMaxLifeTime ignored * @return bool */ - public function gc($sessMaxLifeTime) + public function gc($sessMaxLifeTime): int|false { if ($this->_automaticCleaningFactor > 0) { if ($this->_automaticCleaningFactor == 1 || From 007dfb701001870f77c165d09fe70f8bb8bed9d4 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:33:30 +0100 Subject: [PATCH 6/7] I dont know what happened --- app/code/core/Mage/Core/Model/Resource/Session.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 940a9049362..295c71cef38 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -250,7 +250,7 @@ public function destroy($sessId): bool * Garbage collection * * @param int $sessMaxLifeTime ignored - * @return bool + * @return int|false */ public function gc($sessMaxLifeTime): int|false { @@ -259,9 +259,9 @@ public function gc($sessMaxLifeTime): int|false 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; } } From 27099f373870dfd11e128cff22e58f6f520af534 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Fri, 8 Sep 2023 10:34:51 +0100 Subject: [PATCH 7/7] estetic --- app/code/core/Mage/Core/Model/Resource/Session.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/code/core/Mage/Core/Model/Resource/Session.php b/app/code/core/Mage/Core/Model/Resource/Session.php index 295c71cef38..1092aab6786 100644 --- a/app/code/core/Mage/Core/Model/Resource/Session.php +++ b/app/code/core/Mage/Core/Model/Resource/Session.php @@ -71,10 +71,6 @@ public function __construct() $this->_write = $resource->getConnection('core_write'); } - /** - * Destrucor - * - */ public function __destruct() { session_write_close(); @@ -255,9 +251,7 @@ public function destroy($sessId): bool 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)]; return $this->_write->delete($this->_sessionTable, $where); }