mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 11:44:42 +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:
|
* It provides the interface and some basic functions. For an example, see:
|
||||||
* /wire/modules/Session/SessionHandlerDB/SessionHandlerDB.module
|
* /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
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class WireSessionHandler extends WireData implements Module {
|
abstract class WireSessionHandler extends WireData implements Module {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the save handler
|
* Initialize the save handler when $modules sets the current instance
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function wired() {
|
||||||
$this->addHookBefore('Session::init', $this, 'attach');
|
if(!$this->sessionExists()) {
|
||||||
register_shutdown_function('session_write_close');
|
$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() { }
|
public function init() { }
|
||||||
@@ -35,14 +36,14 @@ abstract class WireSessionHandler extends WireData implements Module {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function attach() {
|
public function attach() {
|
||||||
session_set_save_handler(
|
session_set_save_handler(
|
||||||
array($this, 'open'),
|
array($this, 'open'),
|
||||||
array($this, 'close'),
|
array($this, 'close'),
|
||||||
array($this, 'read'),
|
array($this, 'read'),
|
||||||
array($this, 'write'),
|
array($this, 'write'),
|
||||||
array($this, 'destroy'),
|
array($this, 'destroy'),
|
||||||
array($this, 'gc')
|
array($this, 'gc')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +55,7 @@ abstract class WireSessionHandler extends WireData implements Module {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function open($path, $name) {
|
public function open($path, $name) {
|
||||||
|
if($name && $path) {} // ignore
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +105,18 @@ abstract class WireSessionHandler extends WireData implements Module {
|
|||||||
*/
|
*/
|
||||||
abstract public function gc($seconds);
|
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
|
* Tells the Modules API to only instantiate one instance of this module
|
||||||
*
|
*
|
||||||
|
@@ -102,6 +102,9 @@ class ProcessSessionDB extends Process {
|
|||||||
while($row) {
|
while($row) {
|
||||||
|
|
||||||
list($user_id, $pages_id, $ip, $ua, $ts) = $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])) {
|
if(isset($userNames[$user_id])) {
|
||||||
$userName = $userNames[$user_id];
|
$userName = $userNames[$user_id];
|
||||||
@@ -109,7 +112,7 @@ class ProcessSessionDB extends Process {
|
|||||||
} else {
|
} else {
|
||||||
$user = $this->wire('users')->get($user_id);
|
$user = $this->wire('users')->get($user_id);
|
||||||
$userName = $user && $user->id ? $user->name : '.';
|
$userName = $user && $user->id ? $user->name : '.';
|
||||||
$userNames[$user_id] = $userName;
|
if($userName !== '.') $userNames[$user_id] = $userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($pagePaths[$pages_id])) {
|
if(isset($pagePaths[$pages_id])) {
|
||||||
@@ -118,7 +121,7 @@ class ProcessSessionDB extends Process {
|
|||||||
} else {
|
} else {
|
||||||
$page = $this->wire('pages')->get($pages_id);
|
$page = $this->wire('pages')->get($pages_id);
|
||||||
$pagePath = $page->id ? $page->path : '.';
|
$pagePath = $page->id ? $page->path : '.';
|
||||||
$pagePaths[$pages_id] = $pagePath;
|
if($pagePath !== '.') $pagePaths[$pages_id] = $pagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tr = array(wireRelativeTimeStr($ts), $userName, $pagePath);
|
$tr = array(wireRelativeTimeStr($ts), $userName, $pagePath);
|
||||||
|
Reference in New Issue
Block a user