From 2a209596600a18716c7ce2239ae78fa30772376d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 12 Dec 2018 09:39:13 +0200 Subject: [PATCH] Fixed session throwing error in CLI if initialized --- CHANGELOG.md | 1 + system/src/Grav/Common/Session.php | 2 +- system/src/Grav/Framework/Session/Session.php | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index feab885a6..1d46d71cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ * Fixed `Object` serialization breaking if overriding `jsonSerialize()` method * Grav 1.6: Fixed `FlexObject::update()` call with partial object update * Fixed `YamlFormatter::decode()` when calling `init_set()` with integer + * Fixed session throwing error in CLI if initialized # v1.6.0-beta.6 ## 11/12/2018 diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index d617f4684..234a4c7d4 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -31,7 +31,7 @@ class Session extends \Grav\Framework\Session\Session */ public function init() { - if ($this->autoStart) { + if ($this->autoStart && !$this->isStarted()) { $this->start(); $this->autoStart = false; diff --git a/system/src/Grav/Framework/Session/Session.php b/system/src/Grav/Framework/Session/Session.php index 077adb15a..edadff282 100644 --- a/system/src/Grav/Framework/Session/Session.php +++ b/system/src/Grav/Framework/Session/Session.php @@ -175,6 +175,10 @@ class Session implements SessionInterface */ public function start($readonly = false) { + if (\PHP_SAPI === 'cli') { + return $this; + } + // Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836 if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) { unset($_COOKIE[session_name()]); @@ -189,6 +193,7 @@ class Session implements SessionInterface if (!$success) { $last = error_get_last(); $error = $last ? $last['message'] : 'Unknown error'; + debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);die(); throw new \RuntimeException('Failed to start session: ' . $error, 500); }