88use PhpMyAdmin \Database \Events ;
99use PhpMyAdmin \Database \Routines ;
1010use PhpMyAdmin \Database \Triggers ;
11+ use PhpMyAdmin \Dbal \DatabaseName ;
1112use PhpMyAdmin \Engines \Innodb ;
1213use PhpMyAdmin \Partitioning \Partition ;
1314use PhpMyAdmin \Plugins \Export \ExportSql ;
@@ -55,7 +56,7 @@ public function __construct(DatabaseInterface $dbi, Relation $relation)
5556 *
5657 * @param string $db database name
5758 */
58- public function runProcedureAndFunctionDefinitions ($ db , string $ newDatabaseName ): void
59+ public function runProcedureAndFunctionDefinitions ($ db , DatabaseName $ newDatabaseName ): void
5960 {
6061 $ procedure_names = Routines::getProcedureNames ($ this ->dbi , $ db );
6162 if ($ procedure_names ) {
@@ -95,7 +96,7 @@ public function runProcedureAndFunctionDefinitions($db, string $newDatabaseName)
9596 /**
9697 * Create database before copy
9798 */
98- public function createDbBeforeCopy (string $ newDatabaseName ): void
99+ public function createDbBeforeCopy (DatabaseName $ newDatabaseName ): void
99100 {
100101 $ local_query = 'CREATE DATABASE IF NOT EXISTS '
101102 . Util::backquote ($ newDatabaseName );
@@ -137,7 +138,7 @@ public function getViewsAndCreateSqlViewStandIn(
137138 array $ tables_full ,
138139 $ export_sql_plugin ,
139140 $ db ,
140- string $ newDatabaseName
141+ DatabaseName $ newDatabaseName
141142 ) {
142143 $ views = [];
143144 foreach (array_keys ($ tables_full ) as $ each_table ) {
@@ -178,7 +179,7 @@ public function getViewsAndCreateSqlViewStandIn(
178179 *
179180 * @return array SQL queries for the constraints
180181 */
181- public function copyTables (array $ tables_full , $ move , $ db , string $ newDatabaseName )
182+ public function copyTables (array $ tables_full , $ move , $ db , DatabaseName $ newDatabaseName )
182183 {
183184 $ sqlContraints = [];
184185 foreach (array_keys ($ tables_full ) as $ each_table ) {
@@ -215,7 +216,7 @@ public function copyTables(array $tables_full, $move, $db, string $newDatabaseNa
215216 ! Table::moveCopy (
216217 $ db ,
217218 $ each_table ,
218- $ newDatabaseName ,
219+ $ newDatabaseName-> getName () ,
219220 $ each_table ,
220221 ($ this_what ?? 'data ' ),
221222 $ move ,
@@ -257,7 +258,7 @@ public function copyTables(array $tables_full, $move, $db, string $newDatabaseNa
257258 *
258259 * @param string $db database name
259260 */
260- public function runEventDefinitionsForDb ($ db , string $ newDatabaseName ): void
261+ public function runEventDefinitionsForDb ($ db , DatabaseName $ newDatabaseName ): void
261262 {
262263 $ event_names = $ this ->dbi ->fetchResult (
263264 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
@@ -284,14 +285,14 @@ public function runEventDefinitionsForDb($db, string $newDatabaseName): void
284285 * @param bool $move whether database name is empty or not
285286 * @param string $db database name
286287 */
287- public function handleTheViews (array $ views , $ move , $ db , string $ newDatabaseName ): void
288+ public function handleTheViews (array $ views , $ move , $ db , DatabaseName $ newDatabaseName ): void
288289 {
289290 // Add DROP IF EXIST to CREATE VIEW query, to remove stand-in VIEW that was created earlier.
290291 foreach ($ views as $ view ) {
291292 $ copying_succeeded = Table::moveCopy (
292293 $ db ,
293294 $ view ,
294- $ newDatabaseName ,
295+ $ newDatabaseName-> getName () ,
295296 $ view ,
296297 'structure ' ,
297298 $ move ,
@@ -310,7 +311,7 @@ public function handleTheViews(array $views, $move, $db, string $newDatabaseName
310311 *
311312 * @param string $oldDb Database name before renaming
312313 */
313- public function adjustPrivilegesMoveDb ($ oldDb , string $ newDatabaseName ): void
314+ public function adjustPrivilegesMoveDb ($ oldDb , DatabaseName $ newDatabaseName ): void
314315 {
315316 if (
316317 ! $ GLOBALS ['db_priv ' ] || ! $ GLOBALS ['table_priv ' ]
@@ -321,30 +322,30 @@ public function adjustPrivilegesMoveDb($oldDb, string $newDatabaseName): void
321322 }
322323
323324 $ this ->dbi ->selectDb ('mysql ' );
324- $ newDatabaseName = str_replace ('_ ' , '\_ ' , $ newDatabaseName );
325+ $ newName = str_replace ('_ ' , '\_ ' , $ newDatabaseName-> getName () );
325326 $ oldDb = str_replace ('_ ' , '\_ ' , $ oldDb );
326327
327328 // For Db specific privileges
328329 $ query_db_specific = 'UPDATE ' . Util::backquote ('db ' )
329- . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newDatabaseName )
330+ . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newName )
330331 . '\' where Db = \'' . $ this ->dbi ->escapeString ($ oldDb ) . '\'; ' ;
331332 $ this ->dbi ->query ($ query_db_specific );
332333
333334 // For table specific privileges
334335 $ query_table_specific = 'UPDATE ' . Util::backquote ('tables_priv ' )
335- . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newDatabaseName )
336+ . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newName )
336337 . '\' where Db = \'' . $ this ->dbi ->escapeString ($ oldDb ) . '\'; ' ;
337338 $ this ->dbi ->query ($ query_table_specific );
338339
339340 // For column specific privileges
340341 $ query_col_specific = 'UPDATE ' . Util::backquote ('columns_priv ' )
341- . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newDatabaseName )
342+ . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newName )
342343 . '\' where Db = \'' . $ this ->dbi ->escapeString ($ oldDb ) . '\'; ' ;
343344 $ this ->dbi ->query ($ query_col_specific );
344345
345346 // For procedures specific privileges
346347 $ query_proc_specific = 'UPDATE ' . Util::backquote ('procs_priv ' )
347- . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newDatabaseName )
348+ . 'SET Db = \'' . $ this ->dbi ->escapeString ($ newName )
348349 . '\' where Db = \'' . $ this ->dbi ->escapeString ($ oldDb ) . '\'; ' ;
349350 $ this ->dbi ->query ($ query_proc_specific );
350351
@@ -358,7 +359,7 @@ public function adjustPrivilegesMoveDb($oldDb, string $newDatabaseName): void
358359 *
359360 * @param string $oldDb Database name before copying
360361 */
361- public function adjustPrivilegesCopyDb ($ oldDb , string $ newDatabaseName ): void
362+ public function adjustPrivilegesCopyDb ($ oldDb , DatabaseName $ newDatabaseName ): void
362363 {
363364 if (
364365 ! $ GLOBALS ['db_priv ' ] || ! $ GLOBALS ['table_priv ' ]
@@ -369,7 +370,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
369370 }
370371
371372 $ this ->dbi ->selectDb ('mysql ' );
372- $ newDatabaseName = str_replace ('_ ' , '\_ ' , $ newDatabaseName );
373+ $ newName = str_replace ('_ ' , '\_ ' , $ newDatabaseName-> getName () );
373374 $ oldDb = str_replace ('_ ' , '\_ ' , $ oldDb );
374375
375376 $ query_db_specific_old = 'SELECT * FROM '
@@ -380,7 +381,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
380381
381382 foreach ($ old_privs_db as $ old_priv ) {
382383 $ newDb_db_privs_query = 'INSERT INTO ' . Util::backquote ('db ' )
383- . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newDatabaseName . '" ' ;
384+ . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newName . '" ' ;
384385 $ privCount = count ($ old_priv );
385386 for ($ i = 2 ; $ i < $ privCount ; $ i ++) {
386387 $ newDb_db_privs_query .= ', " ' . $ old_priv [$ i ] . '" ' ;
@@ -401,7 +402,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
401402 foreach ($ old_privs_table as $ old_priv ) {
402403 $ newDb_table_privs_query = 'INSERT INTO ' . Util::backquote (
403404 'tables_priv '
404- ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newDatabaseName . '", " '
405+ ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newName . '", " '
405406 . $ old_priv [2 ] . '", " ' . $ old_priv [3 ] . '", " ' . $ old_priv [4 ]
406407 . '", " ' . $ old_priv [5 ] . '", " ' . $ old_priv [6 ] . '", " '
407408 . $ old_priv [7 ] . '"); ' ;
@@ -419,7 +420,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
419420 foreach ($ old_privs_col as $ old_priv ) {
420421 $ newDb_col_privs_query = 'INSERT INTO ' . Util::backquote (
421422 'columns_priv '
422- ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newDatabaseName . '", " '
423+ ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newName . '", " '
423424 . $ old_priv [2 ] . '", " ' . $ old_priv [3 ] . '", " ' . $ old_priv [4 ]
424425 . '", " ' . $ old_priv [5 ] . '", " ' . $ old_priv [6 ] . '"); ' ;
425426
@@ -436,7 +437,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
436437 foreach ($ old_privs_proc as $ old_priv ) {
437438 $ newDb_proc_privs_query = 'INSERT INTO ' . Util::backquote (
438439 'procs_priv '
439- ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newDatabaseName . '", " '
440+ ) . ' VALUES(" ' . $ old_priv [0 ] . '", " ' . $ newName . '", " '
440441 . $ old_priv [2 ] . '", " ' . $ old_priv [3 ] . '", " ' . $ old_priv [4 ]
441442 . '", " ' . $ old_priv [5 ] . '", " ' . $ old_priv [6 ] . '", " '
442443 . $ old_priv [7 ] . '"); ' ;
@@ -454,7 +455,7 @@ public function adjustPrivilegesCopyDb($oldDb, string $newDatabaseName): void
454455 *
455456 * @param array $sqlConstratints array of sql constraints for the database
456457 */
457- public function createAllAccumulatedConstraints (array $ sqlConstratints , string $ newDatabaseName ): void
458+ public function createAllAccumulatedConstraints (array $ sqlConstratints , DatabaseName $ newDatabaseName ): void
458459 {
459460 $ this ->dbi ->selectDb ($ newDatabaseName );
460461 foreach ($ sqlConstratints as $ one_query ) {
@@ -470,9 +471,9 @@ public function createAllAccumulatedConstraints(array $sqlConstratints, string $
470471 * @param bool $_error whether table rename/copy or not
471472 * @param string $db database name
472473 */
473- public function duplicateBookmarks ($ _error , $ db , string $ newDatabaseName ): void
474+ public function duplicateBookmarks ($ _error , $ db , DatabaseName $ newDatabaseName ): void
474475 {
475- if ($ _error || $ db === $ newDatabaseName ) {
476+ if ($ _error || $ db === $ newDatabaseName-> getName () ) {
476477 return ;
477478 }
478479
@@ -482,7 +483,7 @@ public function duplicateBookmarks($_error, $db, string $newDatabaseName): void
482483 'query ' ,
483484 ];
484485 $ where_fields = ['dbase ' => $ db ];
485- $ new_fields = ['dbase ' => $ newDatabaseName ];
486+ $ new_fields = ['dbase ' => $ newDatabaseName-> getName () ];
486487 Table::duplicateInfo ('bookmarkwork ' , 'bookmark ' , $ get_fields , $ where_fields , $ new_fields );
487488 }
488489
0 commit comments