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 Return an emtpy string instead of false from HybridSession::read() #83

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Feb 14, 2023

README.md Outdated
@@ -17,12 +17,12 @@ multi-server issues like asset storage and databases).

## Installation

* Install with composer using `composer require silverstripe/hybridsessions:*`
* Install with composer using `composer require silverstripe/hybridsessions:^5`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean ^3 (and the ^5 was because of CMS 5)?

Suggested change
* Install with composer using `composer require silverstripe/hybridsessions:^5`
* Install with composer using `composer require silverstripe/hybridsessions:^3`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed the version as per Guys review below


return false;
// Return a blank string if no record was found in any store
// The "session" still exists in memory until a new record will be created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The "session" still exists in memory until a new record will be created
// The "session" still exists in memory until a new record is created

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a comment above return true; in open() something along the lines of

Our interpretation of "or creates a new one" in https://www.php.net/manual/en/sessionhandlerinterface.open.php allows for the session to have been created in memory, to be stored by the appropriate handler on session_write_close(). If the session fails to be written, we return false in write(), so we will be alerted to there being some error.

Alternatively, we could return false from open() if all of the stores return false which would indicate that none of the stores are going to be able to write the session when the session ends. This would also require changing open() of the child handlers to return false if they won't be able to store stuff (db not available, and the checks that are in write() for the cookie handler)

Either one of these - a comment explaining our thinking and interpretation of the docs (or returning false if all handlers return false from open) will be fine.

README.md Outdated
@@ -17,12 +17,12 @@ multi-server issues like asset storage and databases).

## Installation

* Install with composer using `composer require silverstripe/hybridsessions:*`
* Install with composer using `composer require silverstripe/hybridsessions:^5`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Install with composer using `composer require silverstripe/hybridsessions:^5`
* Install with composer using `composer require silverstripe/hybridsessions`

Composer knows what version is right. Specifying here just gives us another thing we have to change next major.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 77 to 86
// Return a blank string if no record was found in any store
// The "session" still exists in memory until a new record will be created
// in the first writable store in write()
// This prevents `PHP Warning: session_start(): Failed to read session data: user`
// when session_start() is called within SilverStripe\Control\Session::start()
return '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Return a blank string if no record was found in any store
// The "session" still exists in memory until a new record will be created
// in the first writable store in write()
// This prevents `PHP Warning: session_start(): Failed to read session data: user`
// when session_start() is called within SilverStripe\Control\Session::start()
return '';
// Return a blank string if no record was found in any store
// The "session" still exists in memory until a new record will be created
// in the first writable store in write()
// Our interpretation then of "If the record was not found" in https://www.php.net/manual/en/sessionhandlerinterface.read.php
// is that we have "found" the NEW session in memory.
// This prevents `PHP Warning: session_start(): Failed to read session data: user`
// when session_start() is called within SilverStripe\Control\Session::start()
return '';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@emteknetnz
Copy link
Member Author

@GuySartorelli I've added the comment to open() rather than changing return types

@GuySartorelli GuySartorelli merged commit 1b6897d into silverstripe:3.0 Feb 15, 2023
@GuySartorelli GuySartorelli deleted the pulls/3.0/emtpy-data branch February 15, 2023 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants