Skip to content

Commit 4327715

Browse files
committed
Merge pull request #64
2 parents 9d087e5 + 3ba5c43 commit 4327715

11 files changed

+12
-65
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ env:
1212
- MONGO_REPO_TYPE="precise/mongodb-enterprise/"
1313
- SOURCES_LOC="/etc/apt/sources.list.d/mongodb.list"
1414
matrix:
15-
- DRIVER_VERSION=1.0 SERVER_VERSION=2.4
16-
- DRIVER_VERSION=1.0 SERVER_VERSION=2.6
17-
- DRIVER_VERSION=1.0 SERVER_VERSION=3.0
15+
- DRIVER_VERSION=1.0.0 SERVER_VERSION=2.4
16+
- DRIVER_VERSION=1.0.0 SERVER_VERSION=2.6
17+
- DRIVER_VERSION=1.0.0 SERVER_VERSION=3.0
1818

1919
before_install:
2020
- sudo apt-key adv --keyserver ${KEY_SERVER} --recv 7F0CEB10
@@ -32,6 +32,7 @@ before_script:
3232
- if ! nc -z localhost 27017; then sudo service ${SERVER_SERVICE} start; fi
3333
- mongod --version
3434
- pecl install -f mongodb-${DRIVER_VERSION}
35+
- if [ "$(php -v | grep 'PHP 5.4')" ]; then echo 'extension = mongodb.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
3536
- php --ri mongodb
3637
- composer install --dev --no-interaction --prefer-source
3738
- ulimit -c

src/Operation/Aggregate.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use MongoDB\Driver\Server;
88
use MongoDB\Exception\InvalidArgumentException;
99
use MongoDB\Exception\InvalidArgumentTypeException;
10-
use MongoDB\Exception\RuntimeException;
1110
use MongoDB\Exception\UnexpectedValueException;
1211
use ArrayIterator;
1312
use stdClass;
@@ -136,10 +135,6 @@ public function execute(Server $server)
136135

137136
$result = current($cursor->toArray());
138137

139-
if (empty($result->ok)) {
140-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
141-
}
142-
143138
if ( ! isset($result->result) || ! is_array($result->result)) {
144139
throw new UnexpectedValueException('aggregate command did not return a "result" array');
145140
}

src/Operation/Count.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use MongoDB\Driver\Server;
88
use MongoDB\Exception\InvalidArgumentException;
99
use MongoDB\Exception\InvalidArgumentTypeException;
10-
use MongoDB\Exception\RuntimeException;
1110
use MongoDB\Exception\UnexpectedValueException;
1211

1312
/**
@@ -100,10 +99,6 @@ public function execute(Server $server)
10099
$cursor = $server->executeCommand($this->databaseName, $this->createCommand(), $readPreference);
101100
$result = current($cursor->toArray());
102101

103-
if (empty($result->ok)) {
104-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
105-
}
106-
107102
// Older server versions may return a float
108103
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
109104
throw new UnexpectedValueException('count command did not return a numeric "n" value');

src/Operation/CreateCollection.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use MongoDB\Driver\Command;
66
use MongoDB\Driver\Server;
77
use MongoDB\Exception\InvalidArgumentException;
8-
use MongoDB\Exception\RuntimeException;
98
use MongoDB\Exception\UnexpectedTypeException;
109
use MongoDB\Model\IndexInput;
1110

@@ -102,13 +101,8 @@ public function __construct($databaseName, $collectionName, array $options = [])
102101
public function execute(Server $server)
103102
{
104103
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
105-
$result = current($cursor->toArray());
106104

107-
if (empty($result->ok)) {
108-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
109-
}
110-
111-
return $result;
105+
return current($cursor->toArray());
112106
}
113107

114108
/**

src/Operation/CreateIndexes.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use MongoDB\Driver\BulkWrite as Bulk;
88
use MongoDB\Driver\WriteConcern;
99
use MongoDB\Exception\InvalidArgumentException;
10-
use MongoDB\Exception\RuntimeException;
1110
use MongoDB\Exception\UnexpectedTypeException;
1211
use MongoDB\Model\IndexInput;
1312

@@ -92,11 +91,8 @@ private function executeCommand(Server $server)
9291
]);
9392

9493
$cursor = $server->executeCommand($this->databaseName, $command);
95-
$result = current($cursor->toArray());
9694

97-
if (empty($result->ok)) {
98-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
99-
}
95+
return current($cursor->toArray());
10096
}
10197

10298
/**

src/Operation/Distinct.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use MongoDB\Driver\Server;
88
use MongoDB\Exception\InvalidArgumentException;
99
use MongoDB\Exception\InvalidArgumentTypeException;
10-
use MongoDB\Exception\RuntimeException;
1110
use MongoDB\Exception\UnexpectedValueException;
1211

1312
/**
@@ -77,10 +76,6 @@ public function execute(Server $server)
7776
$cursor = $server->executeCommand($this->databaseName, $this->createCommand(), $readPreference);
7877
$result = current($cursor->toArray());
7978

80-
if (empty($result->ok)) {
81-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
82-
}
83-
8479
if ( ! isset($result->values) || ! is_array($result->values)) {
8580
throw new UnexpectedValueException('distinct command did not return a "values" array');
8681
}

src/Operation/DropCollection.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use MongoDB\Driver\Command;
66
use MongoDB\Driver\Server;
7-
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
8-
use MongoDB\Exception\RuntimeException;
7+
use MongoDB\Driver\Exception\RuntimeException;
98

109
/**
1110
* Operation for the drop command.
@@ -44,24 +43,18 @@ public function execute(Server $server)
4443
{
4544
try {
4645
$cursor = $server->executeCommand($this->databaseName, new Command(['drop' => $this->collectionName]));
47-
} catch (DriverRuntimeException $e) {
46+
} catch (RuntimeException $e) {
4847
/* The server may return an error if the collection does not exist.
4948
* Check for an error message (unfortunately, there isn't a code)
5049
* and NOP instead of throwing.
5150
*/
5251
if ($e->getMessage() === self::$errorMessageNamespaceNotFound) {
53-
return (object) ['ok' => 0, 'errmsg' => 'ns not found'];
52+
return (object) ['ok' => 0, 'errmsg' => self::$errorMessageNamespaceNotFound];
5453
}
5554

5655
throw $e;
5756
}
5857

59-
$result = current($cursor->toArray());
60-
61-
if (empty($result->ok)) {
62-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
63-
}
64-
65-
return $result;
58+
return current($cursor->toArray());
6659
}
6760
}

src/Operation/DropDatabase.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use MongoDB\Driver\Command;
66
use MongoDB\Driver\Server;
7-
use MongoDB\Exception\RuntimeException;
87

98
/**
109
* Operation for the dropDatabase command.
@@ -39,12 +38,7 @@ public function __construct($databaseName)
3938
public function execute(Server $server)
4039
{
4140
$cursor = $server->executeCommand($this->databaseName, new Command(['dropDatabase' => 1]));
42-
$result = current($cursor->toArray());
4341

44-
if (empty($result->ok)) {
45-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
46-
}
47-
48-
return $result;
42+
return current($cursor->toArray());
4943
}
5044
}

src/Operation/DropIndexes.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use MongoDB\Driver\Command;
66
use MongoDB\Driver\Server;
77
use MongoDB\Exception\InvalidArgumentException;
8-
use MongoDB\Exception\RuntimeException;
98

109
/**
1110
* Operation for the dropIndexes command.
@@ -56,12 +55,7 @@ public function execute(Server $server)
5655
];
5756

5857
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
59-
$result = current($cursor->toArray());
6058

61-
if (empty($result->ok)) {
62-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
63-
}
64-
65-
return $result;
59+
return current($cursor->toArray());
6660
}
6761
}

src/Operation/FindAndModify.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use MongoDB\Driver\Server;
77
use MongoDB\Exception\InvalidArgumentException;
88
use MongoDB\Exception\InvalidArgumentTypeException;
9-
use MongoDB\Exception\RuntimeException;
109
use MongoDB\Exception\UnexpectedValueException;
1110

1211
/**
@@ -120,10 +119,6 @@ public function execute(Server $server)
120119
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
121120
$result = current($cursor->toArray());
122121

123-
if (empty($result->ok)) {
124-
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
125-
}
126-
127122
if ( ! isset($result->value)) {
128123
return null;
129124
}

src/Operation/ListDatabases.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use MongoDB\Driver\Command;
66
use MongoDB\Driver\Server;
7-
use MongoDB\Exception\RuntimeException;
87
use MongoDB\Exception\UnexpectedValueException;
98
use MongoDB\Model\DatabaseInfoIterator;
109
use MongoDB\Model\DatabaseInfoLegacyIterator;
@@ -58,10 +57,6 @@ public function execute(Server $server)
5857
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
5958
$result = current($cursor->toArray());
6059

61-
if (empty($result['ok'])) {
62-
throw new RuntimeException(isset($result['errmsg']) ? $result['errmsg'] : 'Unknown error');
63-
}
64-
6560
if ( ! isset($result['databases']) || ! is_array($result['databases'])) {
6661
throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
6762
}

0 commit comments

Comments
 (0)