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 = '