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

4.2.23 #26441

Closed
wants to merge 4 commits into from
Closed

4.2.23 #26441

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "laravel/framework",
"name": "web-engineer/framework",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
"master": "4.2.23"
}
},
"suggest": {
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Foundation/changes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"4.2.*": [
"4.3.*": [
{"message": "Session fixation backported from 270991219.", "backport": null}
],
"4.2.*": [
{"message": "View and Pagination 'Environment' classes renamed to 'Factory'.", "backport": null},
{"message": "Configurable encryption for Iron.io queue messages.", "backport": null},
{"message": "Make FrameGuard middleware opt-in.", "backport": null},
Expand Down
62 changes: 55 additions & 7 deletions src/Illuminate/Session/DatabaseSessionHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php namespace Illuminate\Session;

use Illuminate\Database\Connection;
use Carbon\Carbon;
use Illuminate\Database\QueryException;
use Illuminate\Support\Arr;

class DatabaseSessionHandler implements \SessionHandlerInterface, ExistenceAwareInterface {

Expand Down Expand Up @@ -74,22 +77,67 @@ public function read($sessionId)
*/
public function write($sessionId, $data)
{
$payload = $this->getDefaultPayload($data);

if (! $this->exists) {
$this->read($sessionId);
}

if ($this->exists)
{
$this->getQuery()->where('id', $sessionId)->update([
'payload' => base64_encode($data), 'last_activity' => time(),
]);
$this->performUpdate($sessionId, $payload);
}
else
{
$this->getQuery()->insert([
'id' => $sessionId, 'payload' => base64_encode($data), 'last_activity' => time(),
]);
$this->performInsert($sessionId, $payload);
}

$this->exists = true;
}

/**
* Perform an insert operation on the session ID.
*
* @param string $sessionId
* @param string $payload
* @return void
*/
protected function performInsert($sessionId, $payload)
{
try {
return $this->getQuery()->insert(Arr::set($payload, 'id', $sessionId));
} catch (QueryException $e) {
$this->performUpdate($sessionId, $payload);
}
}

/**
* Perform an update operation on the session ID.
*
* @param string $sessionId
* @param string $payload
* @return int
*/
protected function performUpdate($sessionId, $payload)
{
return $this->getQuery()->where('id', $sessionId)->update($payload);
}

/**
* Get the default payload for the session.
*
* @param string $data
* @return array
*/
protected function getDefaultPayload($data)
{
//timestamp was time() in 4.2 origionally
$payload = [
'payload' => base64_encode($data),
'last_activity' => Carbon::now()->getTimestamp(),
];
//just return the payload
return $payload;
}
/**
* {@inheritDoc}
*/
Expand Down