Extend disabling foreign key check to row deletion
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
parent
47d6aea6a5
commit
2be7403799
@ -22,8 +22,6 @@
|
||||
* Unbind all event handlers before tearing down a page
|
||||
*/
|
||||
AJAX.registerTeardown('db_structure.js', function () {
|
||||
$("span.fkc_switch").unbind('click');
|
||||
$('#fkc_checkbox').unbind('change');
|
||||
$(document).off('click', "a.truncate_table_anchor.ajax");
|
||||
$(document).off('click', "a.drop_table_anchor.ajax");
|
||||
$(document).off('click', '#real_end_input');
|
||||
@ -245,27 +243,6 @@ AJAX.registerOnload('db_structure.js', function () {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Event handler for 'Foreign Key Checks' disabling option
|
||||
* in the drop table confirmation form
|
||||
*/
|
||||
$("span.fkc_switch").click(function (event) {
|
||||
if ($("#fkc_checkbox").prop('checked')) {
|
||||
$("#fkc_checkbox").prop('checked', false);
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckDisabled);
|
||||
return;
|
||||
}
|
||||
$("#fkc_checkbox").prop('checked', true);
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckEnabled);
|
||||
});
|
||||
|
||||
$('#fkc_checkbox').change(function () {
|
||||
if ($(this).prop("checked")) {
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckEnabled);
|
||||
return;
|
||||
}
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckDisabled);
|
||||
}); // End of event handler for 'Foreign Key Check'
|
||||
|
||||
/**
|
||||
* Ajax Event handler for 'Truncate Table'
|
||||
|
||||
@ -4049,6 +4049,7 @@ AJAX.registerTeardown('functions.js', function () {
|
||||
$('input#print').unbind('click');
|
||||
$(document).off('click', 'a.create_view.ajax');
|
||||
$(document).off('keydown', '#createViewDialog input, #createViewDialog select');
|
||||
$(document).off('change', '#fkc_checkbox');
|
||||
});
|
||||
|
||||
AJAX.registerOnload('functions.js', function () {
|
||||
@ -4096,6 +4097,14 @@ AJAX.registerOnload('functions.js', function () {
|
||||
syntaxHighlighter.on("inputRead", codemirrorAutocompleteOnInputRead);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('change', '#fkc_checkbox', function () {
|
||||
if ($(this).prop("checked")) {
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckEnabled);
|
||||
} else {
|
||||
$("#fkc_status").html(PMA_messages.strForeignKeyCheckDisabled);
|
||||
}
|
||||
}); // End of event handler for 'Foreign Key Check'
|
||||
});
|
||||
|
||||
function PMA_createViewDialog($this)
|
||||
|
||||
@ -214,6 +214,17 @@ if (!empty($submit_mult) && !empty($what)) {
|
||||
$GLOBALS['dbi']->freeResult($result);
|
||||
}
|
||||
|
||||
if (! isset($_REQUEST['fk_check'])
|
||||
&& ($query_type == 'drop_tbl' || $query_type == 'row_delete')
|
||||
) {
|
||||
$default_fk_check_value = $GLOBALS['dbi']->fetchValue(
|
||||
'SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1
|
||||
) == 'ON';
|
||||
|
||||
// for disabling foreign key checks while dropping tables
|
||||
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
|
||||
}
|
||||
|
||||
list(
|
||||
$result, $rebuild_database_list, $reload_ret,
|
||||
$run_parts, $use_sql, $sql_query, $sql_query_views
|
||||
@ -229,9 +240,6 @@ if (!empty($submit_mult) && !empty($what)) {
|
||||
}
|
||||
|
||||
if ($query_type == 'drop_tbl') {
|
||||
$default_fk_check_value = $GLOBALS['dbi']->fetchValue(
|
||||
'SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1
|
||||
) == 'ON';
|
||||
if (!empty($sql_query)) {
|
||||
$sql_query .= ';';
|
||||
} elseif (!empty($sql_query_views)) {
|
||||
@ -253,17 +261,7 @@ if (!empty($submit_mult) && !empty($what)) {
|
||||
);
|
||||
} elseif (!$run_parts) {
|
||||
$GLOBALS['dbi']->selectDb($db);
|
||||
// for disabling foreign key checks while dropping tables
|
||||
if (! isset($_REQUEST['fk_check']) && $query_type == 'drop_tbl') {
|
||||
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
|
||||
}
|
||||
$result = $GLOBALS['dbi']->tryQuery($sql_query);
|
||||
if (! isset($_REQUEST['fk_check'])
|
||||
&& $query_type == 'drop_tbl'
|
||||
&& $default_fk_check_value
|
||||
) {
|
||||
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;');
|
||||
}
|
||||
if ($result && !empty($sql_query_views)) {
|
||||
$sql_query .= ' ' . $sql_query_views . ';';
|
||||
$result = $GLOBALS['dbi']->tryQuery($sql_query_views);
|
||||
@ -274,6 +272,12 @@ if (!empty($submit_mult) && !empty($what)) {
|
||||
$message = PMA_Message::error($GLOBALS['dbi']->getError());
|
||||
}
|
||||
}
|
||||
if (! isset($_REQUEST['fk_check'])
|
||||
&& ($query_type == 'drop_tbl' || $query_type == 'row_delete')
|
||||
&& $default_fk_check_value
|
||||
) {
|
||||
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;');
|
||||
}
|
||||
if ($rebuild_database_list) {
|
||||
// avoid a problem with the database list navigator
|
||||
// when dropping a db from server_databases
|
||||
|
||||
@ -433,11 +433,11 @@ function PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
|
||||
$html .= '<form action="' . $action . '" method="post">';
|
||||
$html .= PMA_URL_getHiddenInputs($_url_params);
|
||||
// Display option to disable foreign key checks while dropping tables
|
||||
if ($what == 'drop_tbl') {
|
||||
if ($what == 'drop_tbl' || $what == 'row_delete') {
|
||||
$html .= '<div id="foreignkeychk">';
|
||||
$html .= '<span class="fkc_switch">';
|
||||
$html .= '<label for="fkc_checkbox">';
|
||||
$html .= __('Foreign key check:');
|
||||
$html .= '</span>';
|
||||
$html .= '</label>';
|
||||
$html .= '<span class="checkbox">';
|
||||
$html .= '<input type="checkbox" name="fk_check" value="1" '
|
||||
. 'id="fkc_checkbox"';
|
||||
@ -448,9 +448,9 @@ function PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
|
||||
$html .= ' checked="checked"';
|
||||
}
|
||||
$html .= '/></span>';
|
||||
$html .= '<span id="fkc_status" class="fkc_switch">';
|
||||
$html .= '<label id="fkc_status" for="fkc_checkbox">';
|
||||
$html .= ($default_fk_check_value) ? __('(Enabled)') : __('(Disabled)');
|
||||
$html .= '</span>';
|
||||
$html .= '</label>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
$html .= '<input type="hidden" name="mult_btn" value="' . __('Yes') . '" />';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user