Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/5.0' into DOCSP-43172-remove-d…
Browse files Browse the repository at this point in the history
…atabasetoken-class
  • Loading branch information
norareidy committed Sep 6, 2024
2 parents 0af9fb3 + 2ee0dd9 commit f0b1b5c
Show file tree
Hide file tree
Showing 40 changed files with 289 additions and 584 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
11 changes: 4 additions & 7 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
- "6.0"
- "7.0"
php:
- "8.1"
- "8.2"
- "8.3"
laravel:
- "10.*"
- "11.*"
mode:
- ""
include:
- php: "8.1"
laravel: "10.*"
- php: "8.2"
laravel: "11.*"
mongodb: "5.0"
mode: "low-deps"
os: "ubuntu-latest"
Expand All @@ -37,9 +37,6 @@ jobs:
mongodb: "7.0"
mode: "ignore-php-req"
os: "ubuntu-latest"
exclude:
- php: "8.1"
laravel: "11.*"

steps:
- uses: "actions/checkout@v4"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
strategy:
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ All notable changes to this project will be documented in this file.

## [5.0.0] - next

* **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)
* Remove support for Laravel 10 by @GromNaN in [#3123](https://github.com/mongodb/laravel-mongodb/pull/3123)
* **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)

## [4.8.0] - 2024-08-27

Expand Down
28 changes: 13 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,27 @@
],
"license": "MIT",
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-mongodb": "^1.15",
"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"
"illuminate/cache": "^11",
"illuminate/container": "^11",
"illuminate/database": "^11",
"illuminate/events": "^11",
"illuminate/support": "^11",
"mongodb/mongodb": "^1.18"
},
"require-dev": {
"mongodb/builder": "^0.2",
"league/flysystem-gridfs": "^3.28",
"league/flysystem-read-only": "^3.0",
"phpunit/phpunit": "^10.3",
"orchestra/testbench": "^8.0|^9.0",
"phpunit/phpunit": "^10.5",
"orchestra/testbench": "^9.0",
"mockery/mockery": "^1.4.4",
"doctrine/coding-standard": "12.0.x-dev",
"spatie/laravel-query-builder": "^5.6",
"phpstan/phpstan": "^1.10"
},
"conflict": {
"illuminate/bus": "< 10.37.2"
"phpstan/phpstan": "^1.10",
"rector/rector": "^1.2"
},
"suggest": {
"league/flysystem-gridfs": "Filesystem storage in MongoDB with GridFS",
Expand All @@ -68,7 +66,6 @@
"laravel": {
"providers": [
"MongoDB\\Laravel\\MongoDBServiceProvider",
"MongoDB\\Laravel\\MongoDBQueueServiceProvider",
"MongoDB\\Laravel\\MongoDBBusServiceProvider"
]
}
Expand All @@ -77,7 +74,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
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 @@ type, to the Laravel ``datetime`` type.
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 `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
This conversion lets you use the PHP `DateTime
<https://www.php.net/manual/en/class.datetime.php>`__ 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
5 changes: 3 additions & 2 deletions docs/includes/query-builder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
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 +64,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
2 changes: 1 addition & 1 deletion docs/includes/usage-examples/FindOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function testFindOne(): void
// end-find-one

$this->assertInstanceOf(Movie::class, $movie);
$this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
}
}
24 changes: 22 additions & 2 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,28 @@ Logical OR Example

The following example shows how to chain the ``orWhere()``
query builder method to retrieve documents from the
``movies`` collection that either match the ``year``
value of ``1955`` or match the ``title`` value ``"Back to the Future"``:
``movies`` collection in which the value of the ``_id``
field is ``ObjectId('573a1398f29313caabce9682')`` or
the value of the ``title`` field is ``"Back to the Future"``:

.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
:language: php
:dedent:
:start-after: begin query orWhere
:end-before: end query orWhere

.. note::

You can use the ``id`` alias in your queries to represent the
``_id`` field in MongoDB documents, as shown in the preceding
code. When you run a find operation using the query builder, {+odm-short+}
automatically converts between ``id`` and ``_id``. This provides better
compatibility with Laravel, as the framework assumes that each record has a
primary key named ``id`` by default.

Because of this behavior, you cannot have two separate ``id`` and ``_id``
fields in your documents.

.. _laravel-query-builder-logical-and:

Logical AND Example
Expand Down Expand Up @@ -346,6 +359,13 @@ query builder method to retrieve documents from the
:start-after: begin query whereDate
:end-before: end query whereDate

.. note:: Date Query Result Type

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.

.. _laravel-query-builder-pattern:

Text Pattern Match Example
Expand Down
13 changes: 12 additions & 1 deletion docs/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Overview

On this page, you can learn how to upgrade {+odm-long+} to a new major version.
This page also includes the changes you must make to your application to upgrade
your object-document mapper (ODM) version without losing functionality, if applicable.
your version of the {+odm-short+} without losing functionality, if applicable.

How to Upgrade
--------------
Expand Down Expand Up @@ -61,6 +61,9 @@ version releases that introduced them. When upgrading library versions,
address all the breaking changes between your current version and the
planned upgrade version.

- :ref:`laravel-breaking-changes-v5.x`
- :ref:`laravel-breaking-changes-v4.x`

.. _laravel-breaking-changes-v5.x:

Version 5.x Breaking Changes
Expand All @@ -77,6 +80,14 @@ This library version introduces the following breaking changes:
- ``MongoDB\Laravel\Queue\Failed\MongoFailedJobProvider``. Instead,
use the default ``Illuminate\Queue\Failed\DatabaseFailedJobProvider``
class and specify a connection to MongoDB.

- In query results, the library converts BSON ``UTCDateTime`` objects to ``Carbon``
date classes, applying the default timezone.

- ``id`` is an alias for the ``_id`` field in MongoDB documents, and the library
automatically converts between ``id`` and ``_id`` when querying data. Because
of this behavior, you cannot have two separate ``id`` and ``_id`` fields in your
documents.

.. _laravel-breaking-changes-v4.x:

Expand Down
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__FILE__,
__DIR__ . '/docs',
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets()
->withTypeCoverageLevel(0)
->withSkip([
RemoveExtraParametersRector::class,
ClosureToArrowFunctionRector::class,
NullToStrictStringFuncCallArgRector::class,
MixedTypeRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
]);
59 changes: 0 additions & 59 deletions src/Auth/DatabaseTokenRepository.php

This file was deleted.

23 changes: 0 additions & 23 deletions src/Auth/PasswordBrokerManager.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Auth/PasswordResetServiceProvider.php

This file was deleted.

Loading

0 comments on commit f0b1b5c

Please sign in to comment.