From 3397300ee78abd77f81387438057953b61d585ab Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Wed, 25 Sep 2013 18:12:05 +0200 Subject: [PATCH 1/2] refactoring : cleanup code, wrap long lines --- libraries/rte/rte_routines.lib.php | 95 ++++++++++++++++++------------ 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index 11d839a9c5..21fd0a8a1c 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -276,7 +276,11 @@ function PMA_RTN_handleEditor() if (! count($errors)) { // set by PMA_RTN_getQueryFromRequest() // Execute the created query if (! empty($_REQUEST['editor_process_edit'])) { - if (! in_array($_REQUEST['item_original_type'], array('PROCEDURE', 'FUNCTION'))) { + $isProcOrFunc = in_array( + $_REQUEST['item_original_type'], + array('PROCEDURE', 'FUNCTION') + ); + if (!$isProcOrFunc) { $errors[] = sprintf( __('Invalid routine type: "%s"'), htmlspecialchars($_REQUEST['item_original_type']) @@ -325,7 +329,8 @@ function PMA_RTN_handleEditor() . __('The backed up query was:') . "\"" . htmlspecialchars($create_routine) . "\"" . '
' - . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); + . __('MySQL said: ') + . $GLOBALS['dbi']->getError(null); } } else { $message = PMA_Message::success( @@ -1094,7 +1099,7 @@ function PMA_RTN_getEditorForm($mode, $operation, $routine) */ function PMA_RTN_getQueryFromRequest() { - global $_REQUEST, $errors, $param_sqldataaccess, $param_directions; + global $_REQUEST, $errors, $param_sqldataaccess, $param_directions, $PMA_Types; $_REQUEST['item_type'] = isset($_REQUEST['item_type']) ? $_REQUEST['item_type'] : ''; @@ -1128,27 +1133,32 @@ function PMA_RTN_getQueryFromRequest() $warned_about_dir = false; $warned_about_name = false; $warned_about_length = false; - if ( ! empty($_REQUEST['item_param_name']) - && ! empty($_REQUEST['item_param_type']) - && ! empty($_REQUEST['item_param_length']) - && is_array($_REQUEST['item_param_name']) - && is_array($_REQUEST['item_param_type']) - && is_array($_REQUEST['item_param_length']) + + $item_param_name = $_REQUEST['item_param_name']; + $item_param_type = $_REQUEST['item_param_type']; + $item_param_length = $_REQUEST['item_param_length']; + + if ( ! empty($item_param_name) + && ! empty($item_param_type) + && ! empty($item_param_length) + && is_array($item_param_name) + && is_array($item_param_type) + && is_array($item_param_length) ) { - for ($i=0; $igetTypeClass($_REQUEST['item_param_type'][$i]) == 'CHAR') { + if ($PMA_Types->getTypeClass($item_param_type[$i]) == 'CHAR') { $params .= ' CHARSET ' . strtolower($_REQUEST['item_param_opts_text'][$i]); } } if (! empty($_REQUEST['item_param_opts_num'][$i])) { - if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_param_type'][$i]) == 'NUMBER') { + if ($PMA_Types->getTypeClass($item_param_type[$i]) == 'NUMBER') { $params .= ' ' . strtoupper($_REQUEST['item_param_opts_num'][$i]); } } - if ($i != count($_REQUEST['item_param_name'])-1) { + if ($i != (count($item_param_name) - 1)) { $params .= ", "; } } else if (! $warned_about_name) { @@ -1203,25 +1215,28 @@ function PMA_RTN_getQueryFromRequest() } $query .= "(" . $params . ") "; if ($_REQUEST['item_type'] == 'FUNCTION') { - if (! empty($_REQUEST['item_returntype']) + $item_returntype = $_REQUEST['item_returntype']; + + if (! empty($item_returntype) && in_array( - $_REQUEST['item_returntype'], PMA_Util::getSupportedDatatypes() + $item_returntype, PMA_Util::getSupportedDatatypes() ) ) { - $query .= "RETURNS {$_REQUEST['item_returntype']}"; + $query .= "RETURNS " . $item_returntype; } else { $errors[] = __('You must provide a valid return type for the routine.'); } if (! empty($_REQUEST['item_returnlength']) && !preg_match( - '@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i', - $_REQUEST['item_returntype'] + '@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|' + . 'MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i', + $item_returntype ) ) { $query .= "(" . $_REQUEST['item_returnlength'] . ")"; } else if (empty($_REQUEST['item_returnlength']) && preg_match( - '@^(ENUM|SET|VARCHAR|VARBINARY)$@i', $_REQUEST['item_returntype'] + '@^(ENUM|SET|VARCHAR|VARBINARY)$@i', $item_returntype ) ) { if (! $warned_about_length) { @@ -1233,13 +1248,13 @@ function PMA_RTN_getQueryFromRequest() } } if (! empty($_REQUEST['item_returnopts_text'])) { - if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_returntype']) == 'CHAR') { + if ($PMA_Types->getTypeClass($item_returntype) == 'CHAR') { $query .= ' CHARSET ' . strtolower($_REQUEST['item_returnopts_text']); } } if (! empty($_REQUEST['item_returnopts_num'])) { - if ($GLOBALS['PMA_Types']->getTypeClass($_REQUEST['item_returntype']) == 'NUMBER') { + if ($PMA_Types->getTypeClass($item_returntype) == 'NUMBER') { $query .= ' ' . strtoupper($_REQUEST['item_returnopts_num']); } } @@ -1382,7 +1397,8 @@ function PMA_RTN_handleExecute() if (($result !== false) && ($num_rows > 0)) { $output .= ""; - foreach ($GLOBALS['dbi']->getFieldsMeta($result) as $key => $field) { + foreach ($GLOBALS['dbi']->getFieldsMeta($result) + as $key => $field) { $output .= ""; @@ -1613,7 +1629,8 @@ function PMA_RTN_getExecuteForm($routine) 'Default' => '', 'first_timestamp' => false ); - $retval .= ""; $retval .= PMA_Util::getFunctionsForField($field, false); $retval .= ""; } @@ -1643,9 +1660,11 @@ function PMA_RTN_getExecuteForm($routine) PMA_Util::unquote($tokens[$j]['data']), ENT_QUOTES ); - $retval .= "" - . "{$tokens[$j]['data']}
\n"; + $retval .= "" + . $tokens[$j]['data'] . "
\n"; } } } else if (in_array( From 3a47225e843efcaa5de1b119d9310239cda77567 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Wed, 25 Sep 2013 19:48:30 +0200 Subject: [PATCH 2/2] first check if REQUEST var exists --- libraries/rte/rte_routines.lib.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index 21fd0a8a1c..12ce2fbece 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -1134,17 +1134,17 @@ function PMA_RTN_getQueryFromRequest() $warned_about_name = false; $warned_about_length = false; - $item_param_name = $_REQUEST['item_param_name']; - $item_param_type = $_REQUEST['item_param_type']; - $item_param_length = $_REQUEST['item_param_length']; - - if ( ! empty($item_param_name) - && ! empty($item_param_type) - && ! empty($item_param_length) - && is_array($item_param_name) - && is_array($item_param_type) - && is_array($item_param_length) + if ( ! empty($_REQUEST['item_param_name']) + && ! empty($_REQUEST['item_param_type']) + && ! empty($_REQUEST['item_param_length']) + && is_array($_REQUEST['item_param_name']) + && is_array($_REQUEST['item_param_type']) + && is_array($_REQUEST['item_param_length']) ) { + $item_param_name = $_REQUEST['item_param_name']; + $item_param_type = $_REQUEST['item_param_type']; + $item_param_length = $_REQUEST['item_param_length']; + for ($i=0; $i < count($item_param_name); $i++) { if (! empty($item_param_name[$i]) && ! empty($item_param_type[$i])
"; $output .= htmlspecialchars($field->name); $output .= "