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
39f59b20
Commit
39f59b20
authored
Nov 13, 2018
by
Derick Rethans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-368: Operations executed within transaction should not inherit read/write concern
parent
6ecf84a8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
515 additions
and
28 deletions
+515
-28
.travis.yml
.travis.yml
+1
-1
Collection.php
src/Collection.php
+49
-27
UnsupportedException.php
src/Exception/UnsupportedException.php
+20
-0
Aggregate.php
src/Operation/Aggregate.php
+11
-0
BulkWrite.php
src/Operation/BulkWrite.php
+5
-0
Count.php
src/Operation/Count.php
+5
-0
CountDocuments.php
src/Operation/CountDocuments.php
+5
-0
CreateIndexes.php
src/Operation/CreateIndexes.php
+5
-0
Delete.php
src/Operation/Delete.php
+5
-0
Distinct.php
src/Operation/Distinct.php
+5
-0
DropCollection.php
src/Operation/DropCollection.php
+5
-0
DropIndexes.php
src/Operation/DropIndexes.php
+5
-0
EstimatedDocumentCount.php
src/Operation/EstimatedDocumentCount.php
+5
-0
Find.php
src/Operation/Find.php
+5
-0
FindAndModify.php
src/Operation/FindAndModify.php
+5
-0
InsertMany.php
src/Operation/InsertMany.php
+6
-0
InsertOne.php
src/Operation/InsertOne.php
+6
-0
MapReduce.php
src/Operation/MapReduce.php
+10
-0
Update.php
src/Operation/Update.php
+5
-0
Watch.php
src/Operation/Watch.php
+5
-0
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+347
-0
No files found.
.travis.yml
View file @
39f59b20
...
@@ -15,7 +15,7 @@ cache:
...
@@ -15,7 +15,7 @@ cache:
env
:
env
:
global
:
global
:
-
DRIVER_VERSION=1.
5.2
-
DRIVER_VERSION=1.
6.0alpha1
-
SERVER_VERSION=4.0.1
-
SERVER_VERSION=4.0.1
-
DEPLOYMENT=STANDALONE
-
DEPLOYMENT=STANDALONE
...
...
src/Collection.php
View file @
39f59b20
This diff is collapsed.
Click to expand it.
src/Exception/UnsupportedException.php
View file @
39f59b20
...
@@ -59,6 +59,16 @@ class UnsupportedException extends RuntimeException
...
@@ -59,6 +59,16 @@ class UnsupportedException extends RuntimeException
return
new
static
(
'Read concern is not supported by the server executing this command'
);
return
new
static
(
'Read concern is not supported by the server executing this command'
);
}
}
/**
* Thrown when a readConcern is used with a read operation in a transaction.
*
* @return self
*/
public
static
function
readConcernNotSupportedInTransaction
()
{
return
new
static
(
'The "readConcern" option cannot be specified within a transaction. Instead, specify it when starting the transaction.'
);
}
/**
/**
* Thrown when a command's writeConcern option is not supported by a server.
* Thrown when a command's writeConcern option is not supported by a server.
*
*
...
@@ -68,4 +78,14 @@ class UnsupportedException extends RuntimeException
...
@@ -68,4 +78,14 @@ class UnsupportedException extends RuntimeException
{
{
return
new
static
(
'Write concern is not supported by the server executing this command'
);
return
new
static
(
'Write concern is not supported by the server executing this command'
);
}
}
/**
* Thrown when a writeConcern is used with a write operation in a transaction.
*
* @return self
*/
public
static
function
writeConcernNotSupportedInTransaction
()
{
return
new
static
(
'The "writeConcern" option cannot be specified within a transaction. Instead, specify it when starting the transaction.'
);
}
}
}
src/Operation/Aggregate.php
View file @
39f59b20
...
@@ -252,6 +252,17 @@ class Aggregate implements Executable
...
@@ -252,6 +252,17 @@ class Aggregate implements Executable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
)
{
if
(
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
if
(
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
}
$hasExplain
=
!
empty
(
$this
->
options
[
'explain'
]);
$hasExplain
=
!
empty
(
$this
->
options
[
'explain'
]);
$hasOutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$this
->
pipeline
);
$hasOutStage
=
\MongoDB\is_last_pipeline_operator_out
(
$this
->
pipeline
);
...
...
src/Operation/BulkWrite.php
View file @
39f59b20
...
@@ -322,6 +322,11 @@ class BulkWrite implements Executable
...
@@ -322,6 +322,11 @@ class BulkWrite implements Executable
throw
UnsupportedException
::
collationNotSupported
();
throw
UnsupportedException
::
collationNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
if
(
if
(
...
...
src/Operation/Count.php
View file @
39f59b20
...
@@ -151,6 +151,11 @@ class Count implements Executable, Explainable
...
@@ -151,6 +151,11 @@ class Count implements Executable, Explainable
throw
UnsupportedException
::
readConcernNotSupported
();
throw
UnsupportedException
::
readConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/CountDocuments.php
View file @
39f59b20
...
@@ -151,6 +151,11 @@ class CountDocuments implements Executable
...
@@ -151,6 +151,11 @@ class CountDocuments implements Executable
throw
UnsupportedException
::
readConcernNotSupported
();
throw
UnsupportedException
::
readConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$allResults
=
$cursor
->
toArray
();
$allResults
=
$cursor
->
toArray
();
...
...
src/Operation/CreateIndexes.php
View file @
39f59b20
...
@@ -139,6 +139,11 @@ class CreateIndexes implements Executable
...
@@ -139,6 +139,11 @@ class CreateIndexes implements Executable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$this
->
executeCommand
(
$server
);
$this
->
executeCommand
(
$server
);
return
array_map
(
function
(
IndexInput
$index
)
{
return
(
string
)
$index
;
},
$this
->
indexes
);
return
array_map
(
function
(
IndexInput
$index
)
{
return
(
string
)
$index
;
},
$this
->
indexes
);
...
...
src/Operation/Delete.php
View file @
39f59b20
...
@@ -117,6 +117,11 @@ class Delete implements Executable, Explainable
...
@@ -117,6 +117,11 @@ class Delete implements Executable, Explainable
throw
UnsupportedException
::
collationNotSupported
();
throw
UnsupportedException
::
collationNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$bulk
=
new
Bulk
();
$bulk
=
new
Bulk
();
$bulk
->
delete
(
$this
->
filter
,
$this
->
createDeleteOptions
());
$bulk
->
delete
(
$this
->
filter
,
$this
->
createDeleteOptions
());
...
...
src/Operation/Distinct.php
View file @
39f59b20
...
@@ -133,6 +133,11 @@ class Distinct implements Executable, Explainable
...
@@ -133,6 +133,11 @@ class Distinct implements Executable, Explainable
throw
UnsupportedException
::
readConcernNotSupported
();
throw
UnsupportedException
::
readConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/DropCollection.php
View file @
39f59b20
...
@@ -102,6 +102,11 @@ class DropCollection implements Executable
...
@@ -102,6 +102,11 @@ class DropCollection implements Executable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$command
=
new
Command
([
'drop'
=>
$this
->
collectionName
]);
$command
=
new
Command
([
'drop'
=>
$this
->
collectionName
]);
try
{
try
{
...
...
src/Operation/DropIndexes.php
View file @
39f59b20
...
@@ -116,6 +116,11 @@ class DropIndexes implements Executable
...
@@ -116,6 +116,11 @@ class DropIndexes implements Executable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$this
->
createOptions
());
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$this
->
createOptions
());
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
...
...
src/Operation/EstimatedDocumentCount.php
View file @
39f59b20
...
@@ -114,6 +114,11 @@ class EstimatedDocumentCount implements Executable, Explainable
...
@@ -114,6 +114,11 @@ class EstimatedDocumentCount implements Executable, Explainable
throw
UnsupportedException
::
readConcernNotSupported
();
throw
UnsupportedException
::
readConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$cursor
=
$server
->
executeReadCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
()),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/Find.php
View file @
39f59b20
...
@@ -296,6 +296,11 @@ class Find implements Executable, Explainable
...
@@ -296,6 +296,11 @@ class Find implements Executable, Explainable
throw
UnsupportedException
::
readConcernNotSupported
();
throw
UnsupportedException
::
readConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeQuery
(
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
new
Query
(
$this
->
filter
,
$this
->
createQueryOptions
()),
$this
->
createExecuteOptions
());
$cursor
=
$server
->
executeQuery
(
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
new
Query
(
$this
->
filter
,
$this
->
createQueryOptions
()),
$this
->
createExecuteOptions
());
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
if
(
isset
(
$this
->
options
[
'typeMap'
]))
{
...
...
src/Operation/FindAndModify.php
View file @
39f59b20
...
@@ -210,6 +210,11 @@ class FindAndModify implements Executable, Explainable
...
@@ -210,6 +210,11 @@ class FindAndModify implements Executable, Explainable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
(
$server
)),
$this
->
createOptions
());
$cursor
=
$server
->
executeWriteCommand
(
$this
->
databaseName
,
new
Command
(
$this
->
createCommandDocument
(
$server
)),
$this
->
createOptions
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
...
...
src/Operation/InsertMany.php
View file @
39f59b20
...
@@ -24,6 +24,7 @@ use MongoDB\Driver\Session;
...
@@ -24,6 +24,7 @@ use MongoDB\Driver\Session;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\UnsupportedException
;
/**
/**
* Operation for inserting multiple documents with the insert command.
* Operation for inserting multiple documents with the insert command.
...
@@ -126,6 +127,11 @@ class InsertMany implements Executable
...
@@ -126,6 +127,11 @@ class InsertMany implements Executable
*/
*/
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
if
(
if
(
...
...
src/Operation/InsertOne.php
View file @
39f59b20
...
@@ -24,6 +24,7 @@ use MongoDB\Driver\Session;
...
@@ -24,6 +24,7 @@ use MongoDB\Driver\Session;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\UnsupportedException
;
/**
/**
* Operation for inserting a single document with the insert command.
* Operation for inserting a single document with the insert command.
...
@@ -104,6 +105,11 @@ class InsertOne implements Executable
...
@@ -104,6 +105,11 @@ class InsertOne implements Executable
{
{
$options
=
[];
$options
=
[];
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
isset
(
$this
->
options
[
'writeConcern'
])
&&
$inTransaction
)
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
if
(
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
...
...
src/Operation/MapReduce.php
View file @
39f59b20
...
@@ -248,6 +248,16 @@ class MapReduce implements Executable
...
@@ -248,6 +248,16 @@ class MapReduce implements Executable
throw
UnsupportedException
::
writeConcernNotSupported
();
throw
UnsupportedException
::
writeConcernNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
)
{
if
(
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
if
(
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
}
$hasOutputCollection
=
!
\MongoDB\is_mapreduce_output_inline
(
$this
->
out
);
$hasOutputCollection
=
!
\MongoDB\is_mapreduce_output_inline
(
$this
->
out
);
$command
=
$this
->
createCommand
(
$server
);
$command
=
$this
->
createCommand
(
$server
);
...
...
src/Operation/Update.php
View file @
39f59b20
...
@@ -167,6 +167,11 @@ class Update implements Executable, Explainable
...
@@ -167,6 +167,11 @@ class Update implements Executable, Explainable
throw
UnsupportedException
::
collationNotSupported
();
throw
UnsupportedException
::
collationNotSupported
();
}
}
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'writeConcern'
]))
{
throw
UnsupportedException
::
writeConcernNotSupportedInTransaction
();
}
$bulkOptions
=
[];
$bulkOptions
=
[];
if
(
if
(
...
...
src/Operation/Watch.php
View file @
39f59b20
...
@@ -213,6 +213,11 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
...
@@ -213,6 +213,11 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
*/
*/
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$inTransaction
=
isset
(
$this
->
options
[
'session'
])
&&
$this
->
options
[
'session'
]
->
isInTransaction
();
if
(
$inTransaction
&&
isset
(
$this
->
options
[
'readConcern'
]))
{
throw
UnsupportedException
::
readConcernNotSupportedInTransaction
();
}
return
new
ChangeStream
(
$this
->
executeAggregate
(
$server
),
$this
->
resumeCallable
);
return
new
ChangeStream
(
$this
->
executeAggregate
(
$server
),
$this
->
resumeCallable
);
}
}
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
39f59b20
This diff is collapsed.
Click to expand it.
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