From d2f3c499f9489dd0654f24b683ccbb215cd4c352 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Fri, 30 Oct 2015 19:16:33 +1100 Subject: [PATCH] Move code related to approximate row counting to a separate method Signed-off-by: Madhura Jayaratne --- .../DatabaseStructureController.php | 82 +++++++++++-------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/libraries/controllers/DatabaseStructureController.php b/libraries/controllers/DatabaseStructureController.php index 2e69136cb8..62fe95eaf5 100644 --- a/libraries/controllers/DatabaseStructureController.php +++ b/libraries/controllers/DatabaseStructureController.php @@ -628,38 +628,9 @@ class DatabaseStructureController extends DatabaseController ); } - $show_superscript = ''; - // there is a null value in the ENGINE - // - when the table needs to be repaired, or - // - when it's a view - // so ensure that we'll display "in use" below for a table - // that needs to be repaired - $approx_rows = false; - if (isset($current_table['TABLE_ROWS']) - && ($current_table['ENGINE'] != null || $table_is_view) - ) { - // InnoDB table: we did not get an accurate row count - $approx_rows = !$table_is_view - && $current_table['ENGINE'] == 'InnoDB' - && !$current_table['COUNTED']; - - if ($table_is_view - && $current_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews'] - ) { - $approx_rows = true; - $show_superscript = Util::showHint( - PMA_sanitize( - sprintf( - __( - 'This view has at least this number of ' - . 'rows. Please refer to %sdocumentation%s.' - ), - '[doc@cfg_MaxExactCountViews]', '[/doc]' - ) - ) - ); - } - } + list($approx_rows, $show_superscript) = $this->isRowCountApproximated( + $current_table, $table_is_view + ); list($do, $ignored) = $this->getReplicationStatus($truename); @@ -750,6 +721,53 @@ class DatabaseStructureController extends DatabaseController $this->response->addHTML(''); //end of form } + /** + * Returns whether the row count is approximated + * + * @param array $current_table array containing details about the table + * @param boolean $table_is_view whether the table is a view + * + * @return array + */ + protected function isRowCountApproximated($current_table, $table_is_view) + { + $approx_rows = false; + $show_superscript = ''; + + // there is a null value in the ENGINE + // - when the table needs to be repaired, or + // - when it's a view + // so ensure that we'll display "in use" below for a table + // that needs to be repaired + if (isset($current_table['TABLE_ROWS']) + && ($current_table['ENGINE'] != null || $table_is_view) + ) { + // InnoDB table: we did not get an accurate row count + $approx_rows = !$table_is_view + && $current_table['ENGINE'] == 'InnoDB' + && !$current_table['COUNTED']; + + if ($table_is_view + && $current_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews'] + ) { + $approx_rows = true; + $show_superscript = Util::showHint( + PMA_sanitize( + sprintf( + __( + 'This view has at least this number of ' + . 'rows. Please refer to %sdocumentation%s.' + ), + '[doc@cfg_MaxExactCountViews]', '[/doc]' + ) + ) + ); + } + } + + return array($approx_rows, $show_superscript); + } + /** * Returns the replication status of the table. *