Refactor insert_edit functions to static methods

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2017-08-19 20:55:52 -03:00
parent 0e00c43379
commit 8a2dd938ef
5 changed files with 3291 additions and 3287 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
* @package PhpMyAdmin
*/
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\InsertEdit;
use PhpMyAdmin\Response;
use PhpMyAdmin\Util;
use PhpMyAdmin\Url;
@ -24,18 +25,13 @@ PageSettings::showGroup('Edit');
*/
require_once 'libraries/db_table_exists.inc.php';
/**
* functions implementation for this script
*/
require_once 'libraries/insert_edit.lib.php';
/**
* Determine whether Insert or Edit and set global variables
*/
list(
$insert_mode, $where_clause, $where_clause_array, $where_clauses,
$result, $rows, $found_unique_key, $after_insert
) = PMA_determineInsertOrEdit(
) = InsertEdit::determineInsertOrEdit(
isset($where_clause) ? $where_clause : null, $db, $table
);
// Increase number of rows if unsaved rows are more
@ -61,11 +57,11 @@ if (empty($GLOBALS['goto'])) {
}
$_url_params = PMA_getUrlParameters($db, $table);
$_url_params = InsertEdit::getUrlParameters($db, $table);
$err_url = $GLOBALS['goto'] . Url::getCommon($_url_params);
unset($_url_params);
$comments_map = PMA_getCommentsMap($db, $table);
$comments_map = InsertEdit::getCommentsMap($db, $table);
/**
* START REGULAR OUTPUT
@ -93,13 +89,13 @@ if (! empty($disp_message)) {
$response->addHTML(Util::getMessage($disp_message, null));
}
$table_columns = PMA_getTableColumns($db, $table);
$table_columns = InsertEdit::getTableColumns($db, $table);
// retrieve keys into foreign fields, if any
$foreigners = PMA_getForeigners($db, $table);
// Retrieve form parameters for insert/edit form
$_form_params = PMA_getFormParametersForInsertForm(
$_form_params = InsertEdit::getFormParametersForInsertForm(
$db, $table, $where_clauses, $where_clause_array, $err_url
);
@ -126,13 +122,13 @@ $biggest_max_file_size = 0;
$url_params['db'] = $db;
$url_params['table'] = $table;
$url_params = PMA_urlParamsInEditMode(
$url_params = InsertEdit::urlParamsInEditMode(
$url_params, $where_clause_array, $where_clause
);
$has_blob_field = false;
foreach ($table_columns as $column) {
if (PMA_isColumn(
if (InsertEdit::isColumn(
$column,
array('blob', 'tinyblob', 'mediumblob', 'longblob')
)) {
@ -143,7 +139,7 @@ foreach ($table_columns as $column) {
//Insert/Edit form
//If table has blob fields we have to disable ajax.
$html_output .= PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
$html_output .= InsertEdit::getHtmlForInsertEditFormHeader($has_blob_field, $is_upload);
$html_output .= Url::getHiddenInputs($_form_params);
@ -156,11 +152,11 @@ if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
}
if (! $cfg['ShowFunctionFields']) {
$html_output .= PMA_showTypeOrFunction('function', $url_params, false);
$html_output .= InsertEdit::showTypeOrFunction('function', $url_params, false);
}
if (! $cfg['ShowFieldTypesInDataEditView']) {
$html_output .= PMA_showTypeOrFunction('type', $url_params, false);
$html_output .= InsertEdit::showTypeOrFunction('type', $url_params, false);
}
$GLOBALS['plugin_scripts'] = array();
@ -182,10 +178,10 @@ foreach ($rows as $row_id => $current_row) {
$checked = false;
}
if ($insert_mode && $row_id > 0) {
$html_output .= PMA_getHtmlForIgnoreOption($row_id, $checked);
$html_output .= InsertEdit::getHtmlForIgnoreOption($row_id, $checked);
}
$html_output .= PMA_getHtmlForInsertEditRow(
$html_output .= InsertEdit::getHtmlForInsertEditRow(
$url_params, $table_columns, $comments_map, $timestamp_seen,
$current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode,
$current_row, $o_rows, $tabindex, $columns_cnt,
@ -202,7 +198,7 @@ if (! isset($after_insert)) {
}
//action panel
$html_output .= PMA_getActionsPanel(
$html_output .= InsertEdit::getActionsPanel(
$where_clause, $after_insert, $tabindex,
$tabindex_for_value, $found_unique_key
);
@ -215,12 +211,12 @@ if ($biggest_max_file_size > 0) {
}
$html_output .= '</form>';
$html_output .= PMA_getHtmlForGisEditor();
$html_output .= InsertEdit::getHtmlForGisEditor();
// end Insert/Edit form
if ($insert_mode) {
//Continue insertion form
$html_output .= PMA_getContinueInsertionForm(
$html_output .= InsertEdit::getContinueInsertionForm(
$table, $db, $where_clause_array, $err_url
);
}

View File

@ -13,6 +13,7 @@
*/
use PhpMyAdmin\Core;
use PhpMyAdmin\InsertEdit;
use PhpMyAdmin\Plugins\IOTransformationsPlugin;
use PhpMyAdmin\Response;
use PhpMyAdmin\Table;
@ -23,11 +24,6 @@ use PhpMyAdmin\Transformations;
*/
require_once 'libraries/common.inc.php';
/**
* functions implementation for this script
*/
require_once 'libraries/insert_edit.lib.php';
// Check parameters
PhpMyAdmin\Util::checkParameters(array('db', 'table', 'goto'));
@ -48,7 +44,7 @@ $scripts->addFile('indexes.js');
$scripts->addFile('gis_data_editor.js');
// check whether insert row mode, if so include tbl_change.php
PMA_isInsertRow();
InsertEdit::isInsertRow();
$after_insert_actions = array('new_insert', 'same_insert', 'edit_next');
if (isset($_REQUEST['after_insert'])
@ -60,22 +56,22 @@ if (isset($_REQUEST['after_insert'])
if ($_REQUEST['after_insert'] == 'same_insert') {
$url_params['where_clause'][] = $one_where_clause;
} elseif ($_REQUEST['after_insert'] == 'edit_next') {
PMA_setSessionForEditNext($one_where_clause);
InsertEdit::setSessionForEditNext($one_where_clause);
}
}
}
}
//get $goto_include for different cases
$goto_include = PMA_getGotoInclude($goto_include);
$goto_include = InsertEdit::getGotoInclude($goto_include);
// Defines the url to return in case of failure of the query
$err_url = PMA_getErrorUrl($url_params);
$err_url = InsertEdit::getErrorUrl($url_params);
/**
* Prepares the update/insert of a row
*/
list($loop_array, $using_key, $is_insert, $is_insertignore)
= PMA_getParamsForUpdateOrInsert();
= InsertEdit::getParamsForUpdateOrInsert();
$query = array();
$value_sets = array();
@ -252,7 +248,7 @@ foreach ($loop_array as $rownumber => $where_clause) {
// delete $file_to_insert temporary variable
$file_to_insert->cleanUp();
$current_value = PMA_getCurrentValueForDifferentTypes(
$current_value = InsertEdit::getCurrentValueForDifferentTypes(
$possibly_uploaded_val, $key, $multi_edit_columns_type,
$current_value, $multi_edit_auto_increment,
$rownumber, $multi_edit_columns_name, $multi_edit_columns_null,
@ -260,7 +256,7 @@ foreach ($loop_array as $rownumber => $where_clause) {
$using_key, $where_clause, $table, $multi_edit_funcs
);
$current_value_as_an_array = PMA_getCurrentValueAsAnArrayForMultipleEdit(
$current_value_as_an_array = InsertEdit::getCurrentValueAsAnArrayForMultipleEdit(
$multi_edit_funcs,
$multi_edit_salt, $gis_from_text_functions, $current_value,
$gis_from_wkb_functions, $func_optional_param, $func_no_param, $key
@ -268,7 +264,7 @@ foreach ($loop_array as $rownumber => $where_clause) {
if (! isset($multi_edit_virtual) || ! isset($multi_edit_virtual[$key])) {
list($query_values, $query_fields)
= PMA_getQueryValuesForInsertAndUpdateInMultipleEdit(
= InsertEdit::getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name, $multi_edit_columns_null,
$current_value, $multi_edit_columns_prev, $multi_edit_funcs,
$is_insert, $query_values, $query_fields,
@ -308,7 +304,7 @@ unset(
// Builds the sql query
if ($is_insert && count($value_sets) > 0) {
$query = PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets);
$query = InsertEdit::buildSqlQuery($is_insertignore, $query_fields, $value_sets);
} elseif (empty($query) && ! isset($_REQUEST['preview_sql']) && !$row_skipped) {
// No change -> move back to the calling script
//
@ -335,7 +331,7 @@ if (isset($_REQUEST['preview_sql'])) {
*/
list ($url_params, $total_affected_rows, $last_messages, $warning_messages,
$error_messages, $return_to_sql_query)
= PMA_executeSqlQuery($url_params, $query);
= InsertEdit::executeSqlQuery($url_params, $query);
if ($is_insert && (count($value_sets) > 0 || $row_skipped)) {
$message = PhpMyAdmin\Message::getMessageForInsertedRows(
@ -395,12 +391,12 @@ if ($response->isAjax() && ! isset($_POST['ajax_page_request'])) {
foreach ($relation_fields as $cell_index => $curr_rel_field) {
foreach ($curr_rel_field as $relation_field => $relation_field_value) {
$where_comparison = "='" . $relation_field_value . "'";
$dispval = PMA_getDisplayValueForForeignTableColumn(
$dispval = InsertEdit::getDisplayValueForForeignTableColumn(
$where_comparison, $map, $relation_field
);
$extra_data['relations'][$cell_index]
= PMA_getLinkForRelationalDisplayField(
= InsertEdit::getLinkForRelationalDisplayField(
$map, $relation_field, $where_comparison,
$dispval, $relation_field_value
);
@ -424,7 +420,7 @@ if ($response->isAjax() && ! isset($_POST['ajax_page_request'])) {
$column_name = $transformation['column_name'];
foreach ($transformation_types as $type) {
$file = Core::securePath($transformation[$type]);
$extra_data = PMA_transformEditedValues(
$extra_data = InsertEdit::transformEditedValues(
$db, $table, $transformation, $edited_values, $file,
$column_name, $extra_data, $type
);
@ -436,7 +432,7 @@ if ($response->isAjax() && ! isset($_POST['ajax_page_request'])) {
// without informing while saving
$column_name = $_REQUEST['fields_name']['multi_edit'][0][0];
PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData(
InsertEdit::verifyWhetherValueCanBeTruncatedAndAppendExtraData(
$db, $table, $column_name, $extra_data
);