diff --git a/ChangeLog b/ChangeLog index b41d3fc374..80aeaf92e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ phpMyAdmin - ChangeLog 4.4.0.0 (not yet released) + rfe #1553 InnoDB presently supports one FULLTEXT index creation at a time ++ rfe #1562 Allow tracking multiple table at once from database level tracking page 4.3.0.0 (not yet released) + rfe #1502 Smart sorting for int keys diff --git a/db_tracking.php b/db_tracking.php index 8cd1075c53..fee85d924e 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -17,7 +17,7 @@ require_once './libraries/tracking.lib.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); -$scripts->addFile('db_structure.js'); +$scripts->addFile('db_tracking.js'); /** * If we are not in an Ajax request, then do the common work and show the links etc. @@ -32,16 +32,51 @@ require 'libraries/db_info.inc.php'; // Work to do? // (here, do not use $_REQUEST['db] as it can be crafted) if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) { - PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']); - /** - * If in an Ajax request, generate the success message and use - * {@link PMA_Response()} to send the output - */ - if ($GLOBALS['is_ajax_request'] == true) { - $response = PMA_Response::getInstance(); - $response->addJSON('message', PMA_Message::success()); - exit; + PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']); + PMA_Message::success( + __('Tracking data deleted successfully.') + )->display(); + +} elseif (isset($_REQUEST['submit_create_version'])) { + + PMA_createTrackingForMultipleTables($_REQUEST['selected']); + PMA_Message::success( + sprintf( + __( + 'Version %1$s was created for selected tables,' + . ' tracking is active for them.' + ), + htmlspecialchars($_REQUEST['version']) + ) + )->display(); + +} elseif (isset($_REQUEST['submit_mult'])) { + + if (! empty($_REQUEST['selected_tbl'])) { + if ($_REQUEST['submit_mult'] == 'drop_tracking') { + + foreach ($_REQUEST['selected_tbl'] as $table) { + PMA_Tracker::deleteTracking($GLOBALS['db'], $table); + } + PMA_Message::success( + __('Tracking data deleted successfully.') + )->display(); + + } elseif ($_REQUEST['submit_mult'] == 'track') { + + echo PMA_getHtmlForDataDefinitionAndManipulationStatements( + 'db_tracking.php' . $url_query, + 0, + $GLOBALS['db'], + $_REQUEST['selected_tbl'] + ); + exit; + } + } else { + PMA_Message::notice( + __('No tables selected.') + )->display(); } } @@ -76,10 +111,15 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {

+
+ - + @@ -125,7 +165,10 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) { . '&delete_tracking=true&'; ?> - + @@ -157,6 +200,24 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) { ?>
+ +
+ '; + + echo '' + . ''; + + echo '' + . __('With selected:') . ''; + + echo PMA_Util::getButtonOrImage( + 'submit_mult', 'mult_submit', 'submit_mult_drop_tracking', + __('Drop'), 'b_drop.png', 'drop_tracking' + ); + ?> +
$value) { if (count($my_tables) > 0) { ?>

- +
+ - + + @@ -222,6 +288,10 @@ if (count($my_tables) > 0) { $my_link .= ''; ?> + @@ -237,6 +307,24 @@ if (count($my_tables) > 0) {
+ +
'; + + echo '' + . ''; + + echo '' + . __('With selected:') . ''; + + echo PMA_Util::getButtonOrImage( + 'submit_mult', 'mult_submit', 'submit_mult_track', + __('Track table'), 'eye.png', 'track' + ); + ?> +
+ 0) { diff --git a/js/db_structure.js b/js/db_structure.js index 7eee8d6db2..e5532ff23e 100644 --- a/js/db_structure.js +++ b/js/db_structure.js @@ -26,7 +26,6 @@ AJAX.registerTeardown('db_structure.js', function () { $('#fkc_checkbox').unbind('change'); $("a.truncate_table_anchor.ajax").die('click'); $("a.drop_table_anchor.ajax").die('click'); - $('a.drop_tracking_anchor.ajax').die('click'); $('#real_end_input').die('click'); $("a.favorite_table_anchor.ajax").die('click'); $('a.real_row_count').off('click'); @@ -369,90 +368,6 @@ AJAX.registerOnload('db_structure.js', function () { }); // end $.PMA_confirm() }); //end of Drop Table Ajax action - /** - * Ajax Event handler for 'Drop tracking' - */ - $('a.drop_tracking_anchor.ajax').live('click', function (event) { - event.preventDefault(); - - var $anchor = $(this); - - /** - * @var curr_tracking_row Object containing reference to the current tracked table's row - */ - var $curr_tracking_row = $anchor.parents('tr'); - /** - * @var question String containing the question to be asked for confirmation - */ - var question = PMA_messages.strDeleteTrackingData; - - $anchor.PMA_confirm(question, $anchor.attr('href'), function (url) { - - PMA_ajaxShowMessage(PMA_messages.strDeletingTrackingData); - - $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function (data) { - if (typeof data !== 'undefined' && data.success === true) { - var $tracked_table = $curr_tracking_row.parents('table'); - var table_name = $curr_tracking_row.find('td:nth-child(2)').text(); - - // Check how many rows will be left after we remove - if ($tracked_table.find('tbody tr').length === 1) { - // We are removing the only row it has - $('#tracked_tables').hide("slow").remove(); - } else { - // There are more rows left after the deletion - toggleRowColors($curr_tracking_row.next()); - $curr_tracking_row.hide("slow", function () { - $(this).remove(); - }); - } - - // Make the removed table visible in the list of 'Untracked tables'. - var $untracked_table = $('table#noversions'); - - // This won't work if no untracked tables are there. - if ($untracked_table.length > 0) { - var $rows = $untracked_table.find('tbody tr'); - - $rows.each(function (index) { - var $row = $(this); - var tmp_tbl_name = $row.find('td:first-child').text(); - var is_last_iteration = (index == ($rows.length - 1)); - - if (tmp_tbl_name > table_name || is_last_iteration) { - var $cloned = $row.clone(); - - // Change the table name of the cloned row. - $cloned.find('td:first-child').text(table_name); - - // Change the link of the cloned row. - var new_url = $cloned - .find('td:nth-child(2) a') - .attr('href') - .replace('table=' + tmp_tbl_name, 'table=' + encodeURIComponent(table_name)); - $cloned.find('td:nth-child(2) a').attr('href', new_url); - - // Insert the cloned row in an appropriate location. - if (tmp_tbl_name > table_name) { - $cloned.insertBefore($row); - toggleRowColors($row); - return false; - } else { - $cloned.insertAfter($row); - toggleRowColors($cloned); - } - } - }); - } - - PMA_ajaxShowMessage(data.message); - } else { - PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest + " : " + data.error, false); - } - }); // end $.get() - }); // end $.PMA_confirm() - }); //end Drop Tracking - //Calculate Real End for InnoDB /** * Ajax Event handler for calculating the real end for a InnoDB table diff --git a/js/db_tracking.js b/js/db_tracking.js new file mode 100644 index 0000000000..99e336e9ba --- /dev/null +++ b/js/db_tracking.js @@ -0,0 +1,60 @@ +/** + * Unbind all event handlers before tearing down the page + */ +AJAX.registerTeardown('db_tracking.js', function () { + $('body').off('click', '#trackedForm.ajax button[name="submit_mult"], #trackedForm.ajax input[name="submit_mult"]'); + $('body').off('click', '#untrackedForm.ajax button[name="submit_mult"], #untrackedForm.ajax input[name="submit_mult"]'); + $('body').off('click', 'a.drop_tracking_anchor.ajax'); +}); + +/** + * Bind event handlers + */ +AJAX.registerOnload('db_tracking.js', function () { + + /** + * Handles multi submit for tracked tables + */ + $('body').on('click', '#trackedForm.ajax button[name="submit_mult"], #trackedForm.ajax input[name="submit_mult"]', function (e) { + e.preventDefault(); + var $button = $(this); + var $form = $button.parent('form'); + var submitData = $form.serialize() + '&ajax_request=true&ajax_page_request=true&submit_mult=' + $button.val(); + + if ($button.val() == 'drop_tracking') { + var question = PMA_messages.strDeleteTrackingDataMultiple; + $button.PMA_confirm(question, $form.attr('action'), function (url) { + PMA_ajaxShowMessage(PMA_messages.strDeletingTrackingData); + $.get(url, submitData, AJAX.responseHandler); + }); + } else { + PMA_ajaxShowMessage(); + $.get($form.attr('action'), submitData, AJAX.responseHandler); + } + }); + + /** + * Handles multi submit for untracked tables + */ + $('body').on('click', '#untrackedForm.ajax button[name="submit_mult"], #untrackedForm.ajax input[name="submit_mult"]', function (e) { + e.preventDefault(); + var $button = $(this); + var $form = $button.parent('form'); + var submitData = $form.serialize() + '&ajax_request=true&ajax_page_request=true&submit_mult=' + $button.val(); + PMA_ajaxShowMessage(); + $.get($form.attr('action'), submitData, AJAX.responseHandler); + }); + + /** + * Ajax Event handler for 'Drop tracking' + */ + $('body').on('click', 'a.drop_tracking_anchor.ajax', function (e) { + e.preventDefault(); + var $anchor = $(this); + var question = PMA_messages.strDeleteTrackingData; + $anchor.PMA_confirm(question, $anchor.attr('href'), function (url) { + PMA_ajaxShowMessage(PMA_messages.strDeletingTrackingData); + $.get(url, {'ajax_page_request': true, 'ajax_request': true}, AJAX.responseHandler); + }); + }); +}); \ No newline at end of file diff --git a/js/messages.php b/js/messages.php index f8b011cad7..2dafbea285 100644 --- a/js/messages.php +++ b/js/messages.php @@ -37,7 +37,8 @@ $js_messages['strDoYouReally'] = __('Do you really want to execute "%s"?'); $js_messages['strDropDatabaseStrongWarning'] = __('You are about to DESTROY a complete database!'); $js_messages['strDropTableStrongWarning'] = __('You are about to DESTROY a complete table!'); $js_messages['strTruncateTableStrongWarning'] = __('You are about to TRUNCATE a complete table!'); -$js_messages['strDeleteTrackingData'] = __('Delete tracking data for this table'); +$js_messages['strDeleteTrackingData'] = __('Delete tracking data for this table?'); +$js_messages['strDeleteTrackingDataMultiple'] = __('Delete tracking data for these tables?'); $js_messages['strDeletingTrackingData'] = __('Deleting tracking data'); $js_messages['strDroppingPrimaryKeyIndex'] = __('Dropping Primary Key/Index'); $js_messages['strDroppingForeignKey'] = __('Dropping Foreign key.'); diff --git a/libraries/tracking.lib.php b/libraries/tracking.lib.php index 4bee5bccc6..72a19b7bf8 100644 --- a/libraries/tracking.lib.php +++ b/libraries/tracking.lib.php @@ -45,22 +45,33 @@ function PMA_filterTracking( * * @param string $url_query url query * @param int $last_version last version + * @param string $db database + * @param array $selected selected tables * * @return string */ function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query, - $last_version + $last_version, $db, $selected ) { - $html = '
'; - $html .= '
'; - $html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); + $html = '
'; + $html .= ''; + $html .= PMA_URL_getHiddenInputs($db); + foreach ($selected as $selected_table) { + $html .= ''; + } + $html .= '
'; $html .= ''; - $html .= sprintf( - __('Create version %1$s of %2$s'), - ($last_version + 1), - htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']) - ); + if (count($selected) == 1) { + $html .= sprintf( + __('Create version %1$s of %2$s'), + ($last_version + 1), + htmlspecialchars($db . '.' . $selected[0]) + ); + } else { + $html .= sprintf(__('Create version %1$s'), ($last_version + 1)); + } $html .= ''; $html .= ''; @@ -1235,6 +1246,26 @@ function PMA_createTrackingVersion() return $html; } +/** + * Create tracking version for multiple tables + * + * @param array $selected list of selected tables + */ +function PMA_createTrackingForMultipleTables($selected) +{ + $tracking_set = PMA_getTrackingSet(); + + foreach ($selected as $selected_table) { + PMA_Tracker::createVersion( + $GLOBALS['db'], + $selected_table, + $_REQUEST['version'], + $tracking_set, + PMA_Table::isView($GLOBALS['db'], $selected_table) + ); + } +} + /** * Function to get the entries * diff --git a/tbl_tracking.php b/tbl_tracking.php index b6b2e07590..43bd77213f 100644 --- a/tbl_tracking.php +++ b/tbl_tracking.php @@ -160,7 +160,10 @@ if ($last_version > 0) { } $html .= PMA_getHtmlForDataDefinitionAndManipulationStatements( - $url_query, $last_version + 'tbl_tracking.php' . $url_query, + $last_version, + $GLOBALS['db'], + array($GLOBALS['table']) ); $html .= '
'; diff --git a/test/libraries/PMA_tbl_tracking_test.php b/test/libraries/PMA_tbl_tracking_test.php index c5cbad1663..db5754e433 100644 --- a/test/libraries/PMA_tbl_tracking_test.php +++ b/test/libraries/PMA_tbl_tracking_test.php @@ -119,7 +119,7 @@ class PMA_TblTrackingTest extends PHPUnit_Framework_TestCase $url_query = "url_query"; $last_version = "10"; $html = PMA_getHtmlForDataDefinitionAndManipulationStatements( - $url_query, $last_version + $url_query, $last_version, $GLOBALS['db'], array($GLOBALS['table']) ); $this->assertContains( @@ -133,7 +133,7 @@ class PMA_TblTrackingTest extends PHPUnit_Framework_TestCase ); $this->assertContains( - PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']), + PMA_URL_getHiddenInputs($GLOBALS['db']), $html );