Skip to content

Commit e3a832d

Browse files
Merge branch 'master' into patch-1
2 parents 5b42dcc + 20d05ad commit e3a832d

19 files changed

+336
-81
lines changed

.github/workflows/build-ci.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
tags:
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ${{matrix.os}}
12+
strategy:
13+
matrix:
14+
php: [7.1, 7.2, 7.3, 7.4]
15+
os: ['ubuntu-latest']
16+
services:
17+
mongo:
18+
image: mongo
19+
ports:
20+
- 27017:27017
21+
mysql:
22+
image: mysql:5.7
23+
ports:
24+
- 3307:3306
25+
env:
26+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
27+
MYSQL_DATABASE: 'unittest'
28+
MYSQL_ROOT_PASSWORD:
29+
name: PHP ${{ matrix.php }} Test ${{ matrix.env }}
30+
31+
steps:
32+
- uses: actions/checkout@v1
33+
- name: Show php version
34+
run: php${{ matrix.php }} -v && composer -V
35+
- name: Debug if needed
36+
run: if [[ "$DEBUG" == "true" ]]; then docker version && env; fi
37+
env:
38+
DEBUG: ${{secrets.DEBUG}}
39+
- name: Get Composer Cache Directory
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
- name: Cache dependencies
43+
uses: actions/cache@v1
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
47+
restore-keys: ${{ matrix.os }}-composer-
48+
- name: Install dependencies
49+
run: |
50+
composer install --no-interaction
51+
- name: Generating code coverage
52+
run: |
53+
mkdir -p build/logs
54+
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
55+
env:
56+
MONGO_HOST: 0.0.0.0
57+
MYSQL_HOST: 0.0.0.0
58+
MYSQL_PORT: 3307
59+
- name: Send coveralls
60+
run: vendor/bin/php-coveralls -v
61+
env:
62+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.styleci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: laravel

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Laravel MongoDB
22
===============
33

4-
[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Build Status](http://img.shields.io/travis/jenssegers/laravel-mongodb.svg)](https://travis-ci.org/jenssegers/laravel-mongodb) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/laravel-mongodb.svg)](https://coveralls.io/r/jenssegers/laravel-mongodb?branch=master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)
4+
[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/laravel-mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/mongodb.svg)](https://packagist.org/packages/jenssegers/mongodb) [![Build Status](https://img.shields.io/github/workflow/status/jenssegers/laravel-mongodb/CI)](https://github.com/jenssegers/laravel-mongodb/actions) [![Coverage Status](https://coveralls.io/repos/github/jenssegers/laravel-mongodb/badge.svg?branch=master)](https://coveralls.io/github/jenssegers/laravel-mongodb?branch=master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)
55

66
An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. *This library extends the original Laravel classes, so it uses exactly the same methods.*
77

@@ -15,7 +15,6 @@ Table of contents
1515
* [Query Builder](#query-builder)
1616
* [Schema](#schema)
1717
* [Extensions](#extensions)
18-
* [Troubleshooting](#troubleshooting)
1918
* [Examples](#examples)
2019

2120
Installation
@@ -45,6 +44,7 @@ composer require jenssegers/mongodb
4544
5.6.x | 3.4.x
4645
5.7.x | 3.4.x
4746
5.8.x | 3.5.x
47+
6.0.x | 3.6.x
4848

4949
And add the service provider in `config/app.php`:
5050

@@ -153,8 +153,8 @@ You can connect to multiple servers or replica sets with the following configura
153153
'username' => env('DB_USERNAME'),
154154
'password' => env('DB_PASSWORD'),
155155
'options' => [
156-
'replicaSet' => 'replicaSetName'
157-
]
156+
'replicaSet' => 'replicaSetName'
157+
]
158158
],
159159
```
160160

@@ -253,7 +253,18 @@ Schema::create('users', function($collection)
253253
$collection->unique('email');
254254
});
255255
```
256+
You can also pass all the parameters specified in the MongoDB docs [here](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types) in the `$options` parameter. For example:
256257

258+
```
259+
Schema::create('users', function($collection)
260+
{
261+
$collection->index('username',null,null,[
262+
'sparse' => true,
263+
'unique' => true,
264+
'background' => true
265+
]);
266+
});
267+
```
257268
Supported operations are:
258269

259270
- create and drop
@@ -263,7 +274,7 @@ Supported operations are:
263274
- unique
264275
- background, sparse, expire, geospatial (MongoDB specific)
265276

266-
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on http://laravel.com/docs/schema
277+
All other (unsupported) operations are implemented as dummy pass-through methods, because MongoDB does not use a predefined schema. Read more about the schema builder on https://laravel.com/docs/6.0/migrations#tables
267278

268279
### Geospatial indexes
269280

@@ -312,6 +323,7 @@ If you want to use MongoDB as your database backend, change the driver in `confi
312323
'queue' => 'default',
313324
'expire' => 60,
314325
],
326+
]
315327
```
316328

317329
If you want to use MongoDB to handle failed jobs, change the database in `config/queue.php`:
@@ -320,7 +332,7 @@ If you want to use MongoDB to handle failed jobs, change the database in `config
320332
'failed' => [
321333
'database' => 'mongodb',
322334
'table' => 'failed_jobs',
323-
],
335+
],
324336
```
325337

326338
And add the service provider in `config/app.php`:
@@ -549,13 +561,13 @@ User::where('name', 'regex', new \MongoDB\BSON\Regex("/.*doe/i"))->get();
549561
**NOTE:** you can also use the Laravel regexp operations. These are a bit more flexible and will automatically convert your regular expression string to a MongoDB\BSON\Regex object.
550562

551563
```php
552-
User::where('name', 'regexp', '/.*doe/i'))->get();
564+
User::where('name', 'regexp', '/.*doe/i')->get();
553565
```
554566

555567
And the inverse:
556568

557569
```php
558-
User::where('name', 'not regexp', '/.*doe/i'))->get();
570+
User::where('name', 'not regexp', '/.*doe/i')->get();
559571
```
560572

561573
**Type**
@@ -601,15 +613,15 @@ $users = User::where('location', 'geoWithin', [
601613
[
602614
-0.1450383,
603615
51.5069158,
604-
],
616+
],
605617
[
606618
-0.1367563,
607619
51.5100913,
608-
],
620+
],
609621
[
610622
-0.1270247,
611623
51.5013233,
612-
],
624+
],
613625
[
614626
-0.1450383,
615627
51.5069158,
@@ -693,7 +705,7 @@ For more information about model manipulation, check http://laravel.com/docs/elo
693705

694706
### Dates
695707

696-
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators
708+
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: https://laravel.com/docs/5.0/eloquent#date-mutators
697709

698710
Example:
699711

@@ -770,7 +782,7 @@ class User extends Eloquent {
770782
```
771783

772784

773-
Other relations are not yet supported, but may be added in the future. Read more about these relations on http://laravel.com/docs/eloquent#relationships
785+
Other relations are not yet supported, but may be added in the future. Read more about these relations on https://laravel.com/docs/master/eloquent-relationships
774786

775787
### EmbedsMany Relations
776788

@@ -969,7 +981,7 @@ $cursor = DB::collection('users')->raw(function($collection)
969981
Optional: if you don't pass a closure to the raw method, the internal MongoCollection object will be accessible:
970982

971983
```php
972-
$model = User::raw()->findOne(['age' => array('$lt' => 18)]);
984+
$model = User::raw()->findOne(['age' => ['$lt' => 18]]);
973985
```
974986

975987
The internal MongoClient and MongoDB objects can be accessed like this:
@@ -1063,7 +1075,7 @@ You may easily cache the results of a query using the remember method:
10631075
$users = User::remember(10)->get();
10641076
```
10651077

1066-
*From: http://laravel.com/docs/queries#caching-queries*
1078+
*From: https://laravel.com/docs/4.2/queries#caching-queries*
10671079

10681080
### Query Logging
10691081

@@ -1073,4 +1085,4 @@ By default, Laravel keeps a log in memory of all queries that have been run for
10731085
DB::connection()->disableQueryLog();
10741086
```
10751087

1076-
*From: http://laravel.com/docs/database#query-logging*
1088+
*From: https://laravel.com/docs/4.2/database#query-logging*

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@
2929
"phpunit/phpunit": "^6.0|^7.0|^8.0",
3030
"orchestra/testbench": "^3.1|^4.0",
3131
"mockery/mockery": "^1.0",
32-
"satooshi/php-coveralls": "^2.0",
33-
"doctrine/dbal": "^2.5"
32+
"php-coveralls/php-coveralls": "dev-add-support-for-github-actions",
33+
"doctrine/dbal": "^2.5",
34+
"phpunit/phpcov": "5.0.0"
3435
},
36+
"repositories": [
37+
{
38+
"type": "vcs",
39+
"url": "https://github.com/Smolevich/php-coveralls"
40+
}
41+
],
3542
"autoload": {
3643
"psr-0": {
3744
"Jenssegers\\Mongodb": "src/"

phpunit.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@
4040
<file>tests/ValidationTest.php</file>
4141
</testsuite>
4242
</testsuites>
43+
<filter>
44+
<whitelist processUncoveredFilesFromWhitelist="true">
45+
<directory suffix=".php">./src</directory>
46+
</whitelist>
47+
</filter>
4348
<php>
4449
<env name="MONGO_HOST" value="mongodb"/>
4550
<env name="MONGO_DATABASE" value="unittest"/>
4651
<env name="MONGO_PORT" value="27017"/>
4752
<env name="MYSQL_HOST" value="mysql"/>
53+
<env name="MYSQL_PORT" value="3306"/>
4854
<env name="MYSQL_DATABASE" value="unittest"/>
4955
<env name="MYSQL_USERNAME" value="root"/>
5056
<env name="QUEUE_CONNECTION" value="database"/>

src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ protected function getPayload($email, $token)
2525
* @inheritdoc
2626
*/
2727
protected function tokenExpired($createdAt)
28+
{
29+
$createdAt = $this->convertDateTime($createdAt);
30+
31+
return parent::tokenExpired($createdAt);
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function tokenRecentlyCreated($createdAt)
38+
{
39+
$createdAt = $this->convertDateTime($createdAt);
40+
41+
return parent::tokenRecentlyCreated($createdAt);
42+
}
43+
44+
private function convertDateTime($createdAt)
2845
{
2946
// Convert UTCDateTime to a date string.
3047
if ($createdAt instanceof UTCDateTime) {
@@ -37,6 +54,6 @@ protected function tokenExpired($createdAt)
3754
$createdAt = $date->format('Y-m-d H:i:s');
3855
}
3956

40-
return parent::tokenExpired($createdAt);
57+
return $createdAt;
4158
}
4259
}

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getDateFormat()
118118
*/
119119
public function freshTimestamp()
120120
{
121-
return new UTCDateTime(time() * 1000);
121+
return new UTCDateTime(Carbon::now());
122122
}
123123

124124
/**

src/Jenssegers/Mongodb/MongodbQueueServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Jenssegers\Mongodb;
44

5+
use DB;
56
use Illuminate\Queue\QueueServiceProvider;
67
use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
78

@@ -13,7 +14,7 @@ class MongodbQueueServiceProvider extends QueueServiceProvider
1314
protected function registerFailedJobServices()
1415
{
1516
// Add compatible queue failer if mongodb is configured.
16-
if (config('queue.failed.database') == 'mongodb') {
17+
if (DB::connection(config('queue.failed.database'))->getDriverName() == 'mongodb') {
1718
$this->app->singleton('queue.failer', function ($app) {
1819
return new MongoFailedJobProvider($app['db'], config('queue.failed.database'), config('queue.failed.table'));
1920
});

0 commit comments

Comments
 (0)