From 58ff71f57fd2c6838407f7152df515cc35e34d04 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 23 Feb 2014 18:47:18 +0100 Subject: [PATCH] Fix typos. Minor PHPDoc update. Minor refactoring. Signed-off-by: Hugues Peccatte --- libraries/DBQbe.class.php | 130 ++++++++++++++++++----------------- libraries/config.default.php | 2 +- 2 files changed, 69 insertions(+), 63 deletions(-) diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index ccaad0bd88..b70cd88ef6 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -143,7 +143,7 @@ class PMA_DbQbe */ private $_curCriteria; /** - * Current criteria AND/OR column realtions + * Current criteria AND/OR column relations * * @access private * @var array @@ -808,27 +808,29 @@ class PMA_DbQbe $column_index < $this->_criteria_column_count; $column_index++ ) { - if (! empty($this->_criteriaColumnInsert) + if (!empty($this->_criteriaColumnInsert) && isset($this->_criteriaColumnInsert[$column_index]) && $this->_criteriaColumnInsert[$column_index] == 'on' ) { - $or = 'Or' . $new_row_index . '[' . $new_column_count . ']'; + $orFieldName = 'Or' . $new_row_index . '[' . $new_column_count . ']'; $html_output .= ''; $html_output .= ''; $html_output .= ''; $new_column_count++; } // end if - if (! empty($this->_criteriaColumnDelete) + if (!empty($this->_criteriaColumnDelete) && isset($this->_criteriaColumnDelete[$column_index]) && $this->_criteriaColumnDelete[$column_index] == 'on' ) { continue; } - $or = 'Or' . $new_row_index; - if (! empty($_POST[$or]) && isset($_POST[$or][$column_index])) { - $tmp_or = $_POST[$or][$column_index]; + $orFieldName = 'Or' . $new_row_index; + if (!empty($_POST[$orFieldName]) + && isset($_POST[$orFieldName][$column_index]) + ) { + $tmp_or = $_POST[$orFieldName][$column_index]; } else { $tmp_or = ''; } @@ -838,8 +840,9 @@ class PMA_DbQbe . ' value="' . htmlspecialchars($tmp_or) . '" class="textfield"' . ' style="width: ' . $this->_realwidth . '" size="20" />'; $html_output .= ''; - if (! empty(${$or}) && isset(${$or}[$column_index])) { - $GLOBALS[${'cur' . $or}][$new_column_count] = ${$or}[$column_index]; + if (!empty(${$orFieldName}) && isset(${$orFieldName}[$column_index])) { + $GLOBALS[${'cur' . $orFieldName}][$new_column_count] + = ${$orFieldName}[$column_index]; } $new_column_count++; } // end for @@ -1121,7 +1124,6 @@ class PMA_DbQbe $where_clause_columns ) { $GLOBALS['dbi']->selectDb($this->_db); - $candidate_columns = array(); // Get unique columns and index columns $indexes = $this->_getIndexes( @@ -1149,24 +1151,26 @@ class PMA_DbQbe // good) as $candidate_columns we want to check if we have any 'Y' there // (that would mean that they were also found in the whereclauses // which would be great). if yes, we take only those - if ($needsort == 1) { - foreach ($candidate_columns as $column => $is_where) { - $table = explode('.', $column); - $table = $table[0]; - if ($is_where == 'Y') { - $vg[$column] = $table; - } else { - $sg[$column] = $table; - } - } - if (isset($vg)) { - $candidate_columns = $vg; - // Candidates restricted in index+where + if ($needsort != 1) { + return $candidate_columns; + } + + foreach ($candidate_columns as $column => $is_where) { + $table = explode('.', $column); + $table = $table[0]; + if ($is_where == 'Y') { + $vg[$column] = $table; } else { - $candidate_columns = $sg; - // None of the candidates where in a where-clause + $sg[$column] = $table; } } + if (isset($vg)) { + $candidate_columns = $vg; + // Candidates restricted in index+where + } else { + $candidate_columns = $sg; + // None of the candidates where in a where-clause + } return $candidate_columns; } @@ -1184,46 +1188,48 @@ class PMA_DbQbe private function _getMasterTable($all_tables, $all_columns, $where_clause_columns, $where_clause_tables ) { - $master = ''; if (count($where_clause_tables) == 1) { // If there is exactly one column that has a decent where-clause // we will just use this $master = key($where_clause_tables); - } else { - // Now let's find out which of the tables has an index - // (When the control user is the same as the normal user - // because he is using one of his databases as pmadb, - // the last db selected is not always the one where we need to work) - $candidate_columns = $this->_getLeftJoinColumnCandidates( - $all_tables, $all_columns, $where_clause_columns - ); - // If our array of candidates has more than one member we'll just - // find the smallest table. - // Of course the actual query would be faster if we check for - // the Criteria which gives the smallest result set in its table, - // but it would take too much time to check this - if (count($candidate_columns) > 1) { - // Of course we only want to check each table once - $checked_tables = $candidate_columns; - foreach ($candidate_columns as $table) { - if ($checked_tables[$table] != 1) { - $tsize[$table] = PMA_Table::countRecords( - $this->_db, - $table, - false - ); - $checked_tables[$table] = 1; - } - $csize[$table] = $tsize[$table]; - } - asort($csize); - reset($csize); - $master = key($csize); // Smallest - } else { - reset($candidate_columns); - $master = current($candidate_columns); // Only one single candidate + return $master; + } + + // Now let's find out which of the tables has an index + // (When the control user is the same as the normal user + // because he is using one of his databases as pmadb, + // the last db selected is not always the one where we need to work) + $candidate_columns = $this->_getLeftJoinColumnCandidates( + $all_tables, $all_columns, $where_clause_columns + ); + // If our array of candidates has more than one member we'll just + // find the smallest table. + // Of course the actual query would be faster if we check for + // the Criteria which gives the smallest result set in its table, + // but it would take too much time to check this + if (!(count($candidate_columns) > 1)) { + reset($candidate_columns); + $master = current($candidate_columns); // Only one single candidate + return $master; + } + + // Of course we only want to check each table once + $checked_tables = $candidate_columns; + foreach ($candidate_columns as $table) { + if ($checked_tables[$table] != 1) { + $tsize[$table] = PMA_Table::countRecords( + $this->_db, + $table, + false + ); + $checked_tables[$table] = 1; } - } // end if (exactly one where clause) + $csize[$table] = $tsize[$table]; + } + asort($csize); + reset($csize); + $master = key($csize); // Smallest + return $master; } @@ -1271,7 +1277,7 @@ class PMA_DbQbe * * @param string $cfgRelation Relation Settings * - * @return FROM clause + * @return string FROM clause */ private function _getFromClause($cfgRelation) { diff --git a/libraries/config.default.php b/libraries/config.default.php index a4694bf9e8..a01c677632 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -457,7 +457,7 @@ $cfg['Servers'][$i]['users'] = ''; $cfg['Servers'][$i]['usergroups'] = ''; /** - * table to store information about item hidden from navigation triee + * table to store information about item hidden from navigation tree * - leave blank to disable hide/show navigation items feature * SUGGESTED: 'pma__navigationhiding' *