8000 Fix compatibility with older mongodb server and driver · symfony/symfony@5e567e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e567e8

Browse files
committed
Fix compatibility with older mongodb server and driver
1 parent 29b7eae commit 5e567e8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function doWrite(#[\SensitiveParameter] string $sessionId, string $dat
123123
$fields = [
124124
$this->options['time_field'] => $this->getUTCDateTime(),
125125
$this->options['expiry_field'] => $expiry,
126-
$this->options['data_field'] => new Binary($data),
126+
$this->options['data_field'] => new Binary($data, Binary::TYPE_GENERIC),
127127
];
128128

129129
$write = new BulkWrite();

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use MongoDB\Client;
1717
use MongoDB\Driver\BulkWrite;
1818
use MongoDB\Driver\Command;
19+
use MongoDB\Driver\Exception\CommandException;
1920
use MongoDB\Driver\Exception\ConnectionException;
2021
use MongoDB\Driver\Manager;
2122
use MongoDB\Driver\Query;
@@ -80,7 +81,14 @@ public function testCreateFromClient()
8081

8182
protected function tearDown(): void
8283
{
83-
$this->manager->executeCommand(self::DABASE_NAME, new Command(['drop' => self::COLLECTION_NAME]));
84+
try {
85+
$this->manager-> 8000 ;executeCommand(self::DABASE_NAME, new Command(['drop' => self::COLLECTION_NAME]));
86+
} catch (CommandException $e) {
87+
// The server may return an error if the collection does not exist
88+
if ($e->getCode() !== 26) {
89+
throw $e;
90+
}
91+
}
8492
}
8593

8694
/** @dataProvider provideInvalidOptions */
@@ -191,7 +199,7 @@ private function insertSession(string $sessionId, string $data, int $timeDiff):
191199
$write = new BulkWrite();
192200
$write->insert([
193201
'_id' => $sessionId,
194-
'data' => new Binary($data),
202+
'data' => new Binary($data, Binary::TYPE_GENERIC),
195203
'time' => new UTCDateTime($time * 1000),
196204
'expires_at' => new UTCDateTime(($time + (int) \ini_get('session.gc_maxlifetime')) * 1000),
197205
]);

0 commit comments

Comments
 (0)
0