Skip to content

Commit 36593b5

Browse files
committed
Merge branch 'main' into next
2 parents fdb003a + 0b3d782 commit 36593b5

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

app/code/core/Mage/Api/Model/Cron.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* OpenMage
4+
*
5+
* This source file is subject to the Open Software License (OSL 3.0)
6+
* that is bundled with this package in the file LICENSE.txt.
7+
* It is also available at https://opensource.org/license/osl-3-0-php
8+
*
9+
* @category Mage
10+
* @package Mage_Api
11+
* @copyright Copyright (c) 2023 The OpenMage Contributors (https://www.openmage.org)
12+
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
13+
*/
14+
15+
class Mage_Api_Model_Cron
16+
{
17+
/**
18+
* Clean session table
19+
*
20+
* @param Mage_Cron_Model_Schedule $schedule
21+
* @return $this
22+
*/
23+
public function cleanOldSessions($schedule)
24+
{
25+
Mage::getResourceSingleton('api/user')->cleanOldSessions(null);
26+
return $this;
27+
}
28+
}

app/code/core/Mage/Api/Model/Resource/User.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,28 @@ public function recordSession(Mage_Api_Model_User $user)
101101
/**
102102
* Clean old session
103103
*
104-
* @param Mage_Api_Model_User $user
104+
* @param Mage_Api_Model_User|null $user
105105
* @return $this
106106
*/
107-
public function cleanOldSessions(Mage_Api_Model_User $user)
107+
public function cleanOldSessions(?Mage_Api_Model_User $user)
108108
{
109109
$readAdapter = $this->_getReadAdapter();
110110
$writeAdapter = $this->_getWriteAdapter();
111111
$timeout = Mage::getStoreConfig('api/config/session_timeout');
112-
$timeSubtract = $readAdapter->getDateAddSql(
112+
$timeSubtract = $readAdapter->getDateAddSql(
113113
'logdate',
114114
$timeout,
115115
Varien_Db_Adapter_Interface::INTERVAL_SECOND
116116
);
117+
$where = [
118+
$readAdapter->quote(Varien_Date::now()) . ' > '. $timeSubtract
119+
];
120+
if ($user) {
121+
$where['user_id = ?'] = $user->getId();
122+
}
117123
$writeAdapter->delete(
118124
$this->getTable('api/session'),
119-
['user_id = ?' => $user->getId(), $readAdapter->quote(Varien_Date::now()) . ' > ' . $timeSubtract]
125+
$where
120126
);
121127
return $this;
122128
}

app/code/core/Mage/Api/etc/config.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@
110110
</modules>
111111
</translate>
112112
</adminhtml>
113+
<crontab>
114+
<jobs>
115+
<api_session_cleanup>
116+
<schedule>
117+
<cron_expr>0 35 * * *</cron_expr>
118+
</schedule>
119+
<run>
120+
<model>api/cron::cleanOldSessions</model>
121+
</run>
122+
</api_session_cleanup>
123+
</jobs>
124+
</crontab>
113125
<default>
114126
<api>
115127
<config>

app/code/core/Mage/Core/Model/Resource/Session.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @category Mage
2020
* @package Mage_Core
2121
*/
22-
class Mage_Core_Model_Resource_Session implements Zend_Session_SaveHandler_Interface
22+
class Mage_Core_Model_Resource_Session implements SessionHandlerInterface
2323
{
2424
/**
2525
* Session maximum cookie lifetime
@@ -162,6 +162,7 @@ public static function setStaticSaveHandler()
162162
* @param string $sessName ignored
163163
* @return bool
164164
*/
165+
#[\ReturnTypeWillChange]
165166
public function open($savePath, $sessName)
166167
{
167168
return true;
@@ -172,6 +173,7 @@ public function open($savePath, $sessName)
172173
*
173174
* @return bool
174175
*/
176+
#[\ReturnTypeWillChange]
175177
public function close()
176178
{
177179
$this->gc($this->getLifeTime());
@@ -185,6 +187,7 @@ public function close()
185187
* @param string $sessId
186188
* @return string
187189
*/
190+
#[\ReturnTypeWillChange]
188191
public function read($sessId)
189192
{
190193
$select = $this->_read->select()
@@ -208,6 +211,7 @@ public function read($sessId)
208211
* @param string $sessData
209212
* @return bool
210213
*/
214+
#[\ReturnTypeWillChange]
211215
public function write($sessId, $sessData)
212216
{
213217
$bindValues = [
@@ -241,6 +245,7 @@ public function write($sessId, $sessData)
241245
* @param string $sessId
242246
* @return bool
243247
*/
248+
#[\ReturnTypeWillChange]
244249
public function destroy($sessId)
245250
{
246251
$where = ['session_id = ?' => $sessId];
@@ -254,6 +259,7 @@ public function destroy($sessId)
254259
* @param int $sessMaxLifeTime ignored
255260
* @return bool
256261
*/
262+
#[\ReturnTypeWillChange]
257263
public function gc($sessMaxLifeTime)
258264
{
259265
if ($this->_automaticCleaningFactor > 0) {

0 commit comments

Comments
 (0)