From f65871c1002ba31ffe3abe27fb71eeb360d834bf Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 3 Nov 2014 21:03:09 -0800 Subject: [PATCH] Success message for display column change. Update display column in the database only if it has changed from the original value. Signed-off-by: Madhura Jayaratne --- libraries/tbl_relation.lib.php | 36 ++++++++++++++++++++++------------ tbl_relation.php | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/libraries/tbl_relation.lib.php b/libraries/tbl_relation.lib.php index 71af0ed9ca..427986e03f 100644 --- a/libraries/tbl_relation.lib.php +++ b/libraries/tbl_relation.lib.php @@ -802,17 +802,23 @@ function PMA_sendHtmlForTableDropdownList() * @param string $table current table * @param array $cfgRelation configuration relation * - * @return void + * @return string */ function PMA_handleUpdateForDisplayField($disp, $display_field, $db, $table, $cfgRelation ) { + $html_output = ''; $upd_query = PMA_getQueryForDisplayUpdate( $disp, $display_field, $db, $table, $cfgRelation ); if ($upd_query) { PMA_queryAsControlUser($upd_query); + $html_output = PMA_Util::getMessage( + __('Display column was successfully updated.'), + null, 'success' + ); } + return $html_output; } /** @@ -831,7 +837,13 @@ function PMA_getQueryForDisplayUpdate($disp, $display_field, $db, $table, ) { $upd_query = false; if ($disp) { - if ($display_field != '') { + if ($display_field == '') { + $upd_query = 'DELETE FROM ' + . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) + . '.' . PMA_Util::backquote($cfgRelation['table_info']) + . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' + . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\''; + } elseif ($disp != $display_field) { $upd_query = 'UPDATE ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($cfgRelation['table_info']) @@ -839,12 +851,6 @@ function PMA_getQueryForDisplayUpdate($disp, $display_field, $db, $table, . PMA_Util::sqlAddSlashes($display_field) . '\'' . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\''; - } else { - $upd_query = 'DELETE FROM ' - . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) - . '.' . PMA_Util::backquote($cfgRelation['table_info']) - . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' - . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\''; } } elseif ($display_field != '') { $upd_query = 'INSERT INTO ' @@ -877,6 +883,8 @@ function PMA_handleUpdatesForInternalRelations($destination_db, $multi_edit_columns_name, $destination_table, $destination_column, $cfgRelation, $db, $table, $existrel ) { + $html_output = ''; + $updated = false; foreach ($destination_db as $master_field_md5 => $foreign_db) { $upd_query = PMA_getQueryForInternalRelationUpdate( $multi_edit_columns_name, @@ -885,12 +893,16 @@ function PMA_handleUpdatesForInternalRelations($destination_db, ); if ($upd_query) { PMA_queryAsControlUser($upd_query); + $updated = true; } } - return PMA_Util::getMessage( - __('Internal relations were successfully updated.'), - null, 'success' - ); + if ($updated) { + $html_output = PMA_Util::getMessage( + __('Internal relations were successfully updated.'), + null, 'success' + ); + } + return $html_output; } /** diff --git a/tbl_relation.php b/tbl_relation.php index f95d131b99..7bfc685906 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -122,7 +122,7 @@ if (isset($destination_foreign_db)) { // U p d a t e s f o r d i s p l a y f i e l d if ($cfgRelation['displaywork'] && isset($display_field)) { - PMA_handleUpdateForDisplayField( + $html_output .= PMA_handleUpdateForDisplayField( $disp, $display_field, $db, $table, $cfgRelation ); } // end if