Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
e4816615
Commit
e4816615
authored
Sep 05, 2017
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Style fixes
parent
7a85d920
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
236 additions
and
172 deletions
+236
-172
DatabaseTokenRepository.php
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
+3
-1
PasswordResetServiceProvider.php
src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
+3
-1
User.php
src/Jenssegers/Mongodb/Auth/User.php
+6
-4
Collection.php
src/Jenssegers/Mongodb/Collection.php
+7
-5
Connection.php
src/Jenssegers/Mongodb/Connection.php
+13
-11
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+6
-3
EmbedsRelations.php
src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php
+3
-1
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+12
-10
Model.php
src/Jenssegers/Mongodb/Eloquent/Model.php
+18
-16
SoftDeletes.php
src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php
+3
-1
QueriesRelationships.php
src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php
+3
-3
MongodbQueueServiceProvider.php
src/Jenssegers/Mongodb/MongodbQueueServiceProvider.php
+3
-1
MongodbServiceProvider.php
src/Jenssegers/Mongodb/MongodbServiceProvider.php
+3
-1
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+39
-37
Grammar.php
src/Jenssegers/Mongodb/Query/Grammar.php
+3
-1
Processor.php
src/Jenssegers/Mongodb/Query/Processor.php
+3
-1
MongoFailedJobProvider.php
...enssegers/Mongodb/Queue/Failed/MongoFailedJobProvider.php
+7
-5
MongoConnector.php
src/Jenssegers/Mongodb/Queue/MongoConnector.php
+5
-4
MongoJob.php
src/Jenssegers/Mongodb/Queue/MongoJob.php
+3
-1
MongoQueue.php
src/Jenssegers/Mongodb/Queue/MongoQueue.php
+5
-3
BelongsTo.php
src/Jenssegers/Mongodb/Relations/BelongsTo.php
+3
-1
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+10
-8
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+9
-7
EmbedsOne.php
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
+5
-3
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+13
-11
HasMany.php
src/Jenssegers/Mongodb/Relations/HasMany.php
+5
-3
HasOne.php
src/Jenssegers/Mongodb/Relations/HasOne.php
+5
-3
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+3
-1
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+9
-7
Builder.php
src/Jenssegers/Mongodb/Schema/Builder.php
+4
-2
Grammar.php
src/Jenssegers/Mongodb/Schema/Grammar.php
+3
-1
DatabasePresenceVerifier.php
...enssegers/Mongodb/Validation/DatabasePresenceVerifier.php
+16
-14
ValidationServiceProvider.php
...nssegers/Mongodb/Validation/ValidationServiceProvider.php
+3
-1
No files found.
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Auth
;
<?php
namespace
Jenssegers\Mongodb\Auth
;
use
DateTime
;
use
DateTime
;
use
DateTimeZone
;
use
DateTimeZone
;
...
...
src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Auth
;
<?php
namespace
Jenssegers\Mongodb\Auth
;
use
Illuminate\Auth\Passwords\PasswordResetServiceProvider
as
BasePasswordResetServiceProvider
;
use
Illuminate\Auth\Passwords\PasswordResetServiceProvider
as
BasePasswordResetServiceProvider
;
...
...
src/Jenssegers/Mongodb/Auth/User.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Auth
;
<?php
namespace
Jenssegers\Mongodb\Auth
;
use
Illuminate\Auth\Authenticatable
;
use
Illuminate\Auth\Authenticatable
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Model
;
use
Illuminate\Auth\Passwords\CanResetPassword
;
use
Illuminate\Auth\Passwords\CanResetPassword
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Access\Authorizable
as
AuthorizableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
use
Illuminate\Foundation\Auth\Access\Authorizable
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Model
;
class
User
extends
Model
implements
class
User
extends
Model
implements
AuthenticatableContract
,
AuthenticatableContract
,
...
...
src/Jenssegers/Mongodb/Collection.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb
;
<?php
namespace
Jenssegers\Mongodb
;
use
Exception
;
use
Exception
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
...
@@ -53,7 +55,7 @@ class Collection
...
@@ -53,7 +55,7 @@ class Collection
// Convert the query parameters to a json string.
// Convert the query parameters to a json string.
array_walk_recursive
(
$parameters
,
function
(
&
$item
,
$key
)
{
array_walk_recursive
(
$parameters
,
function
(
&
$item
,
$key
)
{
if
(
$item
instanceof
ObjectID
)
{
if
(
$item
instanceof
ObjectID
)
{
$item
=
(
string
)
$item
;
$item
=
(
string
)
$item
;
}
}
});
});
...
@@ -66,7 +68,7 @@ class Collection
...
@@ -66,7 +68,7 @@ class Collection
}
}
}
}
$queryString
=
$this
->
collection
->
getCollectionName
()
.
'.'
.
$method
.
'('
.
implode
(
','
,
$query
)
.
')'
;
$queryString
=
$this
->
collection
->
getCollectionName
()
.
'.'
.
$method
.
'('
.
implode
(
','
,
$query
)
.
')'
;
$this
->
connection
->
logQuery
(
$queryString
,
[],
$time
);
$this
->
connection
->
logQuery
(
$queryString
,
[],
$time
);
}
}
...
...
src/Jenssegers/Mongodb/Connection.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb
;
<?php
namespace
Jenssegers\Mongodb
;
use
Illuminate\Database\Connection
as
BaseConnection
;
use
Illuminate\Database\Connection
as
BaseConnection
;
use
MongoDB\Client
;
use
MongoDB\Client
;
...
@@ -128,10 +130,10 @@ class Connection extends BaseConnection
...
@@ -128,10 +130,10 @@ class Connection extends BaseConnection
}
}
// Check if the credentials are not already set in the options
// Check if the credentials are not already set in the options
if
(
!
isset
(
$options
[
'username'
])
&&
!
empty
(
$config
[
'username'
]))
{
if
(
!
isset
(
$options
[
'username'
])
&&
!
empty
(
$config
[
'username'
]))
{
$options
[
'username'
]
=
$config
[
'username'
];
$options
[
'username'
]
=
$config
[
'username'
];
}
}
if
(
!
isset
(
$options
[
'password'
])
&&
!
empty
(
$config
[
'password'
]))
{
if
(
!
isset
(
$options
[
'password'
])
&&
!
empty
(
$config
[
'password'
]))
{
$options
[
'password'
]
=
$config
[
'password'
];
$options
[
'password'
]
=
$config
[
'password'
];
}
}
...
@@ -155,7 +157,7 @@ class Connection extends BaseConnection
...
@@ -155,7 +157,7 @@ class Connection extends BaseConnection
protected
function
getDsn
(
array
$config
)
protected
function
getDsn
(
array
$config
)
{
{
// Check if the user passed a complete dsn to the configuration.
// Check if the user passed a complete dsn to the configuration.
if
(
!
empty
(
$config
[
'dsn'
]))
{
if
(
!
empty
(
$config
[
'dsn'
]))
{
return
$config
[
'dsn'
];
return
$config
[
'dsn'
];
}
}
...
@@ -164,15 +166,15 @@ class Connection extends BaseConnection
...
@@ -164,15 +166,15 @@ class Connection extends BaseConnection
foreach
(
$hosts
as
&
$host
)
{
foreach
(
$hosts
as
&
$host
)
{
// Check if we need to add a port to the host
// Check if we need to add a port to the host
if
(
strpos
(
$host
,
':'
)
===
false
&&
!
empty
(
$config
[
'port'
]))
{
if
(
strpos
(
$host
,
':'
)
===
false
&&
!
empty
(
$config
[
'port'
]))
{
$host
=
$host
.
':'
.
$config
[
'port'
];
$host
=
$host
.
':'
.
$config
[
'port'
];
}
}
}
}
// Check if we want to authenticate against a specific database.
// Check if we want to authenticate against a specific database.
$auth_database
=
isset
(
$config
[
'options'
])
&&
!
empty
(
$config
[
'options'
][
'database'
])
?
$config
[
'options'
][
'database'
]
:
null
;
$auth_database
=
isset
(
$config
[
'options'
])
&&
!
empty
(
$config
[
'options'
][
'database'
])
?
$config
[
'options'
][
'database'
]
:
null
;
return
'mongodb://'
.
implode
(
','
,
$hosts
)
.
(
$auth_database
?
'/'
.
$auth_database
:
''
);
return
'mongodb://'
.
implode
(
','
,
$hosts
)
.
(
$auth_database
?
'/'
.
$auth_database
:
''
);
}
}
/**
/**
...
...
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
Illuminate\Database\Eloquent\Builder
as
EloquentBuilder
;
use
Illuminate\Database\Eloquent\Builder
as
EloquentBuilder
;
use
Jenssegers\Mongodb\Helpers\QueriesRelationships
;
use
Jenssegers\Mongodb\Helpers\QueriesRelationships
;
...
@@ -8,6 +10,7 @@ use MongoDB\Model\BSONDocument;
...
@@ -8,6 +10,7 @@ use MongoDB\Model\BSONDocument;
class
Builder
extends
EloquentBuilder
class
Builder
extends
EloquentBuilder
{
{
use
QueriesRelationships
;
use
QueriesRelationships
;
/**
/**
* The methods that should be returned from query builder.
* The methods that should be returned from query builder.
*
*
...
@@ -157,10 +160,10 @@ class Builder extends EloquentBuilder
...
@@ -157,10 +160,10 @@ class Builder extends EloquentBuilder
elseif
(
$results
instanceof
BSONDocument
)
{
elseif
(
$results
instanceof
BSONDocument
)
{
$results
=
$results
->
getArrayCopy
();
$results
=
$results
->
getArrayCopy
();
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
}
// The result is a single object.
}
// The result is a single object.
elseif
(
is_array
(
$results
)
and
array_key_exists
(
'_id'
,
$results
))
{
elseif
(
is_array
(
$results
)
and
array_key_exists
(
'_id'
,
$results
))
{
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
}
}
return
$results
;
return
$results
;
...
...
src/Jenssegers/Mongodb/Eloquent/EmbedsRelations.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
use
Jenssegers\Mongodb\Relations\EmbedsMany
;
use
Jenssegers\Mongodb\Relations\EmbedsOne
;
use
Jenssegers\Mongodb\Relations\EmbedsOne
;
...
...
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
Illuminate\Database\Eloquent\Relations\MorphMany
;
use
Illuminate\Database\Eloquent\Relations\MorphMany
;
use
Illuminate\Database\Eloquent\Relations\MorphOne
;
use
Illuminate\Database\Eloquent\Relations\MorphOne
;
...
@@ -23,7 +25,7 @@ trait HybridRelations
...
@@ -23,7 +25,7 @@ trait HybridRelations
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -49,7 +51,7 @@ trait HybridRelations
...
@@ -49,7 +51,7 @@ trait HybridRelations
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
...
@@ -73,7 +75,7 @@ trait HybridRelations
...
@@ -73,7 +75,7 @@ trait HybridRelations
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -99,7 +101,7 @@ trait HybridRelations
...
@@ -99,7 +101,7 @@ trait HybridRelations
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
...
@@ -138,7 +140,7 @@ trait HybridRelations
...
@@ -138,7 +140,7 @@ trait HybridRelations
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
...
@@ -146,7 +148,7 @@ trait HybridRelations
...
@@ -146,7 +148,7 @@ trait HybridRelations
// foreign key name by using the name of the relationship function, which
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
))
{
if
(
is_null
(
$foreignKey
))
{
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
}
}
$instance
=
new
$related
;
$instance
=
new
$related
;
...
@@ -225,18 +227,18 @@ trait HybridRelations
...
@@ -225,18 +227,18 @@ trait HybridRelations
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
// First, we'll need to determine the foreign key and "other key" for the
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
// instances as well as the relationship instances we need for this.
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
()
.
's'
;
$foreignKey
=
$foreignKey
?:
$this
->
getForeignKey
()
.
's'
;
$instance
=
new
$related
;
$instance
=
new
$related
;
$otherKey
=
$otherKey
?:
$instance
->
getForeignKey
()
.
's'
;
$otherKey
=
$otherKey
?:
$instance
->
getForeignKey
()
.
's'
;
// If no table name was provided, we can guess it by concatenating the two
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// models using underscores in alphabetical order. The two model names
...
...
src/Jenssegers/Mongodb/Eloquent/Model.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
DateTime
;
use
DateTime
;
...
@@ -44,13 +46,13 @@ abstract class Model extends BaseModel
...
@@ -44,13 +46,13 @@ abstract class Model extends BaseModel
{
{
// If we don't have a value for 'id', we will use the Mongo '_id' value.
// If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way.
// This allows us to work with models in a more sql-like way.
if
(
!
$value
and
array_key_exists
(
'_id'
,
$this
->
attributes
))
{
if
(
!
$value
and
array_key_exists
(
'_id'
,
$this
->
attributes
))
{
$value
=
$this
->
attributes
[
'_id'
];
$value
=
$this
->
attributes
[
'_id'
];
}
}
// Convert ObjectID to string.
// Convert ObjectID to string.
if
(
$value
instanceof
ObjectID
)
{
if
(
$value
instanceof
ObjectID
)
{
return
(
string
)
$value
;
return
(
string
)
$value
;
}
}
return
$value
;
return
$value
;
...
@@ -75,7 +77,7 @@ abstract class Model extends BaseModel
...
@@ -75,7 +77,7 @@ abstract class Model extends BaseModel
}
}
// Let Eloquent convert the value to a DateTime instance.
// Let Eloquent convert the value to a DateTime instance.
if
(
!
$value
instanceof
DateTime
)
{
if
(
!
$value
instanceof
DateTime
)
{
$value
=
parent
::
asDateTime
(
$value
);
$value
=
parent
::
asDateTime
(
$value
);
}
}
...
@@ -124,7 +126,7 @@ abstract class Model extends BaseModel
...
@@ -124,7 +126,7 @@ abstract class Model extends BaseModel
*/
*/
public
function
getAttribute
(
$key
)
public
function
getAttribute
(
$key
)
{
{
if
(
!
$key
)
{
if
(
!
$key
)
{
return
;
return
;
}
}
...
@@ -134,7 +136,7 @@ abstract class Model extends BaseModel
...
@@ -134,7 +136,7 @@ abstract class Model extends BaseModel
}
}
// This checks for embedded relation support.
// This checks for embedded relation support.
if
(
method_exists
(
$this
,
$key
)
and
!
method_exists
(
self
::
class
,
$key
))
{
if
(
method_exists
(
$this
,
$key
)
and
!
method_exists
(
self
::
class
,
$key
))
{
return
$this
->
getRelationValue
(
$key
);
return
$this
->
getRelationValue
(
$key
);
}
}
...
@@ -191,14 +193,14 @@ abstract class Model extends BaseModel
...
@@ -191,14 +193,14 @@ abstract class Model extends BaseModel
// nicely when your models are converted to JSON.
// nicely when your models are converted to JSON.
foreach
(
$attributes
as
$key
=>
&
$value
)
{
foreach
(
$attributes
as
$key
=>
&
$value
)
{
if
(
$value
instanceof
ObjectID
)
{
if
(
$value
instanceof
ObjectID
)
{
$value
=
(
string
)
$value
;
$value
=
(
string
)
$value
;
}
}
}
}
// Convert dot-notation dates.
// Convert dot-notation dates.
foreach
(
$this
->
getDates
()
as
$key
)
{
foreach
(
$this
->
getDates
()
as
$key
)
{
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$attributes
,
$key
))
{
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$attributes
,
$key
))
{
array_set
(
$attributes
,
$key
,
(
string
)
$this
->
asDateTime
(
array_get
(
$attributes
,
$key
)));
array_set
(
$attributes
,
$key
,
(
string
)
$this
->
asDateTime
(
array_get
(
$attributes
,
$key
)));
}
}
}
}
...
@@ -240,7 +242,7 @@ abstract class Model extends BaseModel
...
@@ -240,7 +242,7 @@ abstract class Model extends BaseModel
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
{
if
(
!
is_array
(
$columns
))
{
$columns
=
[
$columns
];
$columns
=
[
$columns
];
}
}
...
@@ -268,7 +270,7 @@ abstract class Model extends BaseModel
...
@@ -268,7 +270,7 @@ abstract class Model extends BaseModel
}
}
// Do batch push by default.
// Do batch push by default.
if
(
!
is_array
(
$values
))
{
if
(
!
is_array
(
$values
))
{
$values
=
[
$values
];
$values
=
[
$values
];
}
}
...
@@ -292,7 +294,7 @@ abstract class Model extends BaseModel
...
@@ -292,7 +294,7 @@ abstract class Model extends BaseModel
public
function
pull
(
$column
,
$values
)
public
function
pull
(
$column
,
$values
)
{
{
// Do batch pull by default.
// Do batch pull by default.
if
(
!
is_array
(
$values
))
{
if
(
!
is_array
(
$values
))
{
$values
=
[
$values
];
$values
=
[
$values
];
}
}
...
@@ -356,7 +358,7 @@ abstract class Model extends BaseModel
...
@@ -356,7 +358,7 @@ abstract class Model extends BaseModel
*/
*/
public
function
getForeignKey
()
public
function
getForeignKey
()
{
{
return
Str
::
snake
(
class_basename
(
$this
))
.
'_'
.
ltrim
(
$this
->
primaryKey
,
'_'
);
return
Str
::
snake
(
class_basename
(
$this
))
.
'_'
.
ltrim
(
$this
->
primaryKey
,
'_'
);
}
}
/**
/**
...
...
src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
trait
SoftDeletes
trait
SoftDeletes
{
{
...
...
src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php
View file @
e4816615
...
@@ -86,7 +86,7 @@ trait QueriesRelationships
...
@@ -86,7 +86,7 @@ trait QueriesRelationships
$not
=
in_array
(
$operator
,
[
'<'
,
'<='
,
'!='
]);
$not
=
in_array
(
$operator
,
[
'<'
,
'<='
,
'!='
]);
// If we are comparing to 0, we need an additional $not flip.
// If we are comparing to 0, we need an additional $not flip.
if
(
$count
==
0
)
{
if
(
$count
==
0
)
{
$not
=
!
$not
;
$not
=
!
$not
;
}
}
$relations
=
$hasQuery
->
pluck
(
$this
->
getHasCompareKey
(
$relation
));
$relations
=
$hasQuery
->
pluck
(
$this
->
getHasCompareKey
(
$relation
));
...
@@ -112,7 +112,7 @@ trait QueriesRelationships
...
@@ -112,7 +112,7 @@ trait QueriesRelationships
return
$relation
->
getForeignKey
();
return
$relation
->
getForeignKey
();
}
}
throw
new
\Exception
(
class_basename
(
$relation
)
.
' Is Not supported for hybrid query constraints!'
);
throw
new
\Exception
(
class_basename
(
$relation
)
.
' Is Not supported for hybrid query constraints!'
);
}
}
/**
/**
...
@@ -137,7 +137,7 @@ trait QueriesRelationships
...
@@ -137,7 +137,7 @@ trait QueriesRelationships
protected
function
getConstrainedRelatedIds
(
$relations
,
$operator
,
$count
)
protected
function
getConstrainedRelatedIds
(
$relations
,
$operator
,
$count
)
{
{
$relationCount
=
array_count_values
(
array_map
(
function
(
$id
)
{
$relationCount
=
array_count_values
(
array_map
(
function
(
$id
)
{
return
(
string
)
$id
;
// Convert Back ObjectIds to Strings
return
(
string
)
$id
;
// Convert Back ObjectIds to Strings
},
is_array
(
$relations
)
?
$relations
:
$relations
->
flatten
()
->
toArray
()));
},
is_array
(
$relations
)
?
$relations
:
$relations
->
flatten
()
->
toArray
()));
// Remove unwanted related objects based on the operator and count.
// Remove unwanted related objects based on the operator and count.
$relationCount
=
array_filter
(
$relationCount
,
function
(
$counted
)
use
(
$count
,
$operator
)
{
$relationCount
=
array_filter
(
$relationCount
,
function
(
$counted
)
use
(
$count
,
$operator
)
{
...
...
src/Jenssegers/Mongodb/MongodbQueueServiceProvider.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb
;
<?php
namespace
Jenssegers\Mongodb
;
use
Illuminate\Queue\QueueServiceProvider
;
use
Illuminate\Queue\QueueServiceProvider
;
use
Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider
;
use
Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider
;
...
...
src/Jenssegers/Mongodb/MongodbServiceProvider.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb
;
<?php
namespace
Jenssegers\Mongodb
;
use
Illuminate\Support\ServiceProvider
;
use
Illuminate\Support\ServiceProvider
;
use
Jenssegers\Mongodb\Eloquent\Model
;
use
Jenssegers\Mongodb\Eloquent\Model
;
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Query
;
<?php
namespace
Jenssegers\Mongodb\Query
;
use
Closure
;
use
Closure
;
use
DateTime
;
use
DateTime
;
...
@@ -237,18 +239,18 @@ class Builder extends BaseBuilder
...
@@ -237,18 +239,18 @@ class Builder extends BaseBuilder
// Add grouping columns to the $group part of the aggregation pipeline.
// Add grouping columns to the $group part of the aggregation pipeline.
if
(
$this
->
groups
)
{
if
(
$this
->
groups
)
{
foreach
(
$this
->
groups
as
$column
)
{
foreach
(
$this
->
groups
as
$column
)
{
$group
[
'_id'
][
$column
]
=
'$'
.
$column
;
$group
[
'_id'
][
$column
]
=
'$'
.
$column
;
// When grouping, also add the $last operator to each grouped field,
// When grouping, also add the $last operator to each grouped field,
// this mimics MySQL's behaviour a bit.
// this mimics MySQL's behaviour a bit.
$group
[
$column
]
=
[
'$last'
=>
'$'
.
$column
];
$group
[
$column
]
=
[
'$last'
=>
'$'
.
$column
];
}
}
// Do the same for other columns that are selected.
// Do the same for other columns that are selected.
foreach
(
$this
->
columns
as
$column
)
{
foreach
(
$this
->
columns
as
$column
)
{
$key
=
str_replace
(
'.'
,
'_'
,
$column
);
$key
=
str_replace
(
'.'
,
'_'
,
$column
);
$group
[
$key
]
=
[
'$last'
=>
'$'
.
$column
];
$group
[
$key
]
=
[
'$last'
=>
'$'
.
$column
];
}
}
}
}
...
@@ -270,7 +272,7 @@ class Builder extends BaseBuilder
...
@@ -270,7 +272,7 @@ class Builder extends BaseBuilder
$group
[
'aggregate'
]
=
[
'$sum'
=>
1
];
$group
[
'aggregate'
]
=
[
'$sum'
=>
1
];
}
// Pass other functions directly.
}
// Pass other functions directly.
else
{
else
{
$group
[
'aggregate'
]
=
[
'$'
.
$function
=>
'$'
.
$column
];
$group
[
'aggregate'
]
=
[
'$'
.
$function
=>
'$'
.
$column
];
}
}
}
}
}
}
...
@@ -296,7 +298,7 @@ class Builder extends BaseBuilder
...
@@ -296,7 +298,7 @@ class Builder extends BaseBuilder
// apply unwinds for subdocument array aggregation
// apply unwinds for subdocument array aggregation
foreach
(
$unwinds
as
$unwind
)
{
foreach
(
$unwinds
as
$unwind
)
{
$pipeline
[]
=
[
'$unwind'
=>
'$'
.
$unwind
];
$pipeline
[]
=
[
'$unwind'
=>
'$'
.
$unwind
];
}
}
if
(
$group
)
{
if
(
$group
)
{
...
@@ -442,7 +444,7 @@ class Builder extends BaseBuilder
...
@@ -442,7 +444,7 @@ class Builder extends BaseBuilder
$this
->
bindings
[
'select'
]
=
$previousSelectBindings
;
$this
->
bindings
[
'select'
]
=
$previousSelectBindings
;
if
(
isset
(
$results
[
0
]))
{
if
(
isset
(
$results
[
0
]))
{
$result
=
(
array
)
$results
[
0
];
$result
=
(
array
)
$results
[
0
];
return
$result
[
'aggregate'
];
return
$result
[
'aggregate'
];
}
}
...
@@ -453,7 +455,7 @@ class Builder extends BaseBuilder
...
@@ -453,7 +455,7 @@ class Builder extends BaseBuilder
*/
*/
public
function
exists
()
public
function
exists
()
{
{
return
!
is_null
(
$this
->
first
());
return
!
is_null
(
$this
->
first
());
}
}
/**
/**
...
@@ -522,20 +524,20 @@ class Builder extends BaseBuilder
...
@@ -522,20 +524,20 @@ class Builder extends BaseBuilder
foreach
(
$values
as
$value
)
{
foreach
(
$values
as
$value
)
{
// As soon as we find a value that is not an array we assume the user is
// As soon as we find a value that is not an array we assume the user is
// inserting a single document.
// inserting a single document.
if
(
!
is_array
(
$value
))
{
if
(
!
is_array
(
$value
))
{
$batch
=
false
;
$batch
=
false
;
break
;
break
;
}
}
}
}
if
(
!
$batch
)
{
if
(
!
$batch
)
{
$values
=
[
$values
];
$values
=
[
$values
];
}
}
// Batch insert
// Batch insert
$result
=
$this
->
collection
->
insertMany
(
$values
);
$result
=
$this
->
collection
->
insertMany
(
$values
);
return
(
1
==
(
int
)
$result
->
isAcknowledged
());
return
(
1
==
(
int
)
$result
->
isAcknowledged
());
}
}
/**
/**
...
@@ -545,7 +547,7 @@ class Builder extends BaseBuilder
...
@@ -545,7 +547,7 @@ class Builder extends BaseBuilder
{
{
$result
=
$this
->
collection
->
insertOne
(
$values
);
$result
=
$this
->
collection
->
insertOne
(
$values
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
is_null
(
$sequence
))
{
if
(
is_null
(
$sequence
))
{
$sequence
=
'_id'
;
$sequence
=
'_id'
;
}
}
...
@@ -561,7 +563,7 @@ class Builder extends BaseBuilder
...
@@ -561,7 +563,7 @@ class Builder extends BaseBuilder
public
function
update
(
array
$values
,
array
$options
=
[])
public
function
update
(
array
$values
,
array
$options
=
[])
{
{
// Use $set as default operator.
// Use $set as default operator.
if
(
!
starts_with
(
key
(
$values
),
'$'
))
{
if
(
!
starts_with
(
key
(
$values
),
'$'
))
{
$values
=
[
'$set'
=>
$values
];
$values
=
[
'$set'
=>
$values
];
}
}
...
@@ -575,7 +577,7 @@ class Builder extends BaseBuilder
...
@@ -575,7 +577,7 @@ class Builder extends BaseBuilder
{
{
$query
=
[
'$inc'
=>
[
$column
=>
$amount
]];
$query
=
[
'$inc'
=>
[
$column
=>
$amount
]];
if
(
!
empty
(
$extra
))
{
if
(
!
empty
(
$extra
))
{
$query
[
'$set'
]
=
$extra
;
$query
[
'$set'
]
=
$extra
;
}
}
...
@@ -607,7 +609,7 @@ class Builder extends BaseBuilder
...
@@ -607,7 +609,7 @@ class Builder extends BaseBuilder
// Convert ObjectID's to strings
// Convert ObjectID's to strings
if
(
$key
==
'_id'
)
{
if
(
$key
==
'_id'
)
{
$results
=
$results
->
map
(
function
(
$item
)
{
$results
=
$results
->
map
(
function
(
$item
)
{
$item
[
'_id'
]
=
(
string
)
$item
[
'_id'
];
$item
[
'_id'
]
=
(
string
)
$item
[
'_id'
];
return
$item
;
return
$item
;
});
});
}
}
...
@@ -624,13 +626,13 @@ class Builder extends BaseBuilder
...
@@ -624,13 +626,13 @@ class Builder extends BaseBuilder
// If an ID is passed to the method, we will set the where clause to check
// If an ID is passed to the method, we will set the where clause to check
// the ID to allow developers to simply and quickly remove a single row
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
// from their database without manually specifying the where clauses.
if
(
!
is_null
(
$id
))
{
if
(
!
is_null
(
$id
))
{
$this
->
where
(
'_id'
,
'='
,
$id
);
$this
->
where
(
'_id'
,
'='
,
$id
);
}
}
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
DeleteMany
(
$wheres
);
$result
=
$this
->
collection
->
DeleteMany
(
$wheres
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
return
$result
->
getDeletedCount
();
return
$result
->
getDeletedCount
();
}
}
...
@@ -656,7 +658,7 @@ class Builder extends BaseBuilder
...
@@ -656,7 +658,7 @@ class Builder extends BaseBuilder
{
{
$result
=
$this
->
collection
->
drop
();
$result
=
$this
->
collection
->
drop
();
return
(
1
==
(
int
)
$result
->
ok
);
return
(
1
==
(
int
)
$result
->
ok
);
}
}
/**
/**
...
@@ -681,7 +683,7 @@ class Builder extends BaseBuilder
...
@@ -681,7 +683,7 @@ class Builder extends BaseBuilder
if
(
$expression
instanceof
Closure
)
{
if
(
$expression
instanceof
Closure
)
{
return
call_user_func
(
$expression
,
$this
->
collection
);
return
call_user_func
(
$expression
,
$this
->
collection
);
}
// Create an expression for the given value
}
// Create an expression for the given value
elseif
(
!
is_null
(
$expression
))
{
elseif
(
!
is_null
(
$expression
))
{
return
new
Expression
(
$expression
);
return
new
Expression
(
$expression
);
}
}
...
@@ -748,7 +750,7 @@ class Builder extends BaseBuilder
...
@@ -748,7 +750,7 @@ class Builder extends BaseBuilder
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
{
if
(
!
is_array
(
$columns
))
{
$columns
=
[
$columns
];
$columns
=
[
$columns
];
}
}
...
@@ -781,13 +783,13 @@ class Builder extends BaseBuilder
...
@@ -781,13 +783,13 @@ class Builder extends BaseBuilder
protected
function
performUpdate
(
$query
,
array
$options
=
[])
protected
function
performUpdate
(
$query
,
array
$options
=
[])
{
{
// Update multiple items by default.
// Update multiple items by default.
if
(
!
array_key_exists
(
'multiple'
,
$options
))
{
if
(
!
array_key_exists
(
'multiple'
,
$options
))
{
$options
[
'multiple'
]
=
true
;
$options
[
'multiple'
]
=
true
;
}
}
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
UpdateMany
(
$wheres
,
$query
,
$options
);
$result
=
$this
->
collection
->
UpdateMany
(
$wheres
,
$query
,
$options
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
return
$result
->
getModifiedCount
()
?
$result
->
getModifiedCount
()
:
$result
->
getUpsertedCount
();
return
$result
->
getModifiedCount
()
?
$result
->
getModifiedCount
()
:
$result
->
getUpsertedCount
();
}
}
...
@@ -936,18 +938,18 @@ class Builder extends BaseBuilder
...
@@ -936,18 +938,18 @@ class Builder extends BaseBuilder
$regex
=
preg_replace
(
'#(^|[^\\\])%#'
,
'$1.*'
,
preg_quote
(
$value
));
$regex
=
preg_replace
(
'#(^|[^\\\])%#'
,
'$1.*'
,
preg_quote
(
$value
));
// Convert like to regular expression.
// Convert like to regular expression.
if
(
!
starts_with
(
$value
,
'%'
))
{
if
(
!
starts_with
(
$value
,
'%'
))
{
$regex
=
'^'
.
$regex
;
$regex
=
'^'
.
$regex
;
}
}
if
(
!
ends_with
(
$value
,
'%'
))
{
if
(
!
ends_with
(
$value
,
'%'
))
{
$regex
=
$regex
.
'$'
;
$regex
=
$regex
.
'$'
;
}
}
$value
=
new
Regex
(
$regex
,
'i'
);
$value
=
new
Regex
(
$regex
,
'i'
);
}
// Manipulate regexp operations.
}
// Manipulate regexp operations.
elseif
(
in_array
(
$operator
,
[
'regexp'
,
'not regexp'
,
'regex'
,
'not regex'
]))
{
elseif
(
in_array
(
$operator
,
[
'regexp'
,
'not regexp'
,
'regex'
,
'not regex'
]))
{
// Automatically convert regular expression strings to Regex objects.
// Automatically convert regular expression strings to Regex objects.
if
(
!
$value
instanceof
Regex
)
{
if
(
!
$value
instanceof
Regex
)
{
$e
=
explode
(
'/'
,
$value
);
$e
=
explode
(
'/'
,
$value
);
$flag
=
end
(
$e
);
$flag
=
end
(
$e
);
$regstr
=
substr
(
$value
,
1
,
-
(
strlen
(
$flag
)
+
1
));
$regstr
=
substr
(
$value
,
1
,
-
(
strlen
(
$flag
)
+
1
));
...
@@ -961,12 +963,12 @@ class Builder extends BaseBuilder
...
@@ -961,12 +963,12 @@ class Builder extends BaseBuilder
}
}
}
}
if
(
!
isset
(
$operator
)
or
$operator
==
'='
)
{
if
(
!
isset
(
$operator
)
or
$operator
==
'='
)
{
$query
=
[
$column
=>
$value
];
$query
=
[
$column
=>
$value
];
}
elseif
(
array_key_exists
(
$operator
,
$this
->
conversion
))
{
}
elseif
(
array_key_exists
(
$operator
,
$this
->
conversion
))
{
$query
=
[
$column
=>
[
$this
->
conversion
[
$operator
]
=>
$value
]];
$query
=
[
$column
=>
[
$this
->
conversion
[
$operator
]
=>
$value
]];
}
else
{
}
else
{
$query
=
[
$column
=>
[
'$'
.
$operator
=>
$value
]];
$query
=
[
$column
=>
[
'$'
.
$operator
=>
$value
]];
}
}
return
$query
;
return
$query
;
...
...
src/Jenssegers/Mongodb/Query/Grammar.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Query
;
<?php
namespace
Jenssegers\Mongodb\Query
;
use
Illuminate\Database\Query\Grammars\Grammar
as
BaseGrammar
;
use
Illuminate\Database\Query\Grammars\Grammar
as
BaseGrammar
;
...
...
src/Jenssegers/Mongodb/Query/Processor.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Query
;
<?php
namespace
Jenssegers\Mongodb\Query
;
use
Illuminate\Database\Query\Processors\Processor
as
BaseProcessor
;
use
Illuminate\Database\Query\Processors\Processor
as
BaseProcessor
;
...
...
src/Jenssegers/Mongodb/Queue/Failed/MongoFailedJobProvider.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Queue\Failed
;
<?php
namespace
Jenssegers\Mongodb\Queue\Failed
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Queue\Failed\DatabaseFailedJobProvider
;
use
Illuminate\Queue\Failed\DatabaseFailedJobProvider
;
...
@@ -31,7 +33,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
...
@@ -31,7 +33,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
$all
=
$this
->
getTable
()
->
orderBy
(
'_id'
,
'desc'
)
->
get
()
->
all
();
$all
=
$this
->
getTable
()
->
orderBy
(
'_id'
,
'desc'
)
->
get
()
->
all
();
$all
=
array_map
(
function
(
$job
)
{
$all
=
array_map
(
function
(
$job
)
{
$job
[
'id'
]
=
(
string
)
$job
[
'_id'
];
$job
[
'id'
]
=
(
string
)
$job
[
'_id'
];
return
$job
;
return
$job
;
},
$all
);
},
$all
);
...
@@ -48,7 +50,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
...
@@ -48,7 +50,7 @@ class MongoFailedJobProvider extends DatabaseFailedJobProvider
{
{
$job
=
$this
->
getTable
()
->
find
(
$id
);
$job
=
$this
->
getTable
()
->
find
(
$id
);
$job
[
'id'
]
=
(
string
)
$job
[
'_id'
];
$job
[
'id'
]
=
(
string
)
$job
[
'_id'
];
return
$job
;
return
$job
;
}
}
...
...
src/Jenssegers/Mongodb/Queue/MongoConnector.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Queue
;
<?php
namespace
Jenssegers\Mongodb\Queue
;
use
Illuminate\Database\ConnectionResolverInterface
;
use
Illuminate\Database\ConnectionResolverInterface
;
use
Illuminate\Queue\Connectors\ConnectorInterface
;
use
Illuminate\Queue\Connectors\ConnectorInterface
;
...
@@ -17,7 +19,6 @@ class MongoConnector implements ConnectorInterface
...
@@ -17,7 +19,6 @@ class MongoConnector implements ConnectorInterface
* Create a new connector instance.
* Create a new connector instance.
*
*
* @param \Illuminate\Database\ConnectionResolverInterface $connections
* @param \Illuminate\Database\ConnectionResolverInterface $connections
* @return void
*/
*/
public
function
__construct
(
ConnectionResolverInterface
$connections
)
public
function
__construct
(
ConnectionResolverInterface
$connections
)
{
{
...
...
src/Jenssegers/Mongodb/Queue/MongoJob.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Queue
;
<?php
namespace
Jenssegers\Mongodb\Queue
;
use
Illuminate\Queue\Jobs\DatabaseJob
;
use
Illuminate\Queue\Jobs\DatabaseJob
;
...
...
src/Jenssegers/Mongodb/Queue/MongoQueue.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Queue
;
<?php
namespace
Jenssegers\Mongodb\Queue
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Queue\DatabaseQueue
;
use
Illuminate\Queue\DatabaseQueue
;
...
@@ -37,7 +39,7 @@ class MongoQueue extends DatabaseQueue
...
@@ -37,7 +39,7 @@ class MongoQueue extends DatabaseQueue
{
{
$queue
=
$this
->
getQueue
(
$queue
);
$queue
=
$this
->
getQueue
(
$queue
);
if
(
!
is_null
(
$this
->
retryAfter
))
{
if
(
!
is_null
(
$this
->
retryAfter
))
{
$this
->
releaseJobsThatHaveBeenReservedTooLong
(
$queue
);
$this
->
releaseJobsThatHaveBeenReservedTooLong
(
$queue
);
}
}
...
...
src/Jenssegers/Mongodb/Relations/BelongsTo.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
...
...
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
...
@@ -144,8 +146,8 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -144,8 +146,8 @@ class BelongsToMany extends EloquentBelongsToMany
if
(
$detaching
and
count
(
$detach
)
>
0
)
{
if
(
$detaching
and
count
(
$detach
)
>
0
)
{
$this
->
detach
(
$detach
);
$this
->
detach
(
$detach
);
$changes
[
'detached'
]
=
(
array
)
array_map
(
function
(
$v
)
{
$changes
[
'detached'
]
=
(
array
)
array_map
(
function
(
$v
)
{
return
is_numeric
(
$v
)
?
(
int
)
$v
:
(
string
)
$v
;
return
is_numeric
(
$v
)
?
(
int
)
$v
:
(
string
)
$v
;
},
$detach
);
},
$detach
);
}
}
...
@@ -190,14 +192,14 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -190,14 +192,14 @@ class BelongsToMany extends EloquentBelongsToMany
$query
=
$this
->
newRelatedQuery
();
$query
=
$this
->
newRelatedQuery
();
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
(
array
)
$id
);
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
(
array
)
$id
);
// Attach the new parent id to the related model.
// Attach the new parent id to the related model.
$query
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
$query
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
}
}
// Attach the new ids to the parent model.
// Attach the new ids to the parent model.
$this
->
parent
->
push
(
$this
->
getRelatedKey
(),
(
array
)
$id
,
true
);
$this
->
parent
->
push
(
$this
->
getRelatedKey
(),
(
array
)
$id
,
true
);
if
(
$touch
)
{
if
(
$touch
)
{
$this
->
touchIfTouching
();
$this
->
touchIfTouching
();
...
@@ -210,7 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -210,7 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany
public
function
detach
(
$ids
=
[],
$touch
=
true
)
public
function
detach
(
$ids
=
[],
$touch
=
true
)
{
{
if
(
$ids
instanceof
Model
)
{
if
(
$ids
instanceof
Model
)
{
$ids
=
(
array
)
$ids
->
getKey
();
$ids
=
(
array
)
$ids
->
getKey
();
}
}
$query
=
$this
->
newRelatedQuery
();
$query
=
$this
->
newRelatedQuery
();
...
@@ -218,7 +220,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -218,7 +220,7 @@ class BelongsToMany extends EloquentBelongsToMany
// If associated IDs were passed to the method we will only delete those
// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
// We'll return the numbers of affected rows when we do the deletes.
$ids
=
(
array
)
$ids
;
$ids
=
(
array
)
$ids
;
// Detach all ids from the parent model.
// Detach all ids from the parent model.
$this
->
parent
->
pull
(
$this
->
getRelatedKey
(),
$ids
);
$this
->
parent
->
pull
(
$this
->
getRelatedKey
(),
$ids
);
...
@@ -307,7 +309,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -307,7 +309,7 @@ class BelongsToMany extends EloquentBelongsToMany
{
{
$results
=
[];
$results
=
[];
foreach
(
$records
as
$id
=>
$attributes
)
{
foreach
(
$records
as
$id
=>
$attributes
)
{
if
(
!
is_array
(
$attributes
))
{
if
(
!
is_array
(
$attributes
))
{
list
(
$id
,
$attributes
)
=
[
$attributes
,
[]];
list
(
$id
,
$attributes
)
=
[
$attributes
,
[]];
}
}
$results
[
$id
]
=
$attributes
;
$results
[
$id
]
=
$attributes
;
...
...
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
...
@@ -37,7 +39,7 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -37,7 +39,7 @@ class EmbedsMany extends EmbedsOneOrMany
public
function
performInsert
(
Model
$model
)
public
function
performInsert
(
Model
$model
)
{
{
// Generate a new key if needed.
// Generate a new key if needed.
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
...
@@ -77,10 +79,10 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -77,10 +79,10 @@ class EmbedsMany extends EmbedsOneOrMany
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
// Use array dot notation for better update behavior.
// Use array dot notation for better update behavior.
$values
=
array_dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.$.'
);
$values
=
array_dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.$.'
);
// Update document in database.
// Update document in database.
$result
=
$this
->
getBaseQuery
()
->
where
(
$this
->
localKey
.
'.'
.
$model
->
getKeyName
(),
$foreignKey
)
$result
=
$this
->
getBaseQuery
()
->
where
(
$this
->
localKey
.
'.'
.
$model
->
getKeyName
(),
$foreignKey
)
->
update
(
$values
);
->
update
(
$values
);
// Attach the model to its parent.
// Attach the model to its parent.
...
@@ -126,7 +128,7 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -126,7 +128,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/
*/
public
function
associate
(
Model
$model
)
public
function
associate
(
Model
$model
)
{
{
if
(
!
$this
->
contains
(
$model
))
{
if
(
!
$this
->
contains
(
$model
))
{
return
$this
->
associateNew
(
$model
);
return
$this
->
associateNew
(
$model
);
}
else
{
}
else
{
return
$this
->
associateExisting
(
$model
);
return
$this
->
associateExisting
(
$model
);
...
@@ -235,7 +237,7 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -235,7 +237,7 @@ class EmbedsMany extends EmbedsOneOrMany
protected
function
associateNew
(
$model
)
protected
function
associateNew
(
$model
)
{
{
// Create a new key if needed.
// Create a new key if needed.
if
(
!
$model
->
getAttribute
(
'_id'
))
{
if
(
!
$model
->
getAttribute
(
'_id'
))
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
...
@@ -309,7 +311,7 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -309,7 +311,7 @@ class EmbedsMany extends EmbedsOneOrMany
*/
*/
protected
function
setEmbedded
(
$models
)
protected
function
setEmbedded
(
$models
)
{
{
if
(
!
is_array
(
$models
))
{
if
(
!
is_array
(
$models
))
{
$models
=
[
$models
];
$models
=
[
$models
];
}
}
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
...
@@ -34,7 +36,7 @@ class EmbedsOne extends EmbedsOneOrMany
...
@@ -34,7 +36,7 @@ class EmbedsOne extends EmbedsOneOrMany
public
function
performInsert
(
Model
$model
)
public
function
performInsert
(
Model
$model
)
{
{
// Generate a new key if needed.
// Generate a new key if needed.
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
...
@@ -69,7 +71,7 @@ class EmbedsOne extends EmbedsOneOrMany
...
@@ -69,7 +71,7 @@ class EmbedsOne extends EmbedsOneOrMany
}
}
// Use array dot notation for better update behavior.
// Use array dot notation for better update behavior.
$values
=
array_dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.'
);
$values
=
array_dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.'
);
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
...
@@ -186,7 +188,7 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -186,7 +188,7 @@ abstract class EmbedsOneOrMany extends Relation
$ids
=
$ids
->
all
();
$ids
=
$ids
->
all
();
}
}
if
(
!
is_array
(
$ids
))
{
if
(
!
is_array
(
$ids
))
{
$ids
=
[
$ids
];
$ids
=
[
$ids
];
}
}
...
@@ -208,7 +210,7 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -208,7 +210,7 @@ abstract class EmbedsOneOrMany extends Relation
$attributes
=
$this
->
parent
->
getAttributes
();
$attributes
=
$this
->
parent
->
getAttributes
();
// Get embedded models form parent attributes.
// Get embedded models form parent attributes.
$embedded
=
isset
(
$attributes
[
$this
->
localKey
])
?
(
array
)
$attributes
[
$this
->
localKey
]
:
null
;
$embedded
=
isset
(
$attributes
[
$this
->
localKey
])
?
(
array
)
$attributes
[
$this
->
localKey
]
:
null
;
return
$embedded
;
return
$embedded
;
}
}
...
@@ -278,7 +280,7 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -278,7 +280,7 @@ abstract class EmbedsOneOrMany extends Relation
return
;
return
;
}
}
$model
=
$this
->
related
->
newFromBuilder
((
array
)
$attributes
);
$model
=
$this
->
related
->
newFromBuilder
((
array
)
$attributes
);
$model
->
setParentRelation
(
$this
);
$model
->
setParentRelation
(
$this
);
...
@@ -339,7 +341,7 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -339,7 +341,7 @@ abstract class EmbedsOneOrMany extends Relation
protected
function
getPathHierarchy
(
$glue
=
'.'
)
protected
function
getPathHierarchy
(
$glue
=
'.'
)
{
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
return
$parentRelation
->
getPathHierarchy
(
$glue
)
.
$glue
.
$this
->
localKey
;
return
$parentRelation
->
getPathHierarchy
(
$glue
)
.
$glue
.
$this
->
localKey
;
}
}
return
$this
->
localKey
;
return
$this
->
localKey
;
...
@@ -351,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -351,7 +353,7 @@ abstract class EmbedsOneOrMany extends Relation
public
function
getQualifiedParentKeyName
()
public
function
getQualifiedParentKeyName
()
{
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
return
$parentRelation
->
getPathHierarchy
()
.
'.'
.
$this
->
parent
->
getKeyName
();
return
$parentRelation
->
getPathHierarchy
()
.
'.'
.
$this
->
parent
->
getKeyName
();
}
}
return
$this
->
parent
->
getKeyName
();
return
$this
->
parent
->
getKeyName
();
...
...
src/Jenssegers/Mongodb/Relations/HasMany.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasMany
as
EloquentHasMany
;
use
Illuminate\Database\Eloquent\Relations\HasMany
as
EloquentHasMany
;
...
...
src/Jenssegers/Mongodb/Relations/HasOne.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasOne
as
EloquentHasOne
;
use
Illuminate\Database\Eloquent\Relations\HasOne
as
EloquentHasOne
;
...
...
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Relations\MorphTo
as
EloquentMorphTo
;
use
Illuminate\Database\Eloquent\Relations\MorphTo
as
EloquentMorphTo
;
...
...
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Schema
;
<?php
namespace
Jenssegers\Mongodb\Schema
;
use
Illuminate\Database\Connection
;
use
Illuminate\Database\Connection
;
...
@@ -84,7 +86,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
...
@@ -84,7 +86,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
$transform
=
[];
$transform
=
[];
foreach
(
$columns
as
$column
)
{
foreach
(
$columns
as
$column
)
{
$transform
[
$column
]
=
$column
.
'_1'
;
$transform
[
$column
]
=
$column
.
'_1'
;
}
}
$columns
=
$transform
;
$columns
=
$transform
;
...
...
src/Jenssegers/Mongodb/Schema/Builder.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Schema
;
<?php
namespace
Jenssegers\Mongodb\Schema
;
use
Closure
;
use
Closure
;
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Connection
;
...
...
src/Jenssegers/Mongodb/Schema/Grammar.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Schema
;
<?php
namespace
Jenssegers\Mongodb\Schema
;
use
Illuminate\Database\Schema\Grammars\Grammar
as
BaseGrammar
;
use
Illuminate\Database\Schema\Grammars\Grammar
as
BaseGrammar
;
...
...
src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Validation
;
<?php
namespace
Jenssegers\Mongodb\Validation
;
class
DatabasePresenceVerifier
extends
\Illuminate\Validation\DatabasePresenceVerifier
class
DatabasePresenceVerifier
extends
\Illuminate\Validation\DatabasePresenceVerifier
{
{
...
@@ -17,7 +19,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
...
@@ -17,7 +19,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
{
{
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
"/
$value
/i"
);
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
"/
$value
/i"
);
if
(
!
is_null
(
$excludeId
)
&&
$excludeId
!=
'NULL'
)
{
if
(
!
is_null
(
$excludeId
)
&&
$excludeId
!=
'NULL'
)
{
$query
->
where
(
$idColumn
?:
'id'
,
'<>'
,
$excludeId
);
$query
->
where
(
$idColumn
?:
'id'
,
'<>'
,
$excludeId
);
}
}
...
@@ -40,7 +42,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
...
@@ -40,7 +42,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe
public
function
getMultiCount
(
$collection
,
$column
,
array
$values
,
array
$extra
=
[])
public
function
getMultiCount
(
$collection
,
$column
,
array
$values
,
array
$extra
=
[])
{
{
// Generates a regex like '/(a|b|c)/i' which can query multiple values
// Generates a regex like '/(a|b|c)/i' which can query multiple values
$regex
=
'/('
.
implode
(
'|'
,
$values
)
.
')/i'
;
$regex
=
'/('
.
implode
(
'|'
,
$values
)
.
')/i'
;
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
$regex
);
$query
=
$this
->
table
(
$collection
)
->
where
(
$column
,
'regex'
,
$regex
);
...
...
src/Jenssegers/Mongodb/Validation/ValidationServiceProvider.php
View file @
e4816615
<?php
namespace
Jenssegers\Mongodb\Validation
;
<?php
namespace
Jenssegers\Mongodb\Validation
;
use
Illuminate\Validation\ValidationServiceProvider
as
BaseProvider
;
use
Illuminate\Validation\ValidationServiceProvider
as
BaseProvider
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment