From 7b17374cad338013f2fc4e91359820deac2ce4b3 Mon Sep 17 00:00:00 2001 From: predominant Date: Fri, 26 Mar 2010 10:46:48 +1100 Subject: [PATCH 1/3] Refs #332. Beginning fix for multiple session starts. --- cake/libs/cake_session.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 4d55cd9a6..83905c382 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -114,6 +114,13 @@ class CakeSession extends Object { */ var $id = null; +/** + * Session Started + * + * @var boolean + * @access public + */ + var $started = false; /** * Constructor. * @@ -181,16 +188,19 @@ class CakeSession extends Object { /** * Starts the Session. * - * @param string $name Variable name to check for - * @return boolean True if variable is there + * @return boolean True if session was started * @access public */ function start() { + if ($this->started) { + return true; + } if (function_exists('session_write_close')) { session_write_close(); } $this->__initSession(); - return $this->__startSession(); + $this->started = $this->__startSession(); + return $this->started; } /** From 13a55b6cd862f567069148372ebf0cdf50e8d4c4 Mon Sep 17 00:00:00 2001 From: predominant Date: Fri, 26 Mar 2010 14:21:08 +1100 Subject: [PATCH 2/3] Fixes #332. --- cake/libs/cake_session.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 83905c382..45fec9c62 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -118,9 +118,9 @@ class CakeSession extends Object { * Session Started * * @var boolean - * @access public + * @access protected */ - var $started = false; + var $_started = false; /** * Constructor. * @@ -192,15 +192,15 @@ class CakeSession extends Object { * @access public */ function start() { - if ($this->started) { + if ($this->started()) { return true; } if (function_exists('session_write_close')) { session_write_close(); } $this->__initSession(); - $this->started = $this->__startSession(); - return $this->started; + $this->_started = $this->__startSession(); + return $this->started(); } /** @@ -210,7 +210,7 @@ class CakeSession extends Object { * @return boolean True if session has been started. */ function started() { - if (isset($_SESSION)) { + if (isset($_SESSION) && $this->_started) { return true; } return false; @@ -243,7 +243,7 @@ class CakeSession extends Object { $this->id = $id; session_id($this->id); } - if (isset($_SESSION)) { + if ($this->started()) { return session_id(); } else { return $this->id; From 5d3f0d7fe0817941a54f831a254de8c683cabafc Mon Sep 17 00:00:00 2001 From: predominant Date: Fri, 26 Mar 2010 14:29:27 +1100 Subject: [PATCH 3/3] Fix for Session Component to use CakeSession started() checks. Refs #332. --- cake/libs/controller/components/session.php | 13 ++++++------- .../libs/controller/components/session.test.php | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index 4dc6e8978..fbe572009 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -41,12 +41,12 @@ class SessionComponent extends CakeSession { var $__active = true; /** - * Used to determine if Session has been started + * Used to determine if request are from an Ajax request * * @var boolean * @access private */ - var $__started = false; + var $__bare = 0; /** * Class constructor @@ -69,7 +69,7 @@ class SessionComponent extends CakeSession { * @access public */ function startup(&$controller) { - if ($this->__started === false && $this->__active === true) { + if ($this->started() === false && $this->__active === true) { $this->__start(); } } @@ -275,15 +275,14 @@ class SessionComponent extends CakeSession { * @access private */ function __start() { - if ($this->__started === false) { + if ($this->started() === false) { if (!$this->id() && parent::start()) { - $this->__started = true; parent::_checkValid(); } else { - $this->__started = parent::start(); + parent::start(); } } - return $this->__started; + return $this->started(); } } diff --git a/cake/tests/cases/libs/controller/components/session.test.php b/cake/tests/cases/libs/controller/components/session.test.php index 575aa3020..5eb2e39bc 100644 --- a/cake/tests/cases/libs/controller/components/session.test.php +++ b/cake/tests/cases/libs/controller/components/session.test.php @@ -112,13 +112,13 @@ class SessionComponentTest extends CakeTestCase { Configure::write('Session.start', false); $Session =& new SessionComponent(); $this->assertFalse($Session->__active); - $this->assertFalse($Session->__started); + $this->assertFalse($Session->started()); $Session->startup(new SessionTestController()); Configure::write('Session.start', true); $Session =& new SessionComponent(); $this->assertTrue($Session->__active); - $this->assertFalse($Session->__started); + $this->assertFalse($Session->started()); $Session->startup(new SessionTestController()); $this->assertTrue(isset($_SESSION));