From d00fe5cf6a25ae448f1dd1d0b183c624f29625cb Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Wed, 6 May 2015 18:48:05 +0530 Subject: [PATCH] RFE #1485 : Add a DROP/ COALESCE Partition option in Partition Maintenance Signed-off-by: Deven Bansod --- js/messages.php | 1 + js/tbl_operations.js | 47 ++++++++++++++++++++++++++ libraries/dbi/DBIDummy.class.php | 5 +++ libraries/operations.lib.php | 43 +++++++++++++++++++++-- test/libraries/PMA_operations_test.php | 1 + 5 files changed, 94 insertions(+), 3 deletions(-) diff --git a/js/messages.php b/js/messages.php index 0571b42a2a..8d796a46b2 100644 --- a/js/messages.php +++ b/js/messages.php @@ -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'); diff --git a/js/tbl_operations.js b/js/tbl_operations.js index 56e60162b9..85eebd8999 100644 --- a/js/tbl_operations.js +++ b/js/tbl_operations.js @@ -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(); /** diff --git a/libraries/dbi/DBIDummy.class.php b/libraries/dbi/DBIDummy.class.php index 69770d9134..cb69e3edaa 100644 --- a/libraries/dbi/DBIDummy.class.php +++ b/libraries/dbi/DBIDummy.class.php @@ -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. diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 466f24933d..bd0e33a3b7 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -1261,6 +1261,35 @@ function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId) . ''; } +/** + * 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 = '
' - . '
' + . '' . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']) . '
' . '' @@ -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); diff --git a/test/libraries/PMA_operations_test.php b/test/libraries/PMA_operations_test.php index b8e6bf07f4..bda31a4cf6 100644 --- a/test/libraries/PMA_operations_test.php +++ b/test/libraries/PMA_operations_test.php @@ -42,6 +42,7 @@ class PMA_Operations_Test extends PHPUnit_Framework_TestCase 'ServerDefault' => 1, 'ActionLinksMode' => 'icons', ); + $GLOBALS['cfg']['DBG']['sql'] = false; $GLOBALS['server'] = 1; }