From 34b18e0ae9921f63e41da2a8b38986727a9a0096 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 17 Dec 2012 07:49:09 -0500 Subject: [PATCH 01/10] Refactoring attempt to start fixing the "Missing redirection to table structure" bug --- libraries/structure.lib.php | 196 ++++++++++++++++++++++++++++++- libraries/tbl_properties.inc.php | 11 +- tbl_alter.php | 191 ------------------------------ tbl_structure.php | 17 +++ 4 files changed, 218 insertions(+), 197 deletions(-) diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 01c56cbfef..eca5446df8 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1316,8 +1316,8 @@ function PMA_getHtmlForDropColumn($tbl_is_view, $db_is_information_schema, if (! $tbl_is_view && ! $db_is_information_schema) { $html_output .= '' - . '' + . '' . $titles['Change'] . '' . ''; $html_output .= '' . ' updates the table - */ -$abort = false; -if (isset($_REQUEST['do_save_data'])) { - $field_cnt = count($_REQUEST['field_orig']); - $key_fields = array(); - $changes = array(); - - for ($i = 0; $i < $field_cnt; $i++) { - $changes[] = 'CHANGE ' . PMA_Table::generateAlter( - $_REQUEST['field_orig'][$i], - $_REQUEST['field_name'][$i], - $_REQUEST['field_type'][$i], - $_REQUEST['field_length'][$i], - $_REQUEST['field_attribute'][$i], - isset($_REQUEST['field_collation'][$i]) - ? $_REQUEST['field_collation'][$i] - : '', - isset($_REQUEST['field_null'][$i]) - ? $_REQUEST['field_null'][$i] - : 'NOT NULL', - $_REQUEST['field_default_type'][$i], - $_REQUEST['field_default_value'][$i], - isset($_REQUEST['field_extra'][$i]) - ? $_REQUEST['field_extra'][$i] - : false, - isset($_REQUEST['field_comments'][$i]) - ? $_REQUEST['field_comments'][$i] - : '', - $key_fields, - $i, - isset($_REQUEST['field_move_to'][$i]) - ? $_REQUEST['field_move_to'][$i] - : '' - ); - } // end for - - // Builds the primary keys statements and updates the table - $key_query = ''; - /** - * this is a little bit more complex - * - * @todo if someone selects A_I when altering a column we need to check: - * - no other column with A_I - * - the column has an index, if not create one - * - if (count($key_fields)) { - $fields = array(); - foreach ($key_fields as $each_field) { - if (isset($_REQUEST['field_name'][$each_field]) && strlen($_REQUEST['field_name'][$each_field])) { - $fields[] = PMA_Util::backquote($_REQUEST['field_name'][$each_field]); - } - } // end for - $key_query = ', ADD KEY (' . implode(', ', $fields) . ') '; - } - */ - - // To allow replication, we first select the db to use and then run queries - // on this db. - if (! PMA_DBI_select_db($db)) { - PMA_Util::mysqlDie( - PMA_DBI_getError(), - 'USE ' . PMA_Util::backquote($db) . ';', - '', - $err_url - ); - } - $sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' '; - $sql_query .= implode(', ', $changes) . $key_query; - $sql_query .= ';'; - $result = PMA_DBI_try_query($sql_query); - - if ($result !== false) { - $message = PMA_Message::success( - __('Table %1$s has been altered successfully') - ); - $message->addParam($table); - $btnDrop = 'Fake'; - - /** - * If comments were sent, enable relation stuff - */ - include_once 'libraries/transformations.lib.php'; - - // update field names in relation - if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) { - foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { - if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { - PMA_REL_renameField( - $db, $table, $fieldcontent, - $_REQUEST['field_name'][$fieldindex] - ); - } - } - } - - // update mime types - if (isset($_REQUEST['field_mimetype']) - && is_array($_REQUEST['field_mimetype']) - && $cfg['BrowseMIME'] - ) { - foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) { - if (isset($_REQUEST['field_name'][$fieldindex]) - && strlen($_REQUEST['field_name'][$fieldindex]) - ) { - PMA_setMIME( - $db, $table, $_REQUEST['field_name'][$fieldindex], - $mimetype, - $_REQUEST['field_transformation'][$fieldindex], - $_REQUEST['field_transformation_options'][$fieldindex] - ); - } - } - } - - $response = PMA_Response::getInstance(); - if ($response->isAjax()) { - $response->isSuccess($message->isSuccess()); - $response->addJSON('message', $message); - $response->addJSON( - 'sql_query', - PMA_Util::getMessage(null, $sql_query) - ); - exit; - } - - $active_page = 'tbl_structure.php'; - include 'tbl_structure.php'; - } else { - PMA_Util::mysqlDie('', '', '', $err_url, false); - // An error happened while inserting/updating a table definition. - // to prevent total loss of that data, we embed the form once again. - // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php - if (isset($_REQUEST['orig_field'])) { - $_REQUEST['field'] = $_REQUEST['orig_field']; - } - - $regenerate = true; - } -} - -/** - * No modifications yet required -> displays the table fields - * - * $selected comes from multi_submits.inc.php - */ -if ($abort == false) { - if (! isset($selected)) { - PMA_Util::checkParameters(array('field')); - $selected[] = $_REQUEST['field']; - $selected_cnt = 1; - } else { // from a multiple submit - $selected_cnt = count($selected); - } - - /** - * @todo optimize in case of multiple fields to modify - */ - for ($i = 0; $i < $selected_cnt; $i++) { - $fields_meta[] = PMA_DBI_get_columns($db, $table, $selected[$i], true); - } - $num_fields = count($fields_meta); - $action = 'tbl_alter.php'; - - // Get more complete field information. - // For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options - // and to know when there is an empty DEFAULT value. - // Later, if the analyser returns more information, it - // could be executed to replace the info given by SHOW FULL COLUMNS FROM. - /** - * @todo put this code into a require() - * or maybe make it part of PMA_DBI_get_columns(); - */ - - // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since - // SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested - // in MySQL 4.0.25). - - $show_create_table = PMA_DBI_fetch_value( - 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), - 0, 1 - ); - $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); - unset($show_create_table); - /** - * Form for changing properties. - */ - include 'libraries/tbl_properties.inc.php'; -} ?> diff --git a/tbl_structure.php b/tbl_structure.php index c96e02c344..a4a5bb9ea0 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -24,6 +24,23 @@ $scripts = $header->getScripts(); $scripts->addFile('tbl_structure.js'); $scripts->addFile('indexes.js'); +/** + * A click on Change has been made for one column + */ +if (isset($_REQUEST['change_column'])) { + PMA_getHtmlForColumnChange($db, $table, null, 'tbl_structure.php'); + exit; +} +/** + * Modifications have been submitted -> updates the table + */ +if (isset($_REQUEST['do_save_data'])) { + PMA_updateColumns($db, $table); + // and continue to show the table's structure + unset($_REQUEST['selected']); + unset($_REQUEST['true_selected']); +} + /** * handle multiple field commands if required * From 5c639aebbc590165a874608ffa049fd0d4881b7b Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 18 Dec 2012 07:27:39 -0500 Subject: [PATCH 02/10] Handler for column Change --- js/tbl_structure.js | 19 +++++++++++++++++++ libraries/structure.lib.php | 24 +++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/js/tbl_structure.js b/js/tbl_structure.js index c34a6b801c..8e19c84204 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -22,6 +22,7 @@ * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('tbl_structure.js', function() { + $("a.change_column_anchor.ajax").die('click'); $("a.drop_column_anchor.ajax").die('click'); $("a.add_primary_key_anchor.ajax").die('click'); $('a.drop_primary_key_index_anchor.ajax').die('click'); @@ -31,6 +32,23 @@ AJAX.registerTeardown('tbl_structure.js', function() { }); AJAX.registerOnload('tbl_structure.js', function() { + /** + * Attach Event Handler for 'Change Column' + * + * (see $GLOBALS['cfg']['AjaxEnable']) + */ + $("a.change_column_anchor.ajax").live('click', function(event) { + event.preventDefault(); + $('#page_content').hide(); + $.get($(this).attr('href'), {'ajax_request': true}, function(data) { + if (data.success) { + $('
') + .html(data.message) + .insertBefore('#page_content'); + } + }); + }); + /** * Attach Event Handler for 'Drop Column' * @@ -356,6 +374,7 @@ function reloadFieldForm(message) { PMA_ajaxShowMessage(message); }, 500); }); + $('#page_content').show(); } /** diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index eca5446df8..a683d541c7 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1316,8 +1316,11 @@ function PMA_getHtmlForDropColumn($tbl_is_view, $db_is_information_schema, if (! $tbl_is_view && ! $db_is_information_schema) { $html_output .= '' - . '
' + . '' . $titles['Change'] . '' . ''; $html_output .= '' . '') + .html(data.message) + .insertBefore('#page_content'); + } + }); + }); + /** * Attach Event Handler for 'Drop Column' * diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 8eddf7db91..f3b7d9a8e7 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -125,7 +125,7 @@ if (! empty($submit_mult) $mult_btn = __('Yes'); break; case 'change': - include './tbl_alter.php'; + PMA_getHtmlForColumnChange($db, $table, $selected, $action); // execution stops here but PMA_Response correctly finishes // the rendering exit; diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index a683d541c7..74f45cc74d 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1377,8 +1377,8 @@ function PMA_getHtmlForCheckAllTableColumn($pmaThemeImage, $text_dir, if (! $tbl_is_view && ! $db_is_information_schema) { $html_output .= PMA_Util::getButtonOrImage( - 'submit_mult', 'mult_submit', 'submit_mult_change', - __('Change'), 'b_edit.png', 'change' + 'submit_mult', 'mult_submit change_columns_anchor ajax', + 'submit_mult_change', __('Change'), 'b_edit.png', 'change' ); $html_output .= PMA_Util::getButtonOrImage( 'submit_mult', 'mult_submit', 'submit_mult_drop', From 4547c9a7c8dc197043f722a68a698e8d07cd16d7 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 18 Dec 2012 08:19:13 -0500 Subject: [PATCH 04/10] Handle the multiple columns Change input (for IE < 9) --- js/tbl_structure.js | 4 ++-- libraries/Util.class.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/js/tbl_structure.js b/js/tbl_structure.js index 10cb1ee0a8..85e6102540 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -23,7 +23,7 @@ */ AJAX.registerTeardown('tbl_structure.js', function() { $("a.change_column_anchor.ajax").die('click'); - $("button.change_columns_anchor.ajax").die('click'); + $("button.change_columns_anchor.ajax, input.change_columns_anchor.ajax").die('click'); $("a.drop_column_anchor.ajax").die('click'); $("a.add_primary_key_anchor.ajax").die('click'); $('a.drop_primary_key_index_anchor.ajax').die('click'); @@ -55,7 +55,7 @@ AJAX.registerOnload('tbl_structure.js', function() { * * (see $GLOBALS['cfg']['AjaxEnable']) */ - $("button.change_columns_anchor.ajax").live('click', function(event) { + $("button.change_columns_anchor.ajax, input.change_columns_anchor.ajax").live('click', function(event) { event.preventDefault(); $('#page_content').hide(); var $form = $(this).closest('form'); diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 5287386b35..1da643eab2 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -2321,7 +2321,7 @@ class PMA_Util * Generate a button or image tag * * @param string $button_name name of button element - * @param string $button_class class of button element + * @param string $button_class class of button or image element * @param string $image_name name of image element * @param string $text text to display * @param string $image image to display @@ -2348,6 +2348,7 @@ class PMA_Util /* IE (before version 9) has trouble with