'
. PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table'])
. '
'
@@ -2274,7 +2274,7 @@ function PMA_displayHtmlForColumnChange($db, $table, $selected, $action)
$num_fields = count($fields_meta);
// set these globals because tbl_properties.inc.php verifies them
// @todo: refactor tbl_properties.inc.php so that it uses function params
- $GLOBALS['action'] = 'tbl_alter.php';
+ $GLOBALS['action'] = 'tbl_structure.php';
$GLOBALS['num_fields'] = $num_fields;
// Get more complete field information.
@@ -2451,4 +2451,98 @@ function PMA_updateColumns($db, $table)
return $regenerate;
}
+/**
+ * Moves columns in the table's structure based on $_REQUEST
+ *
+ * @param string $db database name
+ * @param string $table table name
+ */
+function PMA_moveColumns($db, $table)
+{
+ PMA_DBI_select_db($db);
+
+ /*
+ * load the definitions for all columns
+ */
+ $columns = PMA_DBI_get_columns_full($db, $table);
+ $column_names = array_keys($columns);
+ $changes = array();
+ $we_dont_change_keys = array();
+
+ // move columns from first to last
+ for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) {
+ $column = $_REQUEST['move_columns'][$i];
+ // is this column already correctly placed?
+ if ($column_names[$i] == $column) {
+ continue;
+ }
+
+ // it is not, let's move it to index $i
+ $data = $columns[$column];
+ $extracted_columnspec = PMA_Util::extractColumnSpec($data['Type']);
+ if (isset($data['Extra']) && $data['Extra'] == 'on update CURRENT_TIMESTAMP') {
+ $extracted_columnspec['attribute'] = $data['Extra'];
+ unset($data['Extra']);
+ }
+ $current_timestamp = false;
+ if ($data['Type'] == 'timestamp' && $data['Default'] == 'CURRENT_TIMESTAMP') {
+ $current_timestamp = true;
+ }
+ $default_type
+ = $data['Null'] === 'YES' && $data['Default'] === null
+ ? 'NULL'
+ : ($current_timestamp
+ ? 'CURRENT_TIMESTAMP'
+ : ($data['Default'] == ''
+ ? 'NONE'
+ : 'USER_DEFINED'));
+
+ $changes[] = 'CHANGE ' . PMA_Table::generateAlter(
+ $column,
+ $column,
+ strtoupper($extracted_columnspec['type']),
+ $extracted_columnspec['spec_in_brackets'],
+ $extracted_columnspec['attribute'],
+ isset($data['Collation']) ? $data['Collation'] : '',
+ $data['Null'] === 'YES' ? 'NULL' : 'NOT NULL',
+ $default_type,
+ $current_timestamp ? '' : $data['Default'],
+ isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra'] : false,
+ isset($data['Comments']) && $data['Comments'] !== ''
+ ? $data['Comments'] : false,
+ $we_dont_change_keys,
+ $i,
+ $i === 0 ? '-first' : $column_names[$i - 1]
+ );
+ // update current column_names array, first delete old position
+ for ($j = 0, $ll = count($column_names); $j < $ll; $j++) {
+ if ($column_names[$j] == $column) {
+ unset($column_names[$j]);
+ }
+ }
+ // insert moved column
+ array_splice($column_names, $i, 0, $column);
+ }
+ $response = PMA_Response::getInstance();
+ if (empty($changes)) { // should never happen
+ $response->isSuccess(false);
+ exit;
+ }
+ $move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
+ $move_query .= implode(', ', $changes);
+ // move columns
+ $result = PMA_DBI_try_query($move_query);
+ $tmp_error = PMA_DBI_getError();
+ if ($tmp_error) {
+ $response->isSuccess(false);
+ $response->addJSON('message', PMA_Message::error($tmp_error));
+ } else {
+ $message = PMA_Message::success(
+ __('The columns have been moved successfully.')
+ );
+ $response->addJSON('message', $message);
+ $response->addJSON('columns', $column_names);
+ }
+ exit;
+}
?>
diff --git a/tbl_alter.php b/tbl_alter.php
deleted file mode 100644
index 292b381ed8..0000000000
--- a/tbl_alter.php
+++ /dev/null
@@ -1,128 +0,0 @@
-isSuccess(false);
- exit;
- }
- $move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
- $move_query .= implode(', ', $changes);
- // move columns
- $result = PMA_DBI_try_query($move_query);
- $tmp_error = PMA_DBI_getError();
- if ($tmp_error) {
- $response->isSuccess(false);
- $response->addJSON('message', PMA_Message::error($tmp_error));
- } else {
- $message = PMA_Message::success(
- __('The columns have been moved successfully.')
- );
- $response->addJSON('message', $message);
- $response->addJSON('columns', $column_names);
- }
- exit;
-}
-?>
diff --git a/tbl_structure.php b/tbl_structure.php
index 63a77dedde..a9d6408487 100644
--- a/tbl_structure.php
+++ b/tbl_structure.php
@@ -24,6 +24,17 @@ $scripts = $header->getScripts();
$scripts->addFile('tbl_structure.js');
$scripts->addFile('indexes.js');
+/**
+ * Handle column moving
+ */
+if (isset($_REQUEST['move_columns'])
+ && is_array($_REQUEST['move_columns'])
+ && $response->isAjax()
+) {
+ PMA_moveColumns($db, $table);
+ exit;
+}
+
/**
* A click on Change has been made for one column
*/
diff --git a/test/libraries/core/PMA_checkPageValidity_test.php b/test/libraries/core/PMA_checkPageValidity_test.php
index 31b39a18df..5bf04ad39b 100644
--- a/test/libraries/core/PMA_checkPageValidity_test.php
+++ b/test/libraries/core/PMA_checkPageValidity_test.php
@@ -28,7 +28,6 @@ class PMA_checkPageValidity_test extends PHPUnit_Framework_TestCase
'server_binlog.php',
'server_variables.php',
'sql.php',
- 'tbl_alter.php',
'tbl_select.php',
'transformation_overview.php',
'transformation_wrapper.php',