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

Fix bugs with extending the session handler class #15934

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions core/src/Revolution/Processors/Security/Flush.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@
*/
class Flush extends Processor
{
/**
* @return array
*/
public function getLanguageTopics()
{
return ['topmenu'];
}

public function checkPermissions()
{
return $this->modx->hasPermission('flush_sessions');
}

public function process()
{
if ($this->modx->getOption('session_handler_class',null,modSessionHandler::class) === modSessionHandler::class) {
if (!$this->flushSessions()) {
return $this->failure($this->modx->lexicon('flush_sessions_err'));
}
} else {
$sessionHandler = $this->modx->services->get('session_handler');
if (!$sessionHandler instanceof modSessionHandler) {
return $this->failure($this->modx->lexicon('flush_sessions_not_supported'));
}
return $this->success();

return $this->flushSessions()
? $this->success()
: $this->failure($this->modx->lexicon('flush_sessions_err'));
}

public function flushSessions()
Expand Down
4 changes: 2 additions & 2 deletions core/src/Revolution/modSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @package MODX\Revolution
*/
class modSessionHandler
class modSessionHandler implements \SessionHandlerInterface
{
/**
* @var modX A reference to the modX instance controlling this session
Expand Down Expand Up @@ -68,7 +68,7 @@ function __construct(modX &$modx)
* @return boolean Always returns true; actual connection is managed by
* {@link modX}.
*/
public function open()
public function open($path, $name)
{
return true;
}
Expand Down
24 changes: 7 additions & 17 deletions core/src/Revolution/modX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2746,25 +2746,15 @@ protected function _initSession($options = null) {
$contextKey= $this->context instanceof modContext ? $this->context->get('key') : null;
if ($this->getOption('session_enabled', $options, true) || isset($_GET['preview'])) {
if (!in_array($this->getSessionState(), [modX::SESSION_STATE_INITIALIZED, modX::SESSION_STATE_EXTERNAL, modX::SESSION_STATE_UNAVAILABLE], true)) {
$sh = false;
if ($sessionHandlerClass = $this->getOption('session_handler_class', $options)) {
if ($shClass = $this->loadClass($sessionHandlerClass, '', false, true)) {
if ($sh = new $shClass($this)) {
session_set_save_handler(
Mark-H marked this conversation as resolved.
Show resolved Hide resolved
[& $sh, 'open'],
[& $sh, 'close'],
[& $sh, 'read'],
[& $sh, 'write'],
[& $sh, 'destroy'],
[& $sh, 'gc']
);
}
Mark-H marked this conversation as resolved.
Show resolved Hide resolved
$sessionHandlerClass = $this->getOption('session_handler_class', $options);
if (is_string($sessionHandlerClass) && !empty($sessionHandlerClass) && class_exists($sessionHandlerClass)) {
$sh = new $sessionHandlerClass($this);
if ($sh instanceof \SessionHandlerInterface) {
$this->services->add('session_handler', $sh);
session_set_save_handler($sh);
}
}
if (
(is_string($sessionHandlerClass) && !$sh instanceof $sessionHandlerClass) ||
!is_string($sessionHandlerClass)
) {
if (!$this->services->has('session_handler')) {
Mark-H marked this conversation as resolved.
Show resolved Hide resolved
$sessionSavePath = $this->getOption('session_save_path', $options);
if ($sessionSavePath && is_writable($sessionSavePath)) {
session_save_path($sessionSavePath);
Expand Down