Merge pull request #1662 from devenbansod/rfe1485

RFE #1485
This commit is contained in:
Isaac Bennetch 2015-05-11 09:55:58 -04:00
commit 697fd7825f
5 changed files with 94 additions and 3 deletions

View File

@ -61,6 +61,7 @@ $js_messages['strConfirmNavigation'] = __('You have unsaved changes; are you sur
$js_messages['strDropUserWarning'] = __('Do you really want to revoke the selected user(s) ?');
$js_messages['strDeleteCentralColumnWarning'] = __('Do you really want to delete this central column?');
$js_messages['strDropRTEitems'] = __('Do you really want to delete the selected items?');
$js_messages['strDropPartitionWarning'] = __('Do you really want to DROP the selected partition(s)? This will also DELETE the data related to the selected partition(s)!');
/* For modal dialog buttons */
$js_messages['strSaveAndClose'] = __('Save & Close');

View File

@ -5,6 +5,7 @@ AJAX.registerTeardown('tbl_operations.js', function () {
$(document).off('submit', "#copyTable.ajax");
$(document).off('submit', "#moveTableForm");
$(document).off('submit', "#tableOptionsForm");
$(document).off('submit', "#partitionsForm");
$(document).off('click', "#tbl_maintenance li a.maintain_action.ajax");
$(document).off('click', "#drop_tbl_anchor.ajax");
$(document).off('click', "#drop_view_anchor.ajax");
@ -140,6 +141,52 @@ AJAX.registerOnload('tbl_operations.js', function () {
}); // end $.post()
});//end of table maintenance ajax click
/**
* Ajax action for submitting the "Partition Maintenance"
* Also, asks for confirmation when DROP partition is submitted
*/
$(document).on('submit', "#partitionsForm", function (event) {
event.preventDefault();
var $form = $(this);
var db = $form.find('input[name=db]').val();
var tbl = $form.find('input[name=table]').val();
PMA_prepareForAjaxRequest($form);
var question = PMA_messages.strDropPartitionWarning;
var processingString = PMA_messages.strProcessingRequest;
if($('#partition_operation_DROP').is(':checked')) {
$(this).PMA_confirm(question, $form.attr('action'), function (url) {
$.post($form.attr('action'), $form.serialize(), function (data) {
if (typeof data !== 'undefined' && data.success === true) {
PMA_commonParams.set('db', db);
PMA_commonParams.set('table', tbl);
PMA_commonActions.refreshMain(false, function () {
$('#page_content').html(data.message);
PMA_highlightSQL($('#page_content'));
});
} else {
PMA_ajaxShowMessage(data.error, false);
}
});
});
}
else {
PMA_ajaxShowMessage(processingString);
$.post($form.attr('action'), $form.serialize(), function (data) {
if (typeof data !== 'undefined' && data.success === true) {
PMA_commonParams.set('db', db);
PMA_commonParams.set('table', tbl);
PMA_commonActions.refreshMain(false, function () {
$('#page_content').html(data.message);
PMA_highlightSQL($('#page_content'));
});
} else {
PMA_ajaxShowMessage(data.error, false);
}
});
}
});
$(document).on('click', "#drop_tbl_anchor.ajax", function (event) {
event.preventDefault();
/**

View File

@ -520,6 +520,11 @@ $GLOBALS['dummy_queries'] = array(
array(1),
)
),
array(
'query' => 'SELECT `PARTITION_METHOD` FROM `INFORMATION_SCHEMA`.`PARTITIONS` '
. 'WHERE `TABLE_SCHEMA` = "db" AND `TABLE_NAME` = "table"',
'result' => array()
),
);
/**
* Current database.

View File

@ -1261,6 +1261,35 @@ function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId)
. '</li>';
}
/**
* Adds COALESCE or DROP option to choices array depeding on Partition method used
*
* @param array $choices original common choices array
* @param string $db Database for the partition maintenance
* @param string $table Table for the partition maintenance
*
* @return array $choices new complete choices array
*/
function PMA_addOptionToDropOrCoalescePartition($choices, $db, $table)
{
$partition_method = $GLOBALS['dbi']->fetchResult(
'SELECT `PARTITION_METHOD` FROM `INFORMATION_SCHEMA`.`PARTITIONS` '
. 'WHERE `TABLE_SCHEMA` = "' . $db . '" '
. 'AND `TABLE_NAME` = "' . $table . '"'
);
if (! empty($partition_method)) {
if ($partition_method[0] == 'KEY' || $partition_method[0] == 'HASH') {
$choices['COALESCE'] = __('Coalesce');
}
else {
$choices['DROP'] = __('Drop');
}
}
return $choices;
}
/**
* Get HTML snippet for partition maintenance
*
@ -1279,8 +1308,11 @@ function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
'REPAIR' => __('Repair')
);
$choices = PMA_addOptionToDropOrCoalescePartition($choices, $GLOBALS['db'], $GLOBALS['table']);
$html_output = '<div class="operations_half_width">'
. '<form method="post" action="tbl_operations.php">'
. '<form id="partitionsForm" class="ajax" '
. 'method="post" action="tbl_operations.php" >'
. PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
. '<fieldset>'
. '<legend>'
@ -1587,8 +1619,13 @@ function PMA_getQueryAndResultForPartition()
$sql_query = 'ALTER TABLE '
. PMA_Util::backquote($GLOBALS['table']) . ' '
. $_REQUEST['partition_operation']
. ' PARTITION '
. implode(', ', $_REQUEST['partition_name']) . ';';
. ' PARTITION ';
if($_REQUEST['partition_operation'] == 'COALESCE')
$sql_query .= count($_REQUEST['partition_name']);
else
$sql_query .= implode(', ', $_REQUEST['partition_name']) . ';';
$result = $GLOBALS['dbi']->query($sql_query);
return array($sql_query, $result);

View File

@ -42,6 +42,7 @@ class PMA_Operations_Test extends PHPUnit_Framework_TestCase
'ServerDefault' => 1,
'ActionLinksMode' => 'icons',
);
$GLOBALS['cfg']['DBG']['sql'] = false;
$GLOBALS['server'] = 1;
}