mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 18:24:57 +02:00
Fix issue processwire/processwire-issues#911
This commit is contained in:
@@ -7,25 +7,26 @@
|
||||
* It provides the interface and some basic functions. For an example, see:
|
||||
* /wire/modules/Session/SessionHandlerDB/SessionHandlerDB.module
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class WireSessionHandler extends WireData implements Module {
|
||||
|
||||
/**
|
||||
* Initialize the save handler
|
||||
* Initialize the save handler when $modules sets the current instance
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->addHookBefore('Session::init', $this, 'attach');
|
||||
register_shutdown_function('session_write_close');
|
||||
public function wired() {
|
||||
if(!$this->sessionExists()) {
|
||||
$this->addHookBefore('Session::init', $this, 'attach');
|
||||
register_shutdown_function('session_write_close');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initailize the module, may not be needed here but required for module interface
|
||||
* Initailize, called when module configuration has been populated
|
||||
*
|
||||
*/
|
||||
public function init() { }
|
||||
@@ -35,14 +36,14 @@ abstract class WireSessionHandler extends WireData implements Module {
|
||||
*
|
||||
*/
|
||||
public function attach() {
|
||||
session_set_save_handler(
|
||||
session_set_save_handler(
|
||||
array($this, 'open'),
|
||||
array($this, 'close'),
|
||||
array($this, 'read'),
|
||||
array($this, 'write'),
|
||||
array($this, 'destroy'),
|
||||
array($this, 'gc')
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,7 @@ abstract class WireSessionHandler extends WireData implements Module {
|
||||
*
|
||||
*/
|
||||
public function open($path, $name) {
|
||||
if($name && $path) {} // ignore
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -103,6 +105,18 @@ abstract class WireSessionHandler extends WireData implements Module {
|
||||
*/
|
||||
abstract public function gc($seconds);
|
||||
|
||||
/**
|
||||
* Does a session currently exist? (i.e. already one started)
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.0.158
|
||||
*
|
||||
*/
|
||||
public function sessionExists() {
|
||||
if(function_exists("\\session_status")) return session_status() === PHP_SESSION_ACTIVE;
|
||||
return session_id() !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the Modules API to only instantiate one instance of this module
|
||||
*
|
||||
|
@@ -102,6 +102,9 @@ class ProcessSessionDB extends Process {
|
||||
while($row) {
|
||||
|
||||
list($user_id, $pages_id, $ip, $ua, $ts) = $row;
|
||||
|
||||
$pages_id = (int) $pages_id;
|
||||
$user_id = (int) $user_id;
|
||||
|
||||
if(isset($userNames[$user_id])) {
|
||||
$userName = $userNames[$user_id];
|
||||
@@ -109,7 +112,7 @@ class ProcessSessionDB extends Process {
|
||||
} else {
|
||||
$user = $this->wire('users')->get($user_id);
|
||||
$userName = $user && $user->id ? $user->name : '.';
|
||||
$userNames[$user_id] = $userName;
|
||||
if($userName !== '.') $userNames[$user_id] = $userName;
|
||||
}
|
||||
|
||||
if(isset($pagePaths[$pages_id])) {
|
||||
@@ -118,7 +121,7 @@ class ProcessSessionDB extends Process {
|
||||
} else {
|
||||
$page = $this->wire('pages')->get($pages_id);
|
||||
$pagePath = $page->id ? $page->path : '.';
|
||||
$pagePaths[$pages_id] = $pagePath;
|
||||
if($pagePath !== '.') $pagePaths[$pages_id] = $pagePath;
|
||||
}
|
||||
|
||||
$tr = array(wireRelativeTimeStr($ts), $userName, $pagePath);
|
||||
|
Reference in New Issue
Block a user