Commit 4327715e authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #64

parents 9d087e5a 3ba5c438
......@@ -12,9 +12,9 @@ env:
- MONGO_REPO_TYPE="precise/mongodb-enterprise/"
- SOURCES_LOC="/etc/apt/sources.list.d/mongodb.list"
matrix:
- DRIVER_VERSION=1.0 SERVER_VERSION=2.4
- DRIVER_VERSION=1.0 SERVER_VERSION=2.6
- DRIVER_VERSION=1.0 SERVER_VERSION=3.0
- DRIVER_VERSION=1.0.0 SERVER_VERSION=2.4
- DRIVER_VERSION=1.0.0 SERVER_VERSION=2.6
- DRIVER_VERSION=1.0.0 SERVER_VERSION=3.0
before_install:
- sudo apt-key adv --keyserver ${KEY_SERVER} --recv 7F0CEB10
......@@ -32,6 +32,7 @@ before_script:
- if ! nc -z localhost 27017; then sudo service ${SERVER_SERVICE} start; fi
- mongod --version
- pecl install -f mongodb-${DRIVER_VERSION}
- if [ "$(php -v | grep 'PHP 5.4')" ]; then echo 'extension = mongodb.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
- php --ri mongodb
- composer install --dev --no-interaction --prefer-source
- ulimit -c
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
use ArrayIterator;
use stdClass;
......@@ -136,10 +135,6 @@ class Aggregate implements Executable
$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)) {
throw new UnexpectedValueException('aggregate command did not return a "result" array');
}
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -100,10 +99,6 @@ class Count implements Executable
$cursor = $server->executeCommand($this->databaseName, $this->createCommand(), $readPreference);
$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
if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
throw new UnexpectedValueException('count command did not return a numeric "n" value');
......
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedTypeException;
use MongoDB\Model\IndexInput;
......@@ -102,13 +101,8 @@ class CreateCollection implements Executable
public function execute(Server $server)
{
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
return $result;
return current($cursor->toArray());
}
/**
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\Server;
use MongoDB\Driver\BulkWrite as Bulk;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedTypeException;
use MongoDB\Model\IndexInput;
......@@ -92,11 +91,8 @@ class CreateIndexes implements Executable
]);
$cursor = $server->executeCommand($this->databaseName, $command);
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
return current($cursor->toArray());
}
/**
......
......@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -77,10 +76,6 @@ class Distinct implements Executable
$cursor = $server->executeCommand($this->databaseName, $this->createCommand(), $readPreference);
$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)) {
throw new UnexpectedValueException('distinct command did not return a "values" array');
}
......
......@@ -4,8 +4,7 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Driver\Exception\RuntimeException;
/**
* Operation for the drop command.
......@@ -44,24 +43,18 @@ class DropCollection implements Executable
{
try {
$cursor = $server->executeCommand($this->databaseName, new Command(['drop' => $this->collectionName]));
} catch (DriverRuntimeException $e) {
} catch (RuntimeException $e) {
/* The server may return an error if the collection does not exist.
* Check for an error message (unfortunately, there isn't a code)
* and NOP instead of throwing.
*/
if ($e->getMessage() === self::$errorMessageNamespaceNotFound) {
return (object) ['ok' => 0, 'errmsg' => 'ns not found'];
return (object) ['ok' => 0, 'errmsg' => self::$errorMessageNamespaceNotFound];
}
throw $e;
}
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
return $result;
return current($cursor->toArray());
}
}
......@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\RuntimeException;
/**
* Operation for the dropDatabase command.
......@@ -39,12 +38,7 @@ class DropDatabase implements Executable
public function execute(Server $server)
{
$cursor = $server->executeCommand($this->databaseName, new Command(['dropDatabase' => 1]));
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
return $result;
return current($cursor->toArray());
}
}
......@@ -5,7 +5,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\RuntimeException;
/**
* Operation for the dropIndexes command.
......@@ -56,12 +55,7 @@ class DropIndexes implements Executable
];
$cursor = $server->executeCommand($this->databaseName, new Command($cmd));
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
return $result;
return current($cursor->toArray());
}
}
......@@ -6,7 +6,6 @@ use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\InvalidArgumentTypeException;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
/**
......@@ -120,10 +119,6 @@ class FindAndModify implements Executable
$cursor = $server->executeCommand($this->databaseName, $this->createCommand());
$result = current($cursor->toArray());
if (empty($result->ok)) {
throw new RuntimeException(isset($result->errmsg) ? $result->errmsg : 'Unknown error');
}
if ( ! isset($result->value)) {
return null;
}
......
......@@ -4,7 +4,6 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\RuntimeException;
use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Model\DatabaseInfoIterator;
use MongoDB\Model\DatabaseInfoLegacyIterator;
......@@ -58,10 +57,6 @@ class ListDatabases implements Executable
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$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'])) {
throw new UnexpectedValueException('listDatabases command did not return a "databases" array');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment