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
48c8290c
Commit
48c8290c
authored
Dec 16, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-122: Checking "ok" field in command results is redundant
The driver (via libmongoc) already does this.
parent
9d087e5a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
7 additions
and
61 deletions
+7
-61
Aggregate.php
src/Operation/Aggregate.php
+0
-5
Count.php
src/Operation/Count.php
+0
-5
CreateCollection.php
src/Operation/CreateCollection.php
+1
-7
CreateIndexes.php
src/Operation/CreateIndexes.php
+1
-5
Distinct.php
src/Operation/Distinct.php
+0
-5
DropCollection.php
src/Operation/DropCollection.php
+3
-10
DropDatabase.php
src/Operation/DropDatabase.php
+1
-7
DropIndexes.php
src/Operation/DropIndexes.php
+1
-7
FindAndModify.php
src/Operation/FindAndModify.php
+0
-5
ListDatabases.php
src/Operation/ListDatabases.php
+0
-5
No files found.
src/Operation/Aggregate.php
View file @
48c8290c
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
ArrayIterator
;
use
ArrayIterator
;
use
stdClass
;
use
stdClass
;
...
@@ -136,10 +135,6 @@ class Aggregate implements Executable
...
@@ -136,10 +135,6 @@ class Aggregate implements Executable
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
->
result
)
||
!
is_array
(
$result
->
result
))
{
if
(
!
isset
(
$result
->
result
)
||
!
is_array
(
$result
->
result
))
{
throw
new
UnexpectedValueException
(
'aggregate command did not return a "result" array'
);
throw
new
UnexpectedValueException
(
'aggregate command did not return a "result" array'
);
}
}
...
...
src/Operation/Count.php
View file @
48c8290c
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
/**
/**
...
@@ -100,10 +99,6 @@ class Count implements Executable
...
@@ -100,10 +99,6 @@ class Count implements Executable
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$readPreference
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$readPreference
);
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
// Older server versions may return a float
// Older server versions may return a float
if
(
!
isset
(
$result
->
n
)
||
!
(
is_integer
(
$result
->
n
)
||
is_float
(
$result
->
n
)))
{
if
(
!
isset
(
$result
->
n
)
||
!
(
is_integer
(
$result
->
n
)
||
is_float
(
$result
->
n
)))
{
throw
new
UnexpectedValueException
(
'count command did not return a numeric "n" value'
);
throw
new
UnexpectedValueException
(
'count command did not return a numeric "n" value'
);
...
...
src/Operation/CreateCollection.php
View file @
48c8290c
...
@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
...
@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedTypeException
;
use
MongoDB\Exception\UnexpectedTypeException
;
use
MongoDB\Model\IndexInput
;
use
MongoDB\Model\IndexInput
;
...
@@ -102,13 +101,8 @@ class CreateCollection implements Executable
...
@@ -102,13 +101,8 @@ class CreateCollection implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
return
current
(
$cursor
->
toArray
());
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
}
}
/**
/**
...
...
src/Operation/CreateIndexes.php
View file @
48c8290c
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\Server;
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\Server;
use
MongoDB\Driver\BulkWrite
as
Bulk
;
use
MongoDB\Driver\BulkWrite
as
Bulk
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedTypeException
;
use
MongoDB\Exception\UnexpectedTypeException
;
use
MongoDB\Model\IndexInput
;
use
MongoDB\Model\IndexInput
;
...
@@ -92,11 +91,8 @@ class CreateIndexes implements Executable
...
@@ -92,11 +91,8 @@ class CreateIndexes implements Executable
]);
]);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
return
current
(
$cursor
->
toArray
());
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
}
}
/**
/**
...
...
src/Operation/Distinct.php
View file @
48c8290c
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
/**
/**
...
@@ -77,10 +76,6 @@ class Distinct implements Executable
...
@@ -77,10 +76,6 @@ class Distinct implements Executable
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$readPreference
);
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
(),
$readPreference
);
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
->
values
)
||
!
is_array
(
$result
->
values
))
{
if
(
!
isset
(
$result
->
values
)
||
!
is_array
(
$result
->
values
))
{
throw
new
UnexpectedValueException
(
'distinct command did not return a "values" array'
);
throw
new
UnexpectedValueException
(
'distinct command did not return a "values" array'
);
}
}
...
...
src/Operation/DropCollection.php
View file @
48c8290c
...
@@ -4,8 +4,7 @@ namespace MongoDB\Operation;
...
@@ -4,8 +4,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Driver\Exception\RuntimeException
;
use
MongoDB\Exception\RuntimeException
;
/**
/**
* Operation for the drop command.
* Operation for the drop command.
...
@@ -44,7 +43,7 @@ class DropCollection implements Executable
...
@@ -44,7 +43,7 @@ class DropCollection implements Executable
{
{
try
{
try
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
([
'drop'
=>
$this
->
collectionName
]));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
([
'drop'
=>
$this
->
collectionName
]));
}
catch
(
Driver
RuntimeException
$e
)
{
}
catch
(
RuntimeException
$e
)
{
/* The server may return an error if the collection does not exist.
/* The server may return an error if the collection does not exist.
* Check for an error message (unfortunately, there isn't a code)
* Check for an error message (unfortunately, there isn't a code)
* and NOP instead of throwing.
* and NOP instead of throwing.
...
@@ -56,12 +55,6 @@ class DropCollection implements Executable
...
@@ -56,12 +55,6 @@ class DropCollection implements Executable
throw
$e
;
throw
$e
;
}
}
$result
=
current
(
$cursor
->
toArray
());
return
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
}
}
}
}
src/Operation/DropDatabase.php
View file @
48c8290c
...
@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
...
@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\RuntimeException
;
/**
/**
* Operation for the dropDatabase command.
* Operation for the dropDatabase command.
...
@@ -39,12 +38,7 @@ class DropDatabase implements Executable
...
@@ -39,12 +38,7 @@ class DropDatabase implements Executable
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
([
'dropDatabase'
=>
1
]));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
([
'dropDatabase'
=>
1
]));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
return
current
(
$cursor
->
toArray
());
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
}
}
}
}
src/Operation/DropIndexes.php
View file @
48c8290c
...
@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
...
@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\RuntimeException
;
/**
/**
* Operation for the dropIndexes command.
* Operation for the dropIndexes command.
...
@@ -56,12 +55,7 @@ class DropIndexes implements Executable
...
@@ -56,12 +55,7 @@ class DropIndexes implements Executable
];
];
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
$cmd
));
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
return
current
(
$cursor
->
toArray
());
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
return
$result
;
}
}
}
}
src/Operation/FindAndModify.php
View file @
48c8290c
...
@@ -6,7 +6,6 @@ use MongoDB\Driver\Command;
...
@@ -6,7 +6,6 @@ use MongoDB\Driver\Command;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
/**
/**
...
@@ -120,10 +119,6 @@ class FindAndModify implements Executable
...
@@ -120,10 +119,6 @@ class FindAndModify implements Executable
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
$this
->
createCommand
());
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
throw
new
RuntimeException
(
isset
(
$result
->
errmsg
)
?
$result
->
errmsg
:
'Unknown error'
);
}
if
(
!
isset
(
$result
->
value
))
{
if
(
!
isset
(
$result
->
value
))
{
return
null
;
return
null
;
}
}
...
...
src/Operation/ListDatabases.php
View file @
48c8290c
...
@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
...
@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Model\DatabaseInfoIterator
;
use
MongoDB\Model\DatabaseInfoIterator
;
use
MongoDB\Model\DatabaseInfoLegacyIterator
;
use
MongoDB\Model\DatabaseInfoLegacyIterator
;
...
@@ -58,10 +57,6 @@ class ListDatabases implements Executable
...
@@ -58,10 +57,6 @@ class ListDatabases implements Executable
$cursor
->
setTypeMap
([
'root'
=>
'array'
,
'document'
=>
'array'
]);
$cursor
->
setTypeMap
([
'root'
=>
'array'
,
'document'
=>
'array'
]);
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
[
'ok'
]))
{
throw
new
RuntimeException
(
isset
(
$result
[
'errmsg'
])
?
$result
[
'errmsg'
]
:
'Unknown error'
);
}
if
(
!
isset
(
$result
[
'databases'
])
||
!
is_array
(
$result
[
'databases'
]))
{
if
(
!
isset
(
$result
[
'databases'
])
||
!
is_array
(
$result
[
'databases'
]))
{
throw
new
UnexpectedValueException
(
'listDatabases command did not return a "databases" array'
);
throw
new
UnexpectedValueException
(
'listDatabases command did not return a "databases" array'
);
}
}
...
...
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