diff --git a/doc/config.rst b/doc/config.rst index 3bf15a2948..deb9a449a2 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -2374,6 +2374,16 @@ Design customization put when tables contents are displayed (you may have them displayed at the left side, right side, both sides or nowhere). +.. config:option:: $cfg['RowActionLinksWithoutUnique'] + + :type: boolean + :default: false + + Defines whether to show row links (Edit, Copy, Delete) and checkboxes + for multiple row operations even when the selection does not have a unique key. + Using row actions in the absence of a unique key may result in different/more + rows being affected since there is no guaranteed way to select the exact row(s). + .. config:option:: $cfg['RememberSorting'] :type: boolean diff --git a/libraries/config.default.php b/libraries/config.default.php index 79cb5390b9..a22ac96022 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2680,6 +2680,14 @@ $cfg['LimitChars'] = 50; */ $cfg['RowActionLinks'] = 'left'; +/** + * Whether to show row links (Edit, Copy, Delete) and checkboxes for + * multiple row operations even when the selection does not have a unique key. + * + * @global boolean $cfg['RowActionLinksWithoutUnique'] + */ +$cfg['RowActionLinksWithoutUnique'] = false; + /** * Default sort order by primary key. * @global string $cfg['TablePrimaryKeyOrder'] diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 51e8f41e36..498cabe743 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -490,6 +490,8 @@ $strConfigNumRecentTables_name = __('Recently used tables'); $strConfigNumFavoriteTables_name = __('Favorite tables'); $strConfigRowActionLinks_desc = __('These are Edit, Copy and Delete links.'); $strConfigRowActionLinks_name = __('Where to show the table row links'); +$strConfigRowActionLinksWithoutUnique_desc = __('Whether to show row links even in the absence of a unique key.'); +$strConfigRowActionLinksWithoutUnique_name = __('Show row links anyway'); $strConfigNaturalOrder_desc = __('Use natural order for sorting table and database names.'); $strConfigNaturalOrder_name = __('Natural order'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 095e745194..35a43448a2 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -218,6 +218,7 @@ $forms['Main_panel']['Browse'] = array( 'RepeatCells', 'LimitChars', 'RowActionLinks', + 'RowActionLinksWithoutUnique', 'TablePrimaryKeyOrder', 'RememberSorting', 'RelationalDisplay'); diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 6dac345429..ef9487f70a 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -125,6 +125,7 @@ $forms['Main_panel']['Browse'] = array( 'RepeatCells', 'LimitChars', 'RowActionLinks', + 'RowActionLinksWithoutUnique', 'TablePrimaryKeyOrder', 'RememberSorting', 'RelationalDisplay'); diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 58302ae694..247fc46e4b 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -1751,13 +1751,14 @@ function PMA_getHtmlForPreviousUpdateQuery($disp_query, $showSql, $sql_data, /** * To get the message if a column index is missing. If not will return null * - * @param string $table current table - * @param string $db current database - * @param boolean $editable whether the results table can be editable or not + * @param string $table current table + * @param string $db current database + * @param boolean $editable whether the results table can be editable or not + * @param boolean $has_unique whether there is a unique key * * @return PMA_message $message */ -function PMA_getMessageIfMissingColumnIndex($table, $db, $editable) +function PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $has_unique) { if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $missing_unique_column_msg = PMA_message::notice( @@ -1767,6 +1768,14 @@ function PMA_getMessageIfMissingColumnIndex($table, $db, $editable) . ' are not available.' ) ); + } elseif (! empty($table) && ! $has_unique) { + $missing_unique_column_msg = PMA_message::notice( + __( + 'Current selection does not contain a unique column.' + . ' Grid edit, Edit, Copy and Delete features may result in' + . ' undesired behavior.' + ) + ); } else { $missing_unique_column_msg = null; } @@ -1882,7 +1891,10 @@ function PMA_getQueryResponseForResultsReturned($result, $just_one_table = PMA_resultSetHasJustOneTable($fields_meta); - $editable = ($has_unique || $updatableView) && $just_one_table; + $editable = ($has_unique + || $GLOBALS['cfg']['RowActionLinksWithoutUnique'] + || $updatableView) + && $just_one_table; $displayParts = array( 'edit_lnk' => $displayResultsObject::UPDATE_ROW, @@ -1960,7 +1972,7 @@ function PMA_getQueryResponseForResultsReturned($result, ); $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex( - $table, $db, $editable + $table, $db, $editable, $has_unique ); $bookmark_created_msg = PMA_getBookmarkCreatedMessage();