Skip to content

fix: #1031, #1027 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions MongodbConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MongodbConnectionFactory implements ConnectionFactory
*
* or
*
* mongodb://127.0.0.1:27017/dbname?polling_interval=1000&enqueue_collection=enqueue
* mongodb://127.0.0.1:27017/defaultauthdb?polling_interval=1000&enqueue_database=enqueue&enqueue_collection=enqueue
*
* @param array|string|null $config
*/
Expand All @@ -38,7 +38,10 @@ public function __construct($config = 'mongodb:')
} elseif (is_string($config)) {
$config = $this->parseDsn($config);
} elseif (is_array($config)) {
$config = $this->parseDsn(empty($config['dsn']) ? 'mongodb:' : $config['dsn']);
$config = array_replace(
$config,
$this->parseDsn(empty($config['dsn']) ? 'mongodb:' : $config['dsn'])
);
} else {
throw new \LogicException('The config must be either an array of options, a DSN string or null');
}
Expand Down Expand Up @@ -86,6 +89,8 @@ public static function parseDsn(string $dsn): array
];
}
$config['dsn'] = $dsn;
// FIXME this is NOT a dbname but rather authdb. But removing this would be a BC break.
// see: https://github.com/php-enqueue/enqueue-dev/issues/1027
if (isset($parsedUrl['path']) && '/' !== $parsedUrl['path']) {
$pathParts = explode('/', $parsedUrl['path']);
//DB name
Expand All @@ -103,6 +108,9 @@ public static function parseDsn(string $dsn): array
if (!empty($queryParts['enqueue_collection'])) {
$config['collection_name'] = $queryParts['enqueue_collection'];
}
if (!empty($queryParts['enqueue_database'])) {
$config['dbname'] = $queryParts['enqueue_database'];
}
}

return $config;
Expand Down
2 changes: 1 addition & 1 deletion MongodbProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function send(Destination $destination, Message $message): void
$collection = $this->context->getCollection();
$collection->insertOne($mongoMessage);
} catch (\Exception $e) {
throw new Exception('The transport has failed to send the message due to some internal error.', null, $e);
throw new Exception('The transport has failed to send the message due to some internal error.', $e->getCode(), $e);
}
}

Expand Down