Skip to content

Commit

Permalink
Merge branch '5.0' into merge-4.8-into-5.0-1729798205060
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir authored Oct 24, 2024
2 parents 4123eff + b51aeff commit 25f7e8c
Show file tree
Hide file tree
Showing 85 changed files with 1,284 additions and 1,308 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ This will help reviewers and should be a good start for the documentation.

- [ ] Add tests and ensure they pass
- [ ] Add an entry to the CHANGELOG.md file
- [ ] Update documentation for new features
3 changes: 2 additions & 1 deletion .github/workflows/merge-up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Merge up
on:
push:
branches:
- "[0-9]+.[0-9]+"
- "[0-9]+.[0-9x]+"

env:
GH_TOKEN: ${{ secrets.MERGE_UP_TOKEN }}
Expand All @@ -28,4 +28,5 @@ jobs:
with:
ref: ${{ github.ref_name }}
branchNamePattern: '<major>.<minor>'
devBranchNamePattern: '<major>.x'
enableAutoMerge: true
1 change: 1 addition & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
php:
- '8.1'
- '8.2'
- '8.3'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Changelog
All notable changes to this project will be documented in this file.

## [5.0.2] - 2024-09-17

* Fix missing return types in CommandSubscriber by @GromNaN in [#3158](https://github.com/mongodb/laravel-mongodb/pull/3158)

## [5.0.1] - 2024-09-13

* Restore support for Laravel 10 by @GromNaN in [#3148](https://github.com/mongodb/laravel-mongodb/pull/3148)

## [5.0.0] - 2024-09-12

* **BREAKING CHANGE** Use `id` as an alias for `_id` in commands and queries for compatibility with Eloquent packages by @GromNaN in [#3040](https://github.com/mongodb/laravel-mongodb/pull/3040) and [#3136](https://github.com/mongodb/laravel-mongodb/pull/3136)
* **BREAKING CHANGE** Make Query\Builder return objects instead of array to match Laravel behavior by @GromNaN in [#3107](https://github.com/mongodb/laravel-mongodb/pull/3107)
* **BREAKING CHANGE** In DB query results, convert BSON `UTCDateTime` objects into `Carbon` date with the default timezone by @GromNaN in [#3119](https://github.com/mongodb/laravel-mongodb/pull/3119)
* Remove `MongoFailedJobProvider`, replaced by Laravel `DatabaseFailedJobProvider` by @GromNaN in [#3122](https://github.com/mongodb/laravel-mongodb/pull/3122)
* Remove custom `PasswordResetServiceProvider`, use the default `DatabaseTokenRepository` by @GromNaN in [#3124](https://github.com/mongodb/laravel-mongodb/pull/3124)
* Remove `Blueprint::background()` method by @GromNaN in [#3132](https://github.com/mongodb/laravel-mongodb/pull/3132)
* Replace `Collection` proxy class with Driver monitoring by @GromNaN in [#3137]((https://github.com/mongodb/laravel-mongodb/pull/3137)
* Support options in `count()` queries by @verduck in [#3142](https://github.com/mongodb/laravel-mongodb/pull/3142)

## [4.8.0] - 2024-08-27

* Add `Query\Builder::incrementEach()` and `decrementEach()` methods by @SmallRuralDog in [#2550](https://github.com/mongodb/laravel-mongodb/pull/2550)
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"illuminate/database": "^10.30|^11",
"illuminate/events": "^10.0|^11",
"illuminate/support": "^10.0|^11",
"mongodb/mongodb": "^1.15"
"mongodb/mongodb": "^1.18"
},
"require-dev": {
"mongodb/builder": "^0.2",
Expand All @@ -41,7 +41,8 @@
"mockery/mockery": "^1.4.4",
"doctrine/coding-standard": "12.0.x-dev",
"spatie/laravel-query-builder": "^5.6",
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^1.10",
"rector/rector": "^1.2"
},
"conflict": {
"illuminate/bus": "< 10.37.2"
Expand All @@ -68,7 +69,6 @@
"laravel": {
"providers": [
"MongoDB\\Laravel\\MongoDBServiceProvider",
"MongoDB\\Laravel\\MongoDBQueueServiceProvider",
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
]
}
Expand All @@ -77,7 +77,8 @@
"test": "phpunit",
"test:coverage": "phpunit --coverage-clover ./coverage.xml",
"cs": "phpcs",
"cs:fix": "phpcbf"
"cs:fix": "phpcbf",
"rector": "rector"
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion docs/compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Compatibility
:class: singlecol

.. meta::
:keywords: laravel 9, laravel 10, laravel 11, 4.0, 4.1, 4.2
:keywords: laravel 9, laravel 10, laravel 11, 4.0, 4.1, 4.2, 5.0

Laravel Compatibility
---------------------
Expand Down
19 changes: 11 additions & 8 deletions docs/eloquent-models/model-class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ model attribute, stored in MongoDB as a :php:`MongoDB\\BSON\\UTCDateTime
To learn more, see `Attribute Casting <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-mutators#attribute-casting>`__
in the Laravel documentation.

This conversion lets you use the PHP :php:`DateTime <class.datetime>`
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
This conversion lets you use the PHP :php:`DateTime
<class.datetime>` class to work with dates
in this field. The following example shows a Laravel query that uses the
casting helper on the model to query for planets with a ``discovery_dt`` of
less than three years ago:
Expand All @@ -226,6 +226,13 @@ less than three years ago:

Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get();

.. note:: Carbon Date Class

Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
classes in query results. The {+odm-short+} applies the default
timezone when performing this conversion.

To learn more about MongoDB's data types, see :manual:`BSON Types </reference/bson-types/>`
in the Server manual.

Expand Down Expand Up @@ -295,12 +302,8 @@ including this trait, you can make the third-party class compatible with
MongoDB.

When you apply the ``DocumentModel`` trait to a model class, you must
declare the following properties in your class:

- ``$primaryKey = '_id'``, because the ``_id`` field uniquely
identifies MongoDB documents
- ``$keyType = 'string'``, because the {+odm-short+} casts MongoDB
``ObjectId`` values to type ``string``
set the ``$keyType`` property to ``'string'`` as the {+odm-short+}
casts MongoDB ``ObjectId`` values to type ``string``.

Extended Class Example
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion docs/includes/auth/PersonalAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ class PersonalAccessToken extends SanctumToken

protected $connection = 'mongodb';
protected $table = 'personal_access_tokens';
protected $primaryKey = '_id';
protected $keyType = 'string';
}
1 change: 0 additions & 1 deletion docs/includes/eloquent-models/PlanetThirdParty.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class Planet extends CelestialBody
use DocumentModel;

protected $fillable = ['name', 'diameter'];
protected $primaryKey = '_id';
protected $keyType = 'string';
}
2 changes: 1 addition & 1 deletion docs/includes/framework-compatibility-laravel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Laravel 10.x
- Laravel 9.x

* - 4.2 to 4.8
* - 4.2 to 5.0
- ✓
- ✓
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testModelUpdateFluent(): void

// begin model update one fluent
$concert = Concert::where(['performer' => 'Brad Mehldau'])
->orderBy('_id')
->orderBy('id')
->first()
->update(['venue' => 'Manchester Arena', 'ticketsSold' => 9543]);
// end model update one fluent
Expand Down Expand Up @@ -370,31 +370,31 @@ public function testModelDeleteById(): void

$data = [
[
'_id' => 'CH-0401242000',
'id' => 'CH-0401242000',
'performer' => 'Mitsuko Uchida',
'venue' => 'Carnegie Hall',
'genres' => ['classical'],
'ticketsSold' => 2121,
'performanceDate' => new UTCDateTime(Carbon::create(2024, 4, 1, 20, 0, 0, 'EST')),
],
[
'_id' => 'MSG-0212252000',
'id' => 'MSG-0212252000',
'performer' => 'Brad Mehldau',
'venue' => 'Philharmonie de Paris',
'genres' => [ 'jazz', 'post-bop' ],
'ticketsSold' => 5745,
'performanceDate' => new UTCDateTime(Carbon::create(2025, 2, 12, 20, 0, 0, 'CET')),
],
[
'_id' => 'MSG-021222000',
'id' => 'MSG-021222000',
'performer' => 'Billy Joel',
'venue' => 'Madison Square Garden',
'genres' => [ 'rock', 'soft rock', 'pop rock' ],
'ticketsSold' => 12852,
'performanceDate' => new UTCDateTime(Carbon::create(2025, 2, 12, 20, 0, 0, 'CET')),
],
[
'_id' => 'SF-06302000',
'id' => 'SF-06302000',
'performer' => 'The Rolling Stones',
'venue' => 'Soldier Field',
'genres' => [ 'rock', 'pop', 'blues' ],
Expand Down Expand Up @@ -478,22 +478,22 @@ public function testModelDeleteMultipleById(): void
Concert::truncate();
$data = [
[
'_id' => 3,
'id' => 3,
'performer' => 'Mitsuko Uchida',
'venue' => 'Carnegie Hall',
],
[
'_id' => 5,
'id' => 5,
'performer' => 'Brad Mehldau',
'venue' => 'Philharmonie de Paris',
],
[
'_id' => 7,
'id' => 7,
'performer' => 'Billy Joel',
'venue' => 'Madison Square Garden',
],
[
'_id' => 9,
'id' => 9,
'performer' => 'The Rolling Stones',
'venue' => 'Soldier Field',
],
Expand Down
30 changes: 22 additions & 8 deletions docs/includes/query-builder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace App\Http\Controllers;

use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
use Illuminate\Pagination\AbstractPaginator;
use Illuminate\Support\Facades\DB;
use MongoDB\BSON\ObjectId;
use MongoDB\BSON\Regex;
use MongoDB\Laravel\Collection;
use MongoDB\Collection;
use MongoDB\Laravel\Tests\TestCase;

use function file_get_contents;
Expand Down Expand Up @@ -63,7 +65,7 @@ public function testOrWhere(): void
// begin query orWhere
$result = DB::connection('mongodb')
->table('movies')
->where('year', 1955)
->where('id', new ObjectId('573a1398f29313caabce9682'))
->orWhere('title', 'Back to the Future')
->get();
// end query orWhere
Expand Down Expand Up @@ -147,14 +149,26 @@ public function testWhereIn(): void
$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
}

public function testWhereCarbon(): void
{
// begin query where date
$result = DB::connection('mongodb')
->table('movies')
->where('released', Carbon::create(2010, 1, 15))
->get();
// end query where date

$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
}

public function testWhereDate(): void
{
// begin query whereDate
// begin query whereDate string
$result = DB::connection('mongodb')
->table('movies')
->whereDate('released', '2010-1-15')
->get();
// end query whereDate
// end query whereDate string

$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
}
Expand Down Expand Up @@ -531,11 +545,11 @@ public function testUpsert(): void

$this->assertSame(2, $result);

$this->assertSame(119, DB::table('movies')->where('title', 'Inspector Maigret')->first()['runtime']);
$this->assertSame(false, DB::table('movies')->where('title', 'Inspector Maigret')->first()['recommended']);
$this->assertSame(119, DB::table('movies')->where('title', 'Inspector Maigret')->first()->runtime);
$this->assertSame(false, DB::table('movies')->where('title', 'Inspector Maigret')->first()->recommended);

$this->assertSame(true, DB::table('movies')->where('title', 'Petit Maman')->first()['recommended']);
$this->assertSame(72, DB::table('movies')->where('title', 'Petit Maman')->first()['runtime']);
$this->assertSame(true, DB::table('movies')->where('title', 'Petit Maman')->first()->recommended);
$this->assertSame(72, DB::table('movies')->where('title', 'Petit Maman')->first()->runtime);
}

public function testUpdateUpsert(): void
Expand Down
2 changes: 1 addition & 1 deletion docs/includes/usage-examples/DeleteOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testDeleteOne(): void

// begin-delete-one
$deleted = Movie::where('title', 'Quiz Show')
->orderBy('_id')
->orderBy('id')
->limit(1)
->delete();

Expand Down
2 changes: 1 addition & 1 deletion docs/includes/usage-examples/FindManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFindMany(): void

// begin-find
$movies = Movie::where('runtime', '>', 900)
->orderBy('_id')
->orderBy('id')
->get();
// end-find

Expand Down
4 changes: 2 additions & 2 deletions docs/includes/usage-examples/FindOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function testFindOne(): void

// begin-find-one
$movie = Movie::where('directors', 'Rob Reiner')
->orderBy('_id')
->orderBy('id')
->first();

echo $movie->toJson();
// end-find-one

$this->assertInstanceOf(Movie::class, $movie);
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/');
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
}
}
2 changes: 1 addition & 1 deletion docs/includes/usage-examples/InsertOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function testInsertOne(): void
// end-insert-one

$this->assertInstanceOf(Movie::class, $movie);
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/');
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","id":"[a-z0-9]{24}"}$/');
}
}
2 changes: 1 addition & 1 deletion docs/includes/usage-examples/UpdateOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testUpdateOne(): void

// begin-update-one
$updates = Movie::where('title', 'Carol')
->orderBy('_id')
->orderBy('id')
->first()
->update([
'imdb' => [
Expand Down
Loading

0 comments on commit 25f7e8c

Please sign in to comment.