Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/Illuminate/Session/DatabaseSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\QueryException;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\InteractsWithTime;
Expand Down Expand Up @@ -155,7 +156,7 @@ protected function performInsert($sessionId, $payload)
{
try {
return $this->getQuery()->insert(Arr::set($payload, 'id', $sessionId));
} catch (QueryException) {
} catch (UniqueConstraintViolationException) {
$this->performUpdate($sessionId, $payload);
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/Session/DatabaseSessionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Tests\Integration\Session;

use Illuminate\Database\QueryException;
use Illuminate\Session\DatabaseSessionHandler;
use Illuminate\Support\Carbon;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
Expand Down Expand Up @@ -96,6 +97,19 @@ public function test_destroy()
$this->assertEquals(1, $connection->table('sessions')->where('id', 'id_2')->count());
}

public function test_insert_rethrows_non_unique_constraint_query_exceptions()
{
$connection = $this->app['db']->connection();
$handler = new DatabaseSessionHandler($connection, 'sessions', 1);

// Drop the sessions table to cause a non-unique-constraint QueryException on insert
$connection->getSchemaBuilder()->drop('sessions');

$this->expectException(QueryException::class);

$handler->write('session_id', 'some data');
}

public function test_it_can_work_without_container()
{
$connection = $this->app['db']->connection();
Expand Down
Loading