From 60610f9b8322e027cc656171e2c97caeebcbd98f Mon Sep 17 00:00:00 2001 From: Ashutosh Dhundhara Date: Sun, 17 Aug 2014 01:10:14 +0530 Subject: [PATCH] Fix issues reported by Scrutinizer. Signed-off-by: Ashutosh Dhundhara --- db_structure.php | 2 +- js/functions.js | 106 +++++++++--------- js/tbl_change.js | 94 ++++++++-------- js/tbl_select.js | 5 +- js/tbl_structure.js | 18 +-- libraries/import.lib.php | 10 +- libraries/mult_submits.inc.php | 9 +- libraries/structure.lib.php | 5 +- libraries/tbl_columns_definition_form.inc.php | 4 +- libraries/tbl_columns_definition_form.lib.php | 6 +- libraries/tbl_relation.lib.php | 2 - sql.php | 2 +- tbl_relation.php | 2 +- test/libraries/PMA_import_test.php | 2 +- 14 files changed, 136 insertions(+), 131 deletions(-) diff --git a/db_structure.php b/db_structure.php index 7b6eedb6f4..4a17588eab 100644 --- a/db_structure.php +++ b/db_structure.php @@ -308,7 +308,7 @@ $response->addHTML( PMA_getHtmlBodyForTableSummary( $num_tables, $server_slave_status, $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all, - $update_time_all, $check_time_all, $approx_rows + $update_time_all, $check_time_all, isset($approx_rows) ? $approx_rows : false ) ); $response->addHTML(''); diff --git a/js/functions.js b/js/functions.js index ff9a321bba..4563933b27 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1878,6 +1878,56 @@ function PMA_ajaxRemoveMessage($this_msgbox) } } +/** + * Requests SQL for previewing before executing. + * + * @param jQuery Object $form Form containing query data + * + * @return void + */ +function PMA_previewSQL($form) +{ + var form_url = $form.attr('action'); + var form_data = $form.serialize() + + '&do_save_data=1' + + '&preview_sql=1' + + '&ajax_request=1'; + $.ajax({ + type: 'POST', + url: form_url, + data: form_data, + success: function (response) { + if (response.success) { + var $dialog_content = $('
') + .append(response.sql_data); + var button_options = {}; + button_options[PMA_messages.strClose] = function () { + $(this).dialog('close'); + }; + var $response_dialog = $dialog_content.dialog({ + minWidth: 550, + maxHeight: 400, + modal: true, + buttons: button_options, + title: PMA_messages.strPreviewSQL, + close: function () { + $(this).remove(); + }, + open: function () { + // Pretty SQL printing. + PMA_highlightSQL($(this)); + } + }); + } else { + PMA_ajaxShowMessage(response.message); + } + }, + error: function () { + PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest); + } + }); +} + // This event only need to be fired once after the initial page load $(function () { /** @@ -3658,16 +3708,14 @@ AJAX.registerOnload('functions.js', function () { cache: false, type: 'POST', data: { - favorite_tables: (window.localStorage.favorite_tables - !== undefined) + favorite_tables: (window.localStorage.favorite_tables !== undefined) ? window.localStorage.favorite_tables : '' }, success: function (data) { // Update localStorage. if (window.localStorage !== undefined) { - window.localStorage.favorite_tables - = data.favorite_tables; + window.localStorage.favorite_tables = data.favorite_tables; } $('#pma_favorite_list').html(data.list); } @@ -4411,56 +4459,6 @@ function checkNumberOfFields() { return true; } -/** - * Requests SQL for previewing before executing. - * - * @param jQuery Object $form Form containing query data - * - * @return void - */ -function PMA_previewSQL($form) -{ - var form_url = $form.attr('action'); - var form_data = $form.serialize() + - '&do_save_data=1' + - '&preview_sql=1' + - '&ajax_request=1'; - $.ajax({ - type: 'POST', - url: form_url, - data: form_data, - success: function (response) { - if (response.success) { - var $dialog_content = $('
') - .append(response.sql_data); - var button_options = {}; - button_options[PMA_messages.strClose] = function () { - $(this).dialog('close'); - }; - var $response_dialog = $dialog_content.dialog({ - minWidth: 550, - maxHeight: 400, - modal: true, - buttons: button_options, - title: PMA_messages.strPreviewSQL, - close: function () { - $(this).remove(); - }, - open: function () { - // Pretty SQL printing. - PMA_highlightSQL($(this)); - } - }); - } else { - PMA_ajaxShowMessage(response.message); - } - }, - error: function () { - PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest); - } - }); -} - /** * Ignore the displayed php errors. * Simply removes the displayed errors. diff --git a/js/tbl_change.js b/js/tbl_change.js index 3c70eba503..cc87711abe 100644 --- a/js/tbl_change.js +++ b/js/tbl_change.js @@ -270,6 +270,55 @@ function verificationsAfterFieldChange(urlField, multi_edit, theType) } /* End of fields validation*/ +/** + * Applies the selected function to all rows to be inserted. + * + * @param string currId Current ID of the row + * @param string functionName Name of the function + * @param bool copySalt Whether to copy salt or not + * @param string salt Salt value + * @param object targetRows Target rows + * + * @return void + */ +function applyFunctionToAllRows(currId, functionName, copySalt, salt, targetRows) +{ + targetRows.each(function () { + var currentRowNum = /\d/.exec($(this).find("input[name*='fields_name']").attr("name")); + + // Append the function select list. + var targetSelectList = $(this).find("select[name*='funcs[multi_edit]']"); + + if (targetSelectList.attr("id") === currId) { + return; + } + targetSelectList.find("option").filter(function () { + return $(this).text() === functionName; + }).attr("selected","selected"); + + // Handle salt field. + if (functionName === 'AES_ENCRYPT' || functionName === 'AES_DECRYPT') { + if ($("#salt_" + targetSelectList.attr("id")).length === 0) { + // Get hash value. + var hashed_value = targetSelectList.attr("name").match(/\[multi\_edit\]\[\d\]\[(.*)\]/); + //To generate the textbox that can take the salt + var new_salt_box = "
"; + targetSelectList.parent().next("td").next("td").find("input[name*='fields']").after(new_salt_box); + } + + if (copySalt) { + $("#salt_" + targetSelectList.attr("id")).attr("value", salt); + } + } else { + var id = targetSelectList.attr("id"); + if ($("#salt_" + id).length) { + $("#salt_" + id).remove(); + } + } + }); +} + /** * Unbind all event handlers before tearing down a page @@ -672,48 +721,3 @@ function changeValueFieldType(elem, searchIndex) $("#fieldID_" + searchIndex).removeAttr('multiple'); } } - -function applyFunctionToAllRows(currId, functionName, copySalt, salt, targetRows) -{ - targetRows.each(function () { - var currentRowNum = /\d/.exec($(this).find("input[name*='fields_name']").attr("name")); -/* // Ignore the rows whose insert_ignore_* checkbox is checked. - var insert_ignore = $(this).closest("table.insertRowTable").prevAll("input[name*='insert_ignore']"); - if (insert_ignore.length) { - if ($(insert_ignore).attr("checked")) { - return; - } - } */ - - // Append the function select list. - var targetSelectList = $(this).find("select[name*='funcs[multi_edit]']"); - - if (targetSelectList.attr("id") === currId) { - return; - } - targetSelectList.find("option").filter(function () { - return $(this).text() === functionName; - }).attr("selected","selected"); - - // Handle salt field. - if (functionName === 'AES_ENCRYPT' || functionName === 'AES_DECRYPT') { - if ($("#salt_" + targetSelectList.attr("id")).length === 0) { - // Get hash value. - var hashed_value = targetSelectList.attr("name").match(/\[multi\_edit\]\[\d\]\[(.*)\]/); - //To generate the textbox that can take the salt - var new_salt_box = "
"; - targetSelectList.parent().next("td").next("td").find("input[name*='fields']").after(new_salt_box); - } - - if (copySalt) { - $("#salt_" + targetSelectList.attr("id")).attr("value", salt); - } - } else { - var id = targetSelectList.attr("id"); - if ($("#salt_" + id).length) { - $("#salt_" + id).remove(); - } - } - }); -} diff --git a/js/tbl_select.js b/js/tbl_select.js index b954792323..474d1c114c 100644 --- a/js/tbl_select.js +++ b/js/tbl_select.js @@ -311,11 +311,10 @@ AJAX.registerOnload('tbl_select.js', function () { button_options[PMA_messages.strGo] = function () { var min_value = $('#min_value').val(); var max_value = $('#max_value').val(); + var final_value = ''; if (min_value.length && max_value.length) { - var final_value = min_value + ', ' + + final_value = min_value + ', ' + max_value; - } else { - final_value = ''; } var $target_field = $source_select.closest('tr') .find('[name*="criteriaValues"]'); diff --git a/js/tbl_structure.js b/js/tbl_structure.js index 0eb8747ef4..0d6f929c8d 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -268,9 +268,9 @@ AJAX.registerOnload('tbl_structure.js', function () { var question = $.sprintf(PMA_messages.strDoYouReally, 'ALTER TABLE `' + escapeHtml(curr_table_name) + '` ADD PRIMARY KEY(`' + escapeHtml(curr_column_name) + '`);'); $(this).PMA_confirm(question, $(this).attr('href'), function (url) { var $msg = PMA_ajaxShowMessage(PMA_messages.strAddingPrimaryKey, false); - $.get(url - , {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true} - , function (data) { + $.get(url, + {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true}, + function (data) { if (data.success === true) { PMA_ajaxRemoveMessage($msg); $(this).remove(); @@ -317,9 +317,9 @@ AJAX.registerOnload('tbl_structure.js', function () { var question = $.sprintf(PMA_messages.strDoYouReally, 'ALTER TABLE `' + escapeHtml(curr_table_name) + '` ADD INDEX(`' + escapeHtml(curr_column_name) + '`);'); $(this).PMA_confirm(question, $(this).attr('href'), function (url) { var $msg = PMA_ajaxShowMessage(PMA_messages.strAddingIndex, false); - $.get(url - , {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true} - , function (data) { + $.get(url, + {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true}, + function (data) { if (data.success === true) { PMA_ajaxRemoveMessage($msg); if ($('#result_query').length) { @@ -361,9 +361,9 @@ AJAX.registerOnload('tbl_structure.js', function () { var question = $.sprintf(PMA_messages.strDoYouReally, 'ALTER TABLE `' + escapeHtml(curr_table_name) + '` ADD UNIQUE(`' + escapeHtml(curr_column_name) + '`);'); $(this).PMA_confirm(question, $(this).attr('href'), function (url) { var $msg = PMA_ajaxShowMessage(PMA_messages.strAddingUnique, false); - $.get(url - , {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true} - , function (data) { + $.get(url, + {'is_js_confirmed' : 1, 'ajax_request' : true, 'index_change' : true}, + function (data) { if (data.success === true) { PMA_ajaxRemoveMessage($msg); if ($('#result_query').length) { diff --git a/libraries/import.lib.php b/libraries/import.lib.php index ffff715596..07be7759b5 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -1381,6 +1381,7 @@ function PMA_handleSimulateDMLRequest() // Only single-table queries accepted. $table_references = PMA_getTableReferences($analyzed_sql_results); + $table_references = $table_references ? $table_references : ''; if (preg_match('/JOIN/i', $table_references)) { $error = $error_msg; break; @@ -1393,7 +1394,7 @@ function PMA_handleSimulateDMLRequest() } // Get the matched rows for the query. - $result = PMA_getMatchedRows($sql_query, $analyzed_sql_results); + $result = PMA_getMatchedRows($analyzed_sql_results); if (! $error = $GLOBALS['dbi']->getError()) { $sql_data[] = $result; } else { @@ -1413,12 +1414,11 @@ function PMA_handleSimulateDMLRequest() /** * Find the matching rows for UPDATE/DELETE query. * - * @param string $query SQL query - * @param array $analyzed_sql_results Analyzed SQL results from parser. + * @param array $analyzed_sql_results Analyzed SQL results from parser. * * @return mixed */ -function PMA_getMatchedRows($query, $analyzed_sql_results = array()) +function PMA_getMatchedRows($analyzed_sql_results = array()) { // Get the query type. $query_type = (isset($analyzed_sql_results['analyzed_sql'][0]['querytype'])) @@ -1841,7 +1841,7 @@ function PMA_checkIfRollbackPossible($sql_query) // Get table_references from the query. $table_references = PMA_getTableReferences($analyzed_sql_results); - + $table_references = $table_references ? $table_references : ''; // Get table names from table_references. $tables = PMA_getTableNamesFromTableReferences($table_references); diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index a88cf39e61..531967dd09 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -84,7 +84,7 @@ if (! empty($submit_mult) exit; break; case 'show_create': - $show_create = PMA_getHtmlShowCreate($db, $selected); + $show_create = PMA_getHtmlShowCreate($GLOBALS['db'], $selected); // Send response to client. $response = PMA_Response::getInstance(); $response->addJSON('message', $show_create); @@ -99,7 +99,10 @@ if (! empty($submit_mult) break; case 'make_consistent_with_central_list': include_once 'libraries/central_columns.lib.php'; - $centralColsError = PMA_makeConsistentWithList($db, $selected); + $centralColsError = PMA_makeConsistentWithList( + $GLOBALS['db'], + $selected + ); break; } // end switch } @@ -112,7 +115,7 @@ if (! empty($submit_mult) $centralColsError ) = PMA_getDataForSubmitMult( - $submit_mult, $db, $table, + $submit_mult, $GLOBALS['db'], $table, $selected, $action ); //update the existing variables diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index 9e616e40a2..9e5add8f2c 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -180,6 +180,7 @@ function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status, $row_count_sum = PMA_Util::formatNumber($sum_entries, 0); // If a table shows approximate rows count, display update-all-real-count anchor. + $row_sum_url = array(); if (isset($approx_rows)) { $row_sum_url = array( 'ajax_request' => true, @@ -2824,8 +2825,8 @@ function PMA_checkFavoriteTable($db, $current_table) * Get HTML for favorite anchor. * * @param string $db current database - * @param string $current_table current table - * @param string $titles titles + * @param array $current_table current table + * @param array $titles titles * * @return string The html output */ diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 6c2ed0adc0..8a9d660bb6 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -162,8 +162,8 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { isset($submit_default_current_timestamp) ? $submit_default_current_timestamp : null, $comments_map, isset($fields_meta) ? $fields_meta : null, $is_backup, - isset($move_columns) ? $move_columns : null, $cfgRelation, - isset($available_mime) ? $available_mime : null, + isset($move_columns) ? $move_columns : array(), $cfgRelation, + isset($available_mime) ? $available_mime : array(), isset($mime_map) ? $mime_map : array() ); } // end for diff --git a/libraries/tbl_columns_definition_form.lib.php b/libraries/tbl_columns_definition_form.lib.php index 29113a3f68..3ce1c0f3a7 100644 --- a/libraries/tbl_columns_definition_form.lib.php +++ b/libraries/tbl_columns_definition_form.lib.php @@ -701,7 +701,9 @@ function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset, . '" size="1" name="field_mimetype[' . $columnNumber . ']">'; $html .= ' '; - if (is_array($available_mime['mimetype'])) { + if (isset($available_mime['mimetype']) + && is_array($available_mime['mimetype']) + ) { foreach ($available_mime['mimetype'] as $mimetype) { $checked = (isset($columnMeta['Field']) && isset($mime_map[$columnMeta['Field']]['mimetype']) @@ -743,7 +745,7 @@ function PMA_getHtmlForTransformation($columnNumber, $ci, $ci_offset, . '[' . $columnNumber . ']">'; $html .= ' '; - if (is_array($available_mime[$type])) { + if (isset($available_mime[$type]) && is_array($available_mime[$type])) { foreach ($available_mime[$type] as $mimekey => $transform) { $checked = isset($columnMeta['Field']) && isset($mime_map[$columnMeta['Field']][$type]) diff --git a/libraries/tbl_relation.lib.php b/libraries/tbl_relation.lib.php index 5ddf5174e4..6d3d710431 100644 --- a/libraries/tbl_relation.lib.php +++ b/libraries/tbl_relation.lib.php @@ -289,7 +289,6 @@ function PMA_getHtmlForInternalRelationRow($save_row, $i, $odd_row, $html_output .= ''; - $foreign_db = false; $foreign_table = false; $foreign_column = false; @@ -531,7 +530,6 @@ function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i, . ''; $html_output .= ''; $html_output .= ''; - $foreign_db = false; $foreign_table = false; $foreign_column = false; diff --git a/sql.php b/sql.php index 25141ef975..0630122f06 100644 --- a/sql.php +++ b/sql.php @@ -59,7 +59,7 @@ if (! empty($goto)) { if (! isset($err_url)) { $err_url = (! empty($back) ? $back : $goto) - . '?' . PMA_URL_getCommon($db) + . '?' . PMA_URL_getCommon($GLOBALS['db']) . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table)) ? '&table=' . urlencode($table) : '' diff --git a/tbl_relation.php b/tbl_relation.php index ebb9b4fef8..77aca0daee 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -153,7 +153,7 @@ $columns = $GLOBALS['dbi']->getColumns($db, $table); // common form $html_output .= PMA_getHtmlForCommonForm( $db, $table, $columns, $cfgRelation, $tbl_storage_engine, - isset($existrel) ? $existrel : null, + isset($existrel) ? $existrel : array(), isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null, $options_array ); diff --git a/test/libraries/PMA_import_test.php b/test/libraries/PMA_import_test.php index 6389674277..b053afc57e 100644 --- a/test/libraries/PMA_import_test.php +++ b/test/libraries/PMA_import_test.php @@ -418,7 +418,7 @@ class PMA_Import_Test extends PHPUnit_Framework_TestCase 'analyzed_sql' => $analyzed_sql ); - $simulated_data = PMA_getMatchedRows($sql_query, $analyzed_sql_results); + $simulated_data = PMA_getMatchedRows($analyzed_sql_results); // URL to matched rows. $_url_params = array(