Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
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
mongo-php-library
Commits
5107f939
Unverified
Commit
5107f939
authored
Jul 23, 2019
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-438: Unify handling for write stages in aggregation pipelines
parent
382cb96d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
38 additions
and
35 deletions
+38
-35
apiargs-MongoDBCollection-method-aggregate-option.yaml
...es/apiargs-MongoDBCollection-method-aggregate-option.yaml
+2
-3
apiargs-MongoDBDatabase-method-aggregate-option.yaml
...udes/apiargs-MongoDBDatabase-method-aggregate-option.yaml
+2
-3
apiargs-aggregate-option.yaml
docs/includes/apiargs-aggregate-option.yaml
+2
-1
Collection.php
src/Collection.php
+5
-5
Database.php
src/Database.php
+5
-5
Aggregate.php
src/Operation/Aggregate.php
+8
-8
functions.php
src/functions.php
+3
-3
CrudSpecFunctionalTest.php
tests/Collection/CrudSpecFunctionalTest.php
+1
-1
Context.php
tests/SpecTests/Context.php
+9
-0
CrudSpecTest.php
tests/SpecTests/CrudSpecTest.php
+0
-5
Operation.php
tests/SpecTests/Operation.php
+1
-1
No files found.
docs/includes/apiargs-MongoDBCollection-method-aggregate-option.yaml
View file @
5107f939
...
@@ -39,8 +39,6 @@ source:
...
@@ -39,8 +39,6 @@ source:
source
:
source
:
file
:
apiargs-MongoDBCollection-common-option.yaml
file
:
apiargs-MongoDBCollection-common-option.yaml
ref
:
readPreference
ref
:
readPreference
post
:
|
This option will be ignored when using the :ref:`$out <agg-out>` stage.
---
---
source
:
source
:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
...
@@ -72,7 +70,8 @@ source:
...
@@ -72,7 +70,8 @@ source:
file
:
apiargs-MongoDBCollection-common-option.yaml
file
:
apiargs-MongoDBCollection-common-option.yaml
ref
:
writeConcern
ref
:
writeConcern
post
:
|
post
:
|
This only applies when the :ref:`$out <agg-out>` stage is specified.
This only applies when a :ref:`$out <agg-out>` or :ref:`$merge <agg-merge>`
stage is specified.
This is not supported for server versions prior to 3.4 and will result in an
This is not supported for server versions prior to 3.4 and will result in an
exception at execution time if used.
exception at execution time if used.
...
...
docs/includes/apiargs-MongoDBDatabase-method-aggregate-option.yaml
View file @
5107f939
...
@@ -33,8 +33,6 @@ source:
...
@@ -33,8 +33,6 @@ source:
source
:
source
:
file
:
apiargs-MongoDBDatabase-common-option.yaml
file
:
apiargs-MongoDBDatabase-common-option.yaml
ref
:
readPreference
ref
:
readPreference
post
:
|
This option will be ignored when using the :ref:`$out <agg-out>` stage.
---
---
source
:
source
:
file
:
apiargs-common-option.yaml
file
:
apiargs-common-option.yaml
...
@@ -48,7 +46,8 @@ source:
...
@@ -48,7 +46,8 @@ source:
file
:
apiargs-MongoDBDatabase-common-option.yaml
file
:
apiargs-MongoDBDatabase-common-option.yaml
ref
:
writeConcern
ref
:
writeConcern
post
:
|
post
:
|
This only applies when the :ref:`$out <agg-out>` stage is specified.
This only applies when a :ref:`$out <agg-out>` or :ref:`$merge <agg-merge>`
stage is specified.
This is not supported for server versions prior to 3.4 and will result in an
This is not supported for server versions prior to 3.4 and will result in an
exception at execution time if used.
exception at execution time if used.
...
...
docs/includes/apiargs-aggregate-option.yaml
View file @
5107f939
...
@@ -24,7 +24,8 @@ source:
...
@@ -24,7 +24,8 @@ source:
file
:
apiargs-MongoDBCollection-common-option.yaml
file
:
apiargs-MongoDBCollection-common-option.yaml
ref
:
bypassDocumentValidation
ref
:
bypassDocumentValidation
post
:
|
post
:
|
This only applies when using the :ref:`$out <agg-out>` stage.
This only applies when using the :ref:`$out <agg-out>` and
:ref:`$out <agg-merge>` stages.
Document validation requires MongoDB 3.2 or later: if you are using an earlier
Document validation requires MongoDB 3.2 or later: if you are using an earlier
version of MongoDB, this option will be ignored.
version of MongoDB, this option will be ignored.
...
...
src/Collection.php
View file @
5107f939
...
@@ -69,7 +69,7 @@ class Collection
...
@@ -69,7 +69,7 @@ class Collection
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
static
$wireVersionForFindAndModifyWriteConcern
=
4
;
private
static
$wireVersionForReadConcern
=
4
;
private
static
$wireVersionForReadConcern
=
4
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
static
$wireVersionForReadConcernWith
Out
Stage
=
8
;
private
static
$wireVersionForReadConcernWith
Write
Stage
=
8
;
private
$collectionName
;
private
$collectionName
;
private
$databaseName
;
private
$databaseName
;
...
@@ -190,13 +190,13 @@ class Collection
...
@@ -190,13 +190,13 @@ class Collection
*/
*/
public
function
aggregate
(
array
$pipeline
,
array
$options
=
[])
public
function
aggregate
(
array
$pipeline
,
array
$options
=
[])
{
{
$has
OutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$pipeline
);
$has
WriteStage
=
\MongoDB\is_last_pipeline_operator_write
(
$pipeline
);
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
if
(
$has
Out
Stage
)
{
if
(
$has
Write
Stage
)
{
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
}
}
...
@@ -210,7 +210,7 @@ class Collection
...
@@ -210,7 +210,7 @@ class Collection
if
(
!
isset
(
$options
[
'readConcern'
])
&&
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
)
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
)
&&
!
\MongoDB\is_in_transaction
(
$options
)
&&
!
\MongoDB\is_in_transaction
(
$options
)
&&
(
!
$has
OutStage
||
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcernWithOut
Stage
))
(
!
$has
WriteStage
||
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcernWithWrite
Stage
))
)
{
)
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
}
...
@@ -219,7 +219,7 @@ class Collection
...
@@ -219,7 +219,7 @@ class Collection
$options
[
'typeMap'
]
=
$this
->
typeMap
;
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
}
if
(
$has
Out
Stage
&&
if
(
$has
Write
Stage
&&
!
isset
(
$options
[
'writeConcern'
])
&&
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
)
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
)
&&
!
\MongoDB\is_in_transaction
(
$options
))
{
!
\MongoDB\is_in_transaction
(
$options
))
{
...
...
src/Database.php
View file @
5107f939
...
@@ -48,7 +48,7 @@ class Database
...
@@ -48,7 +48,7 @@ class Database
];
];
private
static
$wireVersionForReadConcern
=
4
;
private
static
$wireVersionForReadConcern
=
4
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
static
$wireVersionForWritableCommandWriteConcern
=
5
;
private
static
$wireVersionForReadConcernWith
Out
Stage
=
8
;
private
static
$wireVersionForReadConcernWith
Write
Stage
=
8
;
private
$databaseName
;
private
$databaseName
;
private
$manager
;
private
$manager
;
...
@@ -175,13 +175,13 @@ class Database
...
@@ -175,13 +175,13 @@ class Database
*/
*/
public
function
aggregate
(
array
$pipeline
,
array
$options
=
[])
public
function
aggregate
(
array
$pipeline
,
array
$options
=
[])
{
{
$has
OutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$pipeline
);
$has
WriteStage
=
\MongoDB\is_last_pipeline_operator_write
(
$pipeline
);
if
(
!
isset
(
$options
[
'readPreference'
]))
{
if
(
!
isset
(
$options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
readPreference
;
$options
[
'readPreference'
]
=
$this
->
readPreference
;
}
}
if
(
$has
Out
Stage
)
{
if
(
$has
Write
Stage
)
{
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$options
[
'readPreference'
]
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
}
}
...
@@ -195,7 +195,7 @@ class Database
...
@@ -195,7 +195,7 @@ class Database
if
(
!
isset
(
$options
[
'readConcern'
])
&&
if
(
!
isset
(
$options
[
'readConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
)
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcern
)
&&
!
\MongoDB\is_in_transaction
(
$options
)
&&
!
\MongoDB\is_in_transaction
(
$options
)
&&
(
!
$has
OutStage
||
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcernWithOut
Stage
))
(
!
$has
WriteStage
||
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForReadConcernWithWrite
Stage
))
)
{
)
{
$options
[
'readConcern'
]
=
$this
->
readConcern
;
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
}
...
@@ -204,7 +204,7 @@ class Database
...
@@ -204,7 +204,7 @@ class Database
$options
[
'typeMap'
]
=
$this
->
typeMap
;
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
}
if
(
$has
Out
Stage
&&
if
(
$has
Write
Stage
&&
!
isset
(
$options
[
'writeConcern'
])
&&
!
isset
(
$options
[
'writeConcern'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
)
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForWritableCommandWriteConcern
)
&&
!
\MongoDB\is_in_transaction
(
$options
))
{
!
\MongoDB\is_in_transaction
(
$options
))
{
...
...
src/Operation/Aggregate.php
View file @
5107f939
...
@@ -264,12 +264,12 @@ class Aggregate implements Executable
...
@@ -264,12 +264,12 @@ class Aggregate implements Executable
$hasExplain
=
!
empty
(
$this
->
options
[
'explain'
]);
$hasExplain
=
!
empty
(
$this
->
options
[
'explain'
]);
$has
OutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$this
->
pipeline
);
$has
WriteStage
=
\MongoDB\is_last_pipeline_operator_write
(
$this
->
pipeline
);
$command
=
$this
->
createCommand
(
$server
,
$has
Out
Stage
);
$command
=
$this
->
createCommand
(
$server
,
$has
Write
Stage
);
$options
=
$this
->
createOptions
(
$has
Out
Stage
,
$hasExplain
);
$options
=
$this
->
createOptions
(
$has
Write
Stage
,
$hasExplain
);
$cursor
=
(
$has
Out
Stage
&&
!
$hasExplain
)
$cursor
=
(
$has
Write
Stage
&&
!
$hasExplain
)
?
$server
->
executeReadWriteCommand
(
$this
->
databaseName
,
$command
,
$options
)
?
$server
->
executeReadWriteCommand
(
$this
->
databaseName
,
$command
,
$options
)
:
$server
->
executeReadCommand
(
$this
->
databaseName
,
$command
,
$options
);
:
$server
->
executeReadCommand
(
$this
->
databaseName
,
$command
,
$options
);
...
@@ -353,11 +353,11 @@ class Aggregate implements Executable
...
@@ -353,11 +353,11 @@ class Aggregate implements Executable
*
*
* @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php
* @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php
* @see http://php.net/manual/en/mongodb-driver-server.executereadwritecommand.php
* @see http://php.net/manual/en/mongodb-driver-server.executereadwritecommand.php
* @param boolean $has
Out
Stage
* @param boolean $has
Write
Stage
* @param boolean $hasExplain
* @param boolean $hasExplain
* @return array
* @return array
*/
*/
private
function
createOptions
(
$has
Out
Stage
,
$hasExplain
)
private
function
createOptions
(
$has
Write
Stage
,
$hasExplain
)
{
{
$options
=
[];
$options
=
[];
...
@@ -365,7 +365,7 @@ class Aggregate implements Executable
...
@@ -365,7 +365,7 @@ class Aggregate implements Executable
$options
[
'readConcern'
]
=
$this
->
options
[
'readConcern'
];
$options
[
'readConcern'
]
=
$this
->
options
[
'readConcern'
];
}
}
if
(
!
$hasOut
Stage
&&
isset
(
$this
->
options
[
'readPreference'
]))
{
if
(
!
$hasWrite
Stage
&&
isset
(
$this
->
options
[
'readPreference'
]))
{
$options
[
'readPreference'
]
=
$this
->
options
[
'readPreference'
];
$options
[
'readPreference'
]
=
$this
->
options
[
'readPreference'
];
}
}
...
@@ -373,7 +373,7 @@ class Aggregate implements Executable
...
@@ -373,7 +373,7 @@ class Aggregate implements Executable
$options
[
'session'
]
=
$this
->
options
[
'session'
];
$options
[
'session'
]
=
$this
->
options
[
'session'
];
}
}
if
(
$has
Out
Stage
&&
!
$hasExplain
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
if
(
$has
Write
Stage
&&
!
$hasExplain
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
$options
[
'writeConcern'
]
=
$this
->
options
[
'writeConcern'
];
$options
[
'writeConcern'
]
=
$this
->
options
[
'writeConcern'
];
}
}
...
...
src/functions.php
View file @
5107f939
...
@@ -127,7 +127,7 @@ function is_in_transaction(array $options)
...
@@ -127,7 +127,7 @@ function is_in_transaction(array $options)
}
}
/**
/**
* Return whether the aggregation pipeline ends with an $out operator.
* Return whether the aggregation pipeline ends with an $out o
r $merge o
perator.
*
*
* This is used for determining whether the aggregation pipeline must be
* This is used for determining whether the aggregation pipeline must be
* executed against a primary server.
* executed against a primary server.
...
@@ -136,7 +136,7 @@ function is_in_transaction(array $options)
...
@@ -136,7 +136,7 @@ function is_in_transaction(array $options)
* @param array $pipeline List of pipeline operations
* @param array $pipeline List of pipeline operations
* @return boolean
* @return boolean
*/
*/
function
is_last_pipeline_operator_
out
(
array
$pipeline
)
function
is_last_pipeline_operator_
write
(
array
$pipeline
)
{
{
$lastOp
=
end
(
$pipeline
);
$lastOp
=
end
(
$pipeline
);
...
@@ -146,7 +146,7 @@ function is_last_pipeline_operator_out(array $pipeline)
...
@@ -146,7 +146,7 @@ function is_last_pipeline_operator_out(array $pipeline)
$lastOp
=
(
array
)
$lastOp
;
$lastOp
=
(
array
)
$lastOp
;
return
key
(
$lastOp
)
===
'$out'
;
return
in_array
(
key
(
$lastOp
),
[
'$out'
,
'$merge'
],
true
)
;
}
}
/**
/**
...
...
tests/Collection/CrudSpecFunctionalTest.php
View file @
5107f939
...
@@ -292,7 +292,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
...
@@ -292,7 +292,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
* the result here; however, assertEquivalentCollections() will
* the result here; however, assertEquivalentCollections() will
* assert the output collection's contents later.
* assert the output collection's contents later.
*/
*/
if
(
!
\MongoDB\is_last_pipeline_operator_
out
(
$operation
[
'arguments'
][
'pipeline'
]))
{
if
(
!
\MongoDB\is_last_pipeline_operator_
write
(
$operation
[
'arguments'
][
'pipeline'
]))
{
$this
->
assertSameDocuments
(
$expectedResult
,
$actualResult
);
$this
->
assertSameDocuments
(
$expectedResult
,
$actualResult
);
}
}
break
;
break
;
...
...
tests/SpecTests/Context.php
View file @
5107f939
...
@@ -63,6 +63,15 @@ final class Context
...
@@ -63,6 +63,15 @@ final class Context
$o
->
outcomeCollectionName
=
$test
->
outcome
->
collection
->
name
;
$o
->
outcomeCollectionName
=
$test
->
outcome
->
collection
->
name
;
}
}
$o
->
defaultWriteOptions
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
$o
->
outcomeFindOptions
=
[
'readConcern'
=>
new
ReadConcern
(
'local'
),
'readPreference'
=>
new
ReadPreference
(
'primary'
),
];
$o
->
client
=
new
Client
(
FunctionalTestCase
::
getUri
(),
$clientOptions
);
$o
->
client
=
new
Client
(
FunctionalTestCase
::
getUri
(),
$clientOptions
);
return
$o
;
return
$o
;
...
...
tests/SpecTests/CrudSpecTest.php
View file @
5107f939
...
@@ -14,11 +14,6 @@ class CrudSpecTest extends FunctionalTestCase
...
@@ -14,11 +14,6 @@ class CrudSpecTest extends FunctionalTestCase
/* These should all pass before the driver can be considered compatible with
/* These should all pass before the driver can be considered compatible with
* MongoDB 4.2. */
* MongoDB 4.2. */
private
static
$incompleteTests
=
[
private
static
$incompleteTests
=
[
'aggregate-merge: Aggregate with $merge'
=>
'PHPLIB-438'
,
'aggregate-merge: Aggregate with $merge and batch size of 0'
=>
'PHPLIB-438'
,
'aggregate-merge: Aggregate with $merge and majority readConcern'
=>
'PHPLIB-438'
,
'aggregate-merge: Aggregate with $merge and local readConcern'
=>
'PHPLIB-438'
,
'aggregate-merge: Aggregate with $merge and available readConcern'
=>
'PHPLIB-438'
,
'bulkWrite-arrayFilters: BulkWrite with arrayFilters'
=>
'Fails due to command assertions'
,
'bulkWrite-arrayFilters: BulkWrite with arrayFilters'
=>
'Fails due to command assertions'
,
'updateWithPipelines: UpdateOne using pipelines'
=>
'PHPLIB-418'
,
'updateWithPipelines: UpdateOne using pipelines'
=>
'PHPLIB-418'
,
'updateWithPipelines: UpdateMany using pipelines'
=>
'PHPLIB-418'
,
'updateWithPipelines: UpdateMany using pipelines'
=>
'PHPLIB-418'
,
...
...
tests/SpecTests/Operation.php
View file @
5107f939
...
@@ -415,7 +415,7 @@ final class Operation
...
@@ -415,7 +415,7 @@ final class Operation
* the CRUD specification and is not implemented in the library
* the CRUD specification and is not implemented in the library
* since we have no concept of lazy cursors. Rely on examining
* since we have no concept of lazy cursors. Rely on examining
* the output collection rather than the operation result. */
* the output collection rather than the operation result. */
if
(
\MongoDB\is_last_pipeline_operator_
out
(
$this
->
arguments
[
'pipeline'
]))
{
if
(
\MongoDB\is_last_pipeline_operator_
write
(
$this
->
arguments
[
'pipeline'
]))
{
return
ResultExpectation
::
ASSERT_NOTHING
;
return
ResultExpectation
::
ASSERT_NOTHING
;
}
}
...
...
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