Skip to content

Commit 6f546e3

Browse files
committed
Merge remote-tracking branch 'origin/dev-main' into dev-l9
2 parents c1cb0dc + f9a65e3 commit 6f546e3

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

src/Connection.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ class Connection extends BaseConnection
2222
protected $retires = null; //null will use default
2323
protected $elasticMetaHeader = null;
2424
protected $rebuild = false;
25+
protected $connectionName = 'elasticsearch';
2526

2627

2728
public function __construct(array $config)
2829
{
30+
31+
$this->connectionName = $config['name'];
32+
2933
$this->config = $config;
3034

3135
$this->setOptions($config);
@@ -199,11 +203,11 @@ protected function buildConnection(): Client
199203

200204
protected function _httpConnection(): Client
201205
{
202-
$hosts = config('database.connections.elasticsearch.hosts') ?? null;
203-
$username = config('database.connections.elasticsearch.username') ?? null;
204-
$pass = config('database.connections.elasticsearch.password') ?? null;
205-
$apiId = config('database.connections.elasticsearch.api_id') ?? null;
206-
$apiKey = config('database.connections.elasticsearch.api_key') ?? null;
206+
$hosts = config('database.connections.'.$this->connectionName.'.hosts') ?? null;
207+
$username = config('database.connections.'.$this->connectionName.'.username') ?? null;
208+
$pass = config('database.connections.'.$this->connectionName.'.password') ?? null;
209+
$apiId = config('database.connections.'.$this->connectionName.'.api_id') ?? null;
210+
$apiKey = config('database.connections.'.$this->connectionName.'.api_key') ?? null;
207211
$cb = ClientBuilder::create()->setHosts($hosts);
208212
$cb = $this->_builderOptions($cb);
209213
if ($username && $pass) {
@@ -218,11 +222,11 @@ protected function _httpConnection(): Client
218222

219223
protected function _cloudConnection(): Client
220224
{
221-
$cloudId = config('database.connections.elasticsearch.cloud_id') ?? null;
222-
$username = config('database.connections.elasticsearch.username') ?? null;
223-
$pass = config('database.connections.elasticsearch.password') ?? null;
224-
$apiId = config('database.connections.elasticsearch.api_id') ?? null;
225-
$apiKey = config('database.connections.elasticsearch.api_key') ?? null;
225+
$cloudId = config('database.connections.'.$this->connectionName.'.cloud_id') ?? null;
226+
$username = config('database.connections.'.$this->connectionName.'.username') ?? null;
227+
$pass = config('database.connections.'.$this->connectionName.'.password') ?? null;
228+
$apiId = config('database.connections.'.$this->connectionName.'.api_id') ?? null;
229+
$apiKey = config('database.connections.'.$this->connectionName.'.api_key') ?? null;
226230

227231
$cb = ClientBuilder::create()->setElasticCloudId($cloudId);
228232
$cb = $this->_builderOptions($cb);
@@ -247,14 +251,14 @@ protected function _builderOptions($cb)
247251
if (isset($this->retires)) {
248252
$cb->setRetries($this->retires);
249253
}
250-
$caBundle = config('database.connections.elasticsearch.ssl_cert') ?? null;
254+
$caBundle = config('database.connections.'.$this->connectionName.'.ssl_cert') ?? null;
251255
if ($caBundle) {
252256
$cb->setCABundle($caBundle);
253257
}
254-
$sslCert = config('database.connections.elasticsearch.ssl.cert') ?? null;
255-
$sslCertPassword = config('database.connections.elasticsearch.ssl.cert_password') ?? null;
256-
$sslKey = config('database.connections.elasticsearch.ssl.key') ?? null;
257-
$sslKeyPassword = config('database.connections.elasticsearch.ssl.key_password') ?? null;
258+
$sslCert = config('database.connections.'.$this->connectionName.'.ssl.cert') ?? null;
259+
$sslCertPassword = config('database.connections.'.$this->connectionName.'.ssl.cert_password') ?? null;
260+
$sslKey = config('database.connections.'.$this->connectionName.'.ssl.key') ?? null;
261+
$sslKeyPassword = config('database.connections.'.$this->connectionName.'.ssl.key_password') ?? null;
258262
if ($sslCert) {
259263
$cb->setSSLCert($sslCert, $sslCertPassword);
260264
}

src/Query/Builder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,29 +1242,29 @@ public function truncate()
12421242

12431243
public function deleteIndex()
12441244
{
1245-
return Schema::delete($this->index);
1245+
return Schema::connection($this->connection->getName())->delete($this->index);
12461246

12471247
}
12481248

12491249
public function deleteIndexIfExists()
12501250
{
1251-
return Schema::deleteIfExists($this->index);
1251+
return Schema::connection($this->connection->getName())->deleteIfExists($this->index);
12521252

12531253
}
12541254

12551255
public function getIndexMappings()
12561256
{
1257-
return Schema::getMappings($this->index);
1257+
return Schema::connection($this->connection->getName())->getMappings($this->index);
12581258
}
12591259

12601260
public function getIndexSettings()
12611261
{
1262-
return Schema::getSettings($this->index);
1262+
return Schema::connection($this->connection->getName())->getSettings($this->index);
12631263
}
12641264

12651265
public function indexExists()
12661266
{
1267-
return Schema::hasIndex($this->index);
1267+
return Schema::connection($this->connection->getName())->hasIndex($this->index);
12681268
}
12691269

12701270
public function createIndex()

src/Schema/Schema.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,19 @@ class Schema extends Facade
4747
*/
4848
public static function connection($name)
4949
{
50+
51+
if ($name === null) {
52+
return static::getFacadeAccessor();
53+
}
54+
5055
return static::$app['db']->connection($name)->getSchemaBuilder();
5156
}
5257

58+
public static function on($name)
59+
{
60+
return static::connection($name);
61+
}
62+
5363
/**
5464
* Get a schema builder instance for the default connection.
5565
*

0 commit comments

Comments
 (0)