Skip to content

Commit a0f6ff6

Browse files
committed
reconnect the correct connection when using read or write connections
1 parent 8dcc5aa commit a0f6ff6

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ class Connection implements ConnectionInterface
161161
*/
162162
protected static $resolvers = [];
163163

164+
/**
165+
* The type of the connection.
166+
*
167+
* @var string|null
168+
*/
169+
protected $type;
170+
164171
/**
165172
* Create a new database connection instance.
166173
*
@@ -1045,6 +1052,16 @@ public function getName()
10451052
return $this->getConfig('name');
10461053
}
10471054

1055+
/**
1056+
* Get the database connection full name.
1057+
*
1058+
* @return string|null
1059+
*/
1060+
public function getFullName()
1061+
{
1062+
return $this->getName().($this->type ? '::'.$this->type : '');
1063+
}
1064+
10481065
/**
10491066
* Get an option from the configuration options.
10501067
*
@@ -1274,6 +1291,19 @@ public function setDatabaseName($database)
12741291
return $this;
12751292
}
12761293

1294+
/**
1295+
* Set the type of the connection.
1296+
*
1297+
* @param string $type
1298+
* @return $this
1299+
*/
1300+
public function setType($type)
1301+
{
1302+
$this->type = $type;
1303+
1304+
return $this;
1305+
}
1306+
12771307
/**
12781308
* Get the table prefix for the connection.
12791309
*

src/Illuminate/Database/DatabaseManager.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($app, ConnectionFactory $factory)
6262
$this->factory = $factory;
6363

6464
$this->reconnector = function ($connection) {
65-
$this->reconnect($connection->getName());
65+
$this->reconnect($connection->getFullName());
6666
};
6767
}
6868

@@ -165,7 +165,7 @@ protected function configuration($name)
165165
*/
166166
protected function configure(Connection $connection, $type)
167167
{
168-
$connection = $this->setPdoForType($connection, $type);
168+
$connection = $this->setPdoForType($connection, $type)->setType($type);
169169

170170
// First we'll set the fetch mode and a few other dependencies of the database
171171
// connection. This method basically just configures and prepares it to get
@@ -275,7 +275,11 @@ public function usingConnection($name, callable $callback)
275275
*/
276276
protected function refreshPdoConnections($name)
277277
{
278-
$fresh = $this->makeConnection($name);
278+
[$database, $type] = $this->parseConnectionName($name);
279+
280+
$fresh = $this->configure(
281+
$this->makeConnection($database), $type
282+
);
279283

280284
return $this->connections[$name]
281285
->setPdo($fresh->getRawPdo())

0 commit comments

Comments
 (0)