Skip to content

Merge 4.9 into 5.0 #3423

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

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 19 additions & 2 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ on:
push:
pull_request:

env:
MONGODB_EXT_V1: mongodb-1.21.0
MONGODB_EXT_V2: mongodb

jobs:
build:
runs-on: "${{ matrix.os }}"

name: "PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} MongoDB ${{ matrix.mongodb }} ${{ matrix.mode }}"
name: "PHP/${{ matrix.php }} Laravel/${{ matrix.laravel }} Driver/${{ matrix.driver }} Server/${{ matrix.mongodb }} ${{ matrix.mode }}"

strategy:
matrix:
Expand All @@ -19,13 +23,18 @@ jobs:
- "5.0"
- "6.0"
- "7.0"
- "8.0"
php:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
laravel:
- "10.*"
- "11.*"
driver:
- 1
- 2
include:
- php: "8.1"
laravel: "10.*"
Expand Down Expand Up @@ -59,11 +68,19 @@ jobs:
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.driver == 1 && env.MONGODB_EXT_V1 || env.MONGODB_EXT_V2 }}
key: "extcache-v${{ matrix.driver }}"

- name: "Installing php"
uses: "shivammathur/setup-php@v2"
with:
php-version: ${{ matrix.php }}
extensions: "curl,mbstring,xdebug"
extensions: "curl,mbstring,xdebug,${{ matrix.driver == 1 && env.MONGODB_EXT_V1 || env.MONGODB_EXT_V2 }}"
coverage: "xdebug"
tools: "composer"

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"license": "MIT",
"require": {
"php": "^8.1",
"ext-mongodb": "^1.15",
"ext-mongodb": "^1.21|^2",
"composer-runtime-api": "^2.0.0",
"illuminate/cache": "^10.36|^11",
"illuminate/container": "^10.0|^11",
"illuminate/database": "^10.30|^11",
"illuminate/events": "^10.0|^11",
"illuminate/support": "^10.0|^11",
"mongodb/mongodb": "^1.15"
"mongodb/mongodb": "^1.21|^2"
},
"require-dev": {
"mongodb/builder": "^0.2",
Expand Down
12 changes: 12 additions & 0 deletions docs/compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ the {+odm-short+} that you can use together.
To find compatibility information for unmaintained versions of the {+odm-short+},
see `Laravel Version Compatibility <{+mongodb-laravel-gh+}/blob/3.9/README.md#installation>`__
on GitHub.

PHP Driver Compatibility
------------------------

To use {+odm-long+} v4.9 or later, you must install v1.21 of the
{+php-library+} and {+php-extension+}.

.. important:: {+php-extension+} v2.0 Compatibility

If you upgrade the {+php-extension+} to v2.0, you must also upgrade
{+odm-long+} to v4.9.0. {+odm-long+} v4.9.0 still supports v1.x
versions of the extension.
2 changes: 1 addition & 1 deletion docs/feature-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Migration Features
------------------

The {+odm-short+} supports all Laravel migration features, but the
implementation is specific to MongoDB's schemaless model.
implementation is specific to MongoDB's schema-flexible model.

Seeding Features
----------------
Expand Down
11 changes: 6 additions & 5 deletions docs/fundamentals/database-collection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ methods in your application:

.. note::

MongoDB is a schemaless database, so the preceding schema builder methods
query the database data rather than the schema.
MongoDB is a schema-flexible database, so the preceding schema
builder methods query the database data rather than the schema.

Example
```````
Expand Down Expand Up @@ -265,9 +265,10 @@ collection fields:

.. note::

MongoDB is a schemaless database, so the preceding methods query the collection
data rather than the database schema. If the specified collection doesn't exist
or is empty, these methods return a value of ``false``.
MongoDB is a schema-flexible database, so the preceding methods query
the collection data rather than the database schema. If the specified
collection doesn't exist or is empty, these methods return a value of
``false``.

Example
```````
Expand Down
6 changes: 3 additions & 3 deletions docs/quick-start/view-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ View MongoDB Data
.. code-block:: none
:copyable: false

INFO View [resources/views/browse_movie.blade.php] created successfully.
INFO View [resources/views/browse_movies.blade.php] created successfully.

Open the ``browse_movie.blade.php`` view file in the ``resources/views``
Open the ``browse_movies.blade.php`` view file in the ``resources/views``
directory. Replace the contents with the following code and save the
changes:

Expand Down Expand Up @@ -141,7 +141,7 @@ View MongoDB Data

.. step:: Optionally, view your results as JSON documents

Rather than generating a view and editing the ``browse_movie.blade.php`` file, you can
Rather than generating a view and editing the ``browse_movies.blade.php`` file, you can
use the ``toJson()`` method to display your results in JSON format.

Replace the ``show()`` function with the following code to retrieve results and
Expand Down
4 changes: 2 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(array $config)
$this->connection = $this->createConnection($dsn, $config, $options);

// Select database
$this->db = $this->connection->selectDatabase($this->getDefaultDatabaseName($dsn, $config));
$this->db = $this->connection->getDatabase($this->getDefaultDatabaseName($dsn, $config));

$this->tablePrefix = $config['prefix'] ?? '';

Expand Down Expand Up @@ -117,7 +117,7 @@ public function table($table, $as = null)
*/
public function getCollection($name)
{
return new Collection($this, $this->db->selectCollection($this->tablePrefix . $name));
return new Collection($this, $this->db->getCollection($this->tablePrefix . $name));
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\Exception\WriteException;
use MongoDB\Driver\Exception\BulkWriteException;
use MongoDB\Laravel\Connection;
use MongoDB\Laravel\Helpers\QueriesRelationships;
use MongoDB\Laravel\Query\AggregationBuilder;
Expand Down Expand Up @@ -222,7 +222,7 @@ public function createOrFirst(array $attributes = [], array $values = [])

try {
return $this->create(array_merge($attributes, $values));
} catch (WriteException $e) {
} catch (BulkWriteException $e) {
if ($e->getCode() === self::DUPLICATE_KEY_ERROR) {
return $this->where($attributes)->first() ?? throw $e;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MongoDBServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function registerFlysystemAdapter(): void
}

$bucket = $connection->getMongoClient()
->selectDatabase($config['database'] ?? $connection->getDatabaseName())
->getDatabase($config['database'] ?? $connection->getDatabaseName())
->selectGridFSBucket(['bucketName' => $config['bucket'] ?? 'fs', 'disableMD5' => true]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getTables()
$collections = [];

foreach ($db->listCollectionNames() as $collectionName) {
$stats = $db->selectCollection($collectionName)->aggregate([
$stats = $db->getCollection($collectionName)->aggregate([
['$collStats' => ['storageStats' => ['scale' => 1]]],
['$project' => ['storageStats.totalSize' => 1]],
])->toArray();
Expand Down Expand Up @@ -176,7 +176,7 @@ public function getTableListing()

public function getColumns($table)
{
$stats = $this->connection->getMongoDB()->selectCollection($table)->aggregate([
$stats = $this->connection->getMongoDB()->getCollection($table)->aggregate([
// Sample 1,000 documents to get a representative sample of the collection
['$sample' => ['size' => 1_000]],
// Convert each document to an array of fields
Expand Down Expand Up @@ -224,7 +224,7 @@ public function getColumns($table)

public function getIndexes($table)
{
$indexes = $this->connection->getMongoDB()->selectCollection($table)->listIndexes();
$indexes = $this->connection->getMongoDB()->getCollection($table)->listIndexes();

$indexList = [];
foreach ($indexes as $index) {
Expand Down
6 changes: 3 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function testFindWithTimeout()
$id = DB::table('users')->insertGetId(['name' => 'John Doe']);

$subscriber = new class implements CommandSubscriber {
public function commandStarted(CommandStartedEvent $event)
public function commandStarted(CommandStartedEvent $event): void
{
if ($event->getCommandName() !== 'find') {
return;
Expand All @@ -166,11 +166,11 @@ public function commandStarted(CommandStartedEvent $event)
Assert::assertSame(1000, $event->getCommand()->maxTimeMS);
}

public function commandFailed(CommandFailedEvent $event)
public function commandFailed(CommandFailedEvent $event): void
{
}

public function commandSucceeded(CommandSucceededEvent $event)
public function commandSucceeded(CommandSucceededEvent $event): void
{
}
};
Expand Down
Loading