Merge pull request #1408 from madhuracj/tracking

Tracking improvements. Implements rfe #1562
This commit is contained in:
Marc Delisle 2014-11-25 12:46:56 -05:00
commit 9ca5ea653a
8 changed files with 211 additions and 112 deletions

View File

@ -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

View File

@ -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) {
<div id="tracked_tables">
<h3><?php echo __('Tracked tables');?></h3>
<form method="post" action="db_tracking.php" name="trackedForm"
id="trackedForm" class="ajax">
<?php
echo PMA_URL_getHiddenInputs($GLOBALS['db'])
?>
<table id="versions" class="data">
<thead>
<tr>
<th><?php echo __('Database');?></th>
<th></th>
<th><?php echo __('Table');?></th>
<th><?php echo __('Last version');?></th>
<th><?php echo __('Created');?></th>
@ -125,7 +165,10 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
. '&amp;delete_tracking=true&amp';
?>
<tr class="noclick <?php echo $style;?>">
<td><?php echo htmlspecialchars($version_data['db_name']);?></td>
<td class="center">
<input type="checkbox" name="selected_tbl[]" class="checkall"
value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
</td>
<td><?php echo htmlspecialchars($version_data['table_name']);?></td>
<td><?php echo $version_data['version'];?></td>
<td><?php echo $version_data['date_created'];?></td>
@ -157,6 +200,24 @@ if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) {
?>
</tbody>
</table>
<?php
echo '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
echo '<input type="checkbox" id="trackedForm_checkall" '
. 'class="checkall_box" title="' . __('Check All') . '" />'
. '<label for="trackedForm_checkall">' . __('Check All') . '</label>';
echo '<i style="margin-left: 2em">'
. __('With selected:') . '</i>';
echo PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_drop_tracking',
__('Drop'), 'b_drop.png', 'drop_tracking'
);
?>
</form>
</div>
<?php
}
@ -200,12 +261,17 @@ foreach ($table_list as $key => $value) {
if (count($my_tables) > 0) {
?>
<h3><?php echo __('Untracked tables');?></h3>
<form method="post" action="db_tracking.php" name="untrackedForm"
id="untrackedForm" class="ajax">
<?php
echo PMA_URL_getHiddenInputs($GLOBALS['db'])
?>
<table id="noversions" class="data">
<thead>
<tr>
<th style="width: 300px"><?php echo __('Table');?></th>
<th></th>
<th style="width: 300px"><?php echo __('Table');?></th>
<th><?php echo __('Action');?></th>
</tr>
</thead>
<tbody>
@ -222,6 +288,10 @@ if (count($my_tables) > 0) {
$my_link .= '</a>';
?>
<tr class="noclick <?php echo $style;?>">
<td class="center">
<input type="checkbox" name="selected_tbl[]" class="checkall"
value="<?php echo htmlspecialchars($tablename);?>"/>
</td>
<td><?php echo htmlspecialchars($tablename);?></td>
<td><?php echo $my_link;?></td>
</tr>
@ -237,6 +307,24 @@ if (count($my_tables) > 0) {
</tbody>
</table>
<?php
echo '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
echo '<input type="checkbox" id="untrackedForm_checkall" '
. 'class="checkall_box" title="' . __('Check All') . '" />'
. '<label for="untrackedForm_checkall">' . __('Check All') . '</label>';
echo '<i style="margin-left: 2em">'
. __('With selected:') . '</i>';
echo PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_track',
__('Track table'), 'eye.png', 'track'
);
?>
</form>
<?php
}
// If available print out database log
if (count($data['ddlog']) > 0) {

View File

@ -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

60
js/db_tracking.js Normal file
View File

@ -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);
});
});
});

View File

@ -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.');

View File

@ -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 = '<div id="div_create_version">';
$html .= '<form method="post" action="tbl_tracking.php' . $url_query . '">';
$html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$html = '<div id="div_create_version">';
$html .= '<form method="post" action="' . $url_query . '">';
$html .= PMA_URL_getHiddenInputs($db);
foreach ($selected as $selected_table) {
$html .= '<input type="hidden" name="selected[]"'
. ' value="' . htmlspecialchars($selected_table) . '" />';
}
$html .= '<fieldset>';
$html .= '<legend>';
$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 .= '</legend>';
$html .= '<input type="hidden" name="version" value="' . ($last_version + 1)
. '" />';
@ -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
*

View File

@ -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 .= '<br class="clearfloat"/>';

View File

@ -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
);