@@ -84,18 +84,9 @@ public function create($id, array $data)
8484 throw $ ex ;
8585 }
8686
87- Config::set ('database.connections.dynamic ' , [
88- 'driver ' => 'mysql ' ,
89- 'host ' => $ host ->host ,
90- 'port ' => $ host ->port ,
91- 'database ' => 'mysql ' ,
92- 'username ' => $ host ->username ,
93- 'password ' => Crypt::decrypt ($ host ->password ),
94- 'charset ' => 'utf8 ' ,
95- 'collation ' => 'utf8_unicode_ci ' ,
96- ]);
97-
9887 try {
88+ $ host ->setDynamicConnection ();
89+
9990 DB ::connection ('dynamic ' )->statement (sprintf ('CREATE DATABASE IF NOT EXISTS `%s` ' , $ database ->database ));
10091 DB ::connection ('dynamic ' )->statement (sprintf (
10192 'CREATE USER `%s`@`%s` IDENTIFIED BY \'%s \'' ,
@@ -137,21 +128,11 @@ public function create($id, array $data)
137128 public function password ($ id , $ password )
138129 {
139130 $ database = Database::with ('host ' )->findOrFail ($ id );
131+ $ database ->host ->setDynamicConnection ();
140132
141133 DB ::transaction (function () use ($ database , $ password ) {
142134 $ database ->password = Crypt::encrypt ($ password );
143135
144- Config::set ('database.connections.dynamic ' , [
145- 'driver ' => 'mysql ' ,
146- 'host ' => $ database ->host ->host ,
147- 'port ' => $ database ->host ->port ,
148- 'database ' => 'mysql ' ,
149- 'username ' => $ database ->host ->username ,
150- 'password ' => Crypt::decrypt ($ database ->host ->password ),
151- 'charset ' => 'utf8 ' ,
152- 'collation ' => 'utf8_unicode_ci ' ,
153- ]);
154-
155136 // We have to do the whole delete user, create user thing rather than
156137 // SET PASSWORD ... because MariaDB and PHP statements ends up inserting
157138 // a corrupted password. A way around this is strtoupper(sha1(sha1($password, true)))
@@ -180,19 +161,9 @@ public function password($id, $password)
180161 public function drop ($ id )
181162 {
182163 $ database = Database::with ('host ' )->findOrFail ($ id );
164+ $ database ->host ->setDynamicConnection ();
183165
184166 DB ::transaction (function () use ($ database ) {
185- Config::set ('database.connections.dynamic ' , [
186- 'driver ' => 'mysql ' ,
187- 'host ' => $ database ->host ->host ,
188- 'port ' => $ database ->host ->port ,
189- 'database ' => 'mysql ' ,
190- 'username ' => $ database ->host ->username ,
191- 'password ' => Crypt::decrypt ($ database ->host ->password ),
192- 'charset ' => 'utf8 ' ,
193- 'collation ' => 'utf8_unicode_ci ' ,
194- ]);
195-
196167 DB ::connection ('dynamic ' )->statement (sprintf ('DROP DATABASE IF EXISTS `%s` ' , $ database ->database ));
197168 DB ::connection ('dynamic ' )->statement (sprintf ('DROP USER IF EXISTS `%s`@`%s` ' , $ database ->username , $ database ->remote ));
198169 DB ::connection ('dynamic ' )->statement ('FLUSH PRIVILEGES ' );
@@ -248,20 +219,6 @@ public function add(array $data)
248219 }
249220
250221 return DB ::transaction (function () use ($ data ) {
251- Config::set ('database.connections.dynamic ' , [
252- 'driver ' => 'mysql ' ,
253- 'host ' => $ data ['host ' ],
254- 'port ' => $ data ['port ' ],
255- 'database ' => 'mysql ' ,
256- 'username ' => $ data ['username ' ],
257- 'password ' => $ data ['password ' ],
258- 'charset ' => 'utf8 ' ,
259- 'collation ' => 'utf8_unicode_ci ' ,
260- ]);
261-
262- // Allows us to check that we can connect to things.
263- DB ::connection ('dynamic ' )->select ('SELECT 1 FROM dual ' );
264-
265222 $ host = new DatabaseHost ;
266223 $ host ->password = Crypt::encrypt ($ data ['password ' ]);
267224
@@ -274,6 +231,10 @@ public function add(array $data)
274231 'node_id ' => (isset ($ data ['node_id ' ])) ? $ data ['node_id ' ] : null ,
275232 ])->save ();
276233
234+ // Allows us to check that we can connect to things.
235+ $ host ->setDynamicConnection ();
236+ DB ::connection ('dynamic ' )->select ('SELECT 1 FROM dual ' );
237+
277238 return $ host ;
278239 });
279240 }
@@ -315,18 +276,7 @@ public function update($id, array $data)
315276 $ host ->fill ($ data )->save ();
316277
317278 // Check that we can still connect with these details.
318- Config::set ('database.connections.dynamic ' , [
319- 'driver ' => 'mysql ' ,
320- 'host ' => $ host ->host ,
321- 'port ' => $ host ->port ,
322- 'database ' => 'mysql ' ,
323- 'username ' => $ host ->username ,
324- 'password ' => Crypt::decrypt ($ host ->password ),
325- 'charset ' => 'utf8 ' ,
326- 'collation ' => 'utf8_unicode_ci ' ,
327- ]);
328-
329- // Allows us to check that we can connect to things.
279+ $ host ->setDynamicConnection ();
330280 DB ::connection ('dynamic ' )->select ('SELECT 1 FROM dual ' );
331281
332282 return $ host ;
0 commit comments