From 6b85f72604b9fe5dcff3915d582ca6fda6252626 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 2 Jan 2015 15:35:42 +0530 Subject: [PATCH] bug #4683 Relational data is not properly updated on table rename Signed-off-by: Madhura Jayaratne --- ChangeLog | 1 + libraries/relation.lib.php | 52 ++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef0a5551b8..53a8ee3e58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ phpMyAdmin - ChangeLog - bug #4679 Setup does not allow providing a name for favorites table - bug #4680 Number of favorite table are not configurable in setup - bug #4681 'Central columns table' field in setup does not have a description +- bug #4683 Relational data is not properly updated on table rename 4.3.4.0 (2014-12-29) - bug #4653 Always connection error was shown, on /setup at tab "configuration storage" diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 328d0bba61..8d1023e339 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -1613,21 +1613,57 @@ function PMA_REL_renameTable($source_db, $target_db, $source_table, $target_tabl ); } - /** - * @todo Can't get moving PDFs the right way. The page numbers - * always get screwed up independently from duplication because the - * numbers do not seem to be stored on a per-database basis. Would - * the author of pdf support please have a look at it? - */ - if ($GLOBALS['cfgRelation']['pdfwork']) { + if ($source_db == $target_db) { + // rename within the database can be handled + PMA_REL_renameSingleTable( + 'table_coords', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + } else { + // if the table is moved out of the database we can no loger keep the + // record for table coordinate + $remove_query = "DELETE FROM " + . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . "." + . PMA_Util::backquote($GLOBALS['cfgRelation']['table_coords']) + . " WHERE db_name = '" . PMA_Util::sqlAddSlashes($source_db) . "'" + . " AND table_name = '" . PMA_Util::sqlAddSlashes($source_table) + . "'"; + PMA_queryAsControlUser($remove_query); + } + } + + if ($GLOBALS['cfgRelation']['uiprefswork']) { PMA_REL_renameSingleTable( - 'table_coords', + 'table_uiprefs', $source_db, $target_db, $source_table, $target_table, 'db_name', 'table_name' ); } + + if ($GLOBALS['cfgRelation']['navwork']) { + // update hidden items inside table + PMA_REL_renameSingleTable( + 'navigationhiding', + $source_db, $target_db, + $source_table, $target_table, + 'db_name', 'table_name' + ); + + // update data for hidden table + $query = "UPDATE " + . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . "." + . PMA_Util::backquote($GLOBALS['cfgRelation']['navigationhiding']) + . " SET db_name = '" . PMA_Util::sqlAddSlashes($target_db) . "'," + . " item_name = '" . PMA_Util::sqlAddSlashes($target_table) . "'" + . " WHERE db_name = '" . PMA_Util::sqlAddSlashes($source_db) . "'" + . " AND item_name = '" . PMA_Util::sqlAddSlashes($source_table) . "'" + . " AND item_type = 'table'"; + PMA_queryAsControlUser($query); + } } /**