From dce862d41b3cdbe91afc43ed6b3d0ff8b5127d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 22 May 2018 16:51:03 -0300 Subject: [PATCH] Remove dbi global from Controllers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Database/DatabaseStructureController.php | 2 +- .../Server/ServerCollationsController.php | 20 +++++++++------- .../Server/ServerDatabasesController.php | 24 +++++++++---------- .../Server/ServerVariablesController.php | 6 ++--- .../Table/TableChartController.php | 2 +- .../Table/TableIndexesController.php | 2 +- .../Table/TableRelationController.php | 2 +- .../Table/TableSearchController.php | 22 ++++++++--------- .../Table/TableStructureController.php | 10 ++++---- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/libraries/classes/Controllers/Database/DatabaseStructureController.php b/libraries/classes/Controllers/Database/DatabaseStructureController.php index a7be69c2d4..7016fa7f60 100644 --- a/libraries/classes/Controllers/Database/DatabaseStructureController.php +++ b/libraries/classes/Controllers/Database/DatabaseStructureController.php @@ -735,7 +735,7 @@ class DatabaseStructureController extends DatabaseController 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], 'db' => $GLOBALS['db'], 'properties_num_columns' => $GLOBALS['cfg']['PropertiesNumColumns'], - 'dbi' => $GLOBALS['dbi'], + 'dbi' => $this->dbi, 'show_charset' => $GLOBALS['cfg']['ShowDbStructureCharset'], 'show_comment' => $GLOBALS['cfg']['ShowDbStructureComment'], 'show_creation' => $GLOBALS['cfg']['ShowDbStructureCreation'], diff --git a/libraries/classes/Controllers/Server/ServerCollationsController.php b/libraries/classes/Controllers/Server/ServerCollationsController.php index 4ae7a0893a..b4a9ee3797 100644 --- a/libraries/classes/Controllers/Server/ServerCollationsController.php +++ b/libraries/classes/Controllers/Server/ServerCollationsController.php @@ -27,9 +27,8 @@ class ServerCollationsController extends Controller * * @return void */ - public function indexAction() + public function indexAction(): void { - $dbi = $GLOBALS['dbi']; $disableIs = $GLOBALS['cfg']['Server']['DisableIS']; /** @@ -44,10 +43,10 @@ class ServerCollationsController extends Controller ); $this->response->addHTML( $this->_getHtmlForCharsets( - Charsets::getMySQLCharsets($dbi, $disableIs), - Charsets::getMySQLCollations($dbi, $disableIs), - Charsets::getMySQLCharsetsDescriptions($dbi, $disableIs), - Charsets::getMySQLCollationsDefault($dbi, $disableIs) + Charsets::getMySQLCharsets($this->dbi, $disableIs), + Charsets::getMySQLCollations($this->dbi, $disableIs), + Charsets::getMySQLCharsetsDescriptions($this->dbi, $disableIs), + Charsets::getMySQLCollationsDefault($this->dbi, $disableIs) ) ); } @@ -62,9 +61,12 @@ class ServerCollationsController extends Controller * * @return string */ - function _getHtmlForCharsets(array $mysqlCharsets, array $mysqlCollations, - array $mysqlCharsetsDesc, array $mysqlDftCollations - ) { + function _getHtmlForCharsets( + array $mysqlCharsets, + array $mysqlCollations, + array $mysqlCharsetsDesc, + array $mysqlDftCollations + ): string { return Template::get('server/collations/charsets')->render( array( 'mysql_charsets' => $mysqlCharsets, diff --git a/libraries/classes/Controllers/Server/ServerDatabasesController.php b/libraries/classes/Controllers/Server/ServerDatabasesController.php index 8c8829d879..3fe1ccf2d9 100644 --- a/libraries/classes/Controllers/Server/ServerDatabasesController.php +++ b/libraries/classes/Controllers/Server/ServerDatabasesController.php @@ -1,6 +1,5 @@ isAjax() - && ($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) + && ($this->dbi->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) ) { $this->dropDatabasesAction(); return; @@ -112,9 +110,9 @@ class ServerDatabasesController extends Controller 'is_create_db_priv' => $GLOBALS['is_create_db_priv'], 'dbstats' => $this->_dbstats, 'db_to_create' => $GLOBALS['db_to_create'], - 'server_collation' => $GLOBALS['dbi']->getServerCollation(), + 'server_collation' => $this->dbi->getServerCollation(), 'databases' => isset($databases) ? $databases : null, - 'dbi' => $GLOBALS['dbi'], + 'dbi' => $this->dbi, 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'], ])); } @@ -133,11 +131,11 @@ class ServerDatabasesController extends Controller if (! empty($_POST['db_collation'])) { list($db_charset) = explode('_', $_POST['db_collation']); $charsets = Charsets::getMySQLCharsets( - $GLOBALS['dbi'], + $this->dbi, $GLOBALS['cfg']['Server']['DisableIS'] ); $collations = Charsets::getMySQLCollations( - $GLOBALS['dbi'], + $this->dbi, $GLOBALS['cfg']['Server']['DisableIS'] ); if (in_array($db_charset, $charsets) @@ -149,13 +147,13 @@ class ServerDatabasesController extends Controller } $sql_query .= ';'; - $result = $GLOBALS['dbi']->tryQuery($sql_query); + $result = $this->dbi->tryQuery($sql_query); if (! $result) { // avoid displaying the not-created db name in header or navi panel $GLOBALS['db'] = ''; - $message = Message::rawError($GLOBALS['dbi']->getError()); + $message = Message::rawError($this->dbi->getError()); $this->response->setRequestStatus(false); $this->response->addJSON('message', $message); } else { @@ -293,7 +291,7 @@ class ServerDatabasesController extends Controller 'first_database' => $first_database, 'master_replication' => $GLOBALS['replication_info']['master']['status'], 'slave_replication' => $GLOBALS['replication_info']['slave']['status'], - 'is_superuser' => $GLOBALS['dbi']->isSuperuser(), + 'is_superuser' => $this->dbi->isSuperuser(), 'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'], ]); @@ -305,7 +303,7 @@ class ServerDatabasesController extends Controller 'master_replication' => $GLOBALS['replication_info']['master']['status'], 'slave_replication' => $GLOBALS['replication_info']['slave']['status'], 'database_count' => $this->_database_count, - 'is_superuser' => $GLOBALS['dbi']->isSuperuser(), + 'is_superuser' => $this->dbi->isSuperuser(), 'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'], 'pma_theme_image' => $GLOBALS['pmaThemeImage'], 'text_dir' => $GLOBALS['text_dir'], @@ -456,9 +454,9 @@ class ServerDatabasesController extends Controller 'master_replication' => $master_replication, 'slave_replication_status' => $GLOBALS['replication_info']['slave']['status'], 'slave_replication' => $slave_replication, - 'is_superuser' => $GLOBALS['dbi']->isSuperuser(), + 'is_superuser' => $this->dbi->isSuperuser(), 'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'], - 'is_system_schema' => $GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true), + 'is_system_schema' => $this->dbi->isSystemSchema($current['SCHEMA_NAME'], true), 'default_tab_database' => $GLOBALS['cfg']['DefaultTabDatabase'], ]); } diff --git a/libraries/classes/Controllers/Server/ServerVariablesController.php b/libraries/classes/Controllers/Server/ServerVariablesController.php index 6be5ff9803..e7b4fec1bf 100644 --- a/libraries/classes/Controllers/Server/ServerVariablesController.php +++ b/libraries/classes/Controllers/Server/ServerVariablesController.php @@ -144,7 +144,7 @@ class ServerVariablesController extends Controller // when server is running in ANSI_QUOTES sql_mode $varValue = $this->dbi->fetchSingleRow( 'SHOW GLOBAL VARIABLES WHERE Variable_name=\'' - . $GLOBALS['dbi']->escapeString($_REQUEST['varName']) . '\';', + . $this->dbi->escapeString($_REQUEST['varName']) . '\';', 'NUM' ); @@ -196,7 +196,7 @@ class ServerVariablesController extends Controller $exp[mb_strtolower($matches[3])] ); } else { - $value = $GLOBALS['dbi']->escapeString($value); + $value = $this->dbi->escapeString($value); } if (! is_numeric($value)) { @@ -211,7 +211,7 @@ class ServerVariablesController extends Controller // Some values are rounded down etc. $varValue = $this->dbi->fetchSingleRow( 'SHOW GLOBAL VARIABLES WHERE Variable_name="' - . $GLOBALS['dbi']->escapeString($_REQUEST['varName']) + . $this->dbi->escapeString($_REQUEST['varName']) . '";', 'NUM' ); list($formattedValue, $isHtmlFormatted) = $this->_formatVariable( diff --git a/libraries/classes/Controllers/Table/TableChartController.php b/libraries/classes/Controllers/Table/TableChartController.php index 69d79d36e3..fba2f40b24 100644 --- a/libraries/classes/Controllers/Table/TableChartController.php +++ b/libraries/classes/Controllers/Table/TableChartController.php @@ -126,7 +126,7 @@ class TableChartController extends TableController ); $url_params['back'] = 'tbl_sql.php'; include 'libraries/tbl_common.inc.php'; - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $this->dbi->selectDb($GLOBALS['db']); } elseif (strlen($this->db) > 0) { $url_params['goto'] = Util::getScriptNameForOption( $this->cfg['DefaultTabDatabase'], 'database' diff --git a/libraries/classes/Controllers/Table/TableIndexesController.php b/libraries/classes/Controllers/Table/TableIndexesController.php index ef996c5598..a968622739 100644 --- a/libraries/classes/Controllers/Table/TableIndexesController.php +++ b/libraries/classes/Controllers/Table/TableIndexesController.php @@ -71,7 +71,7 @@ class TableIndexesController extends TableController */ public function displayFormAction() { - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $this->dbi->selectDb($GLOBALS['db']); $add_fields = 0; if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) { // coming already from form diff --git a/libraries/classes/Controllers/Table/TableRelationController.php b/libraries/classes/Controllers/Table/TableRelationController.php index 3c668b24a0..d361edf7d7 100644 --- a/libraries/classes/Controllers/Table/TableRelationController.php +++ b/libraries/classes/Controllers/Table/TableRelationController.php @@ -210,7 +210,7 @@ class TableRelationController extends TableController 'save_row' => array_values($columns), 'url_params' => $GLOBALS['url_params'], 'databases' => $GLOBALS['dblist']->databases, - 'dbi' => $GLOBALS['dbi'], + 'dbi' => $this->dbi, ]) ); diff --git a/libraries/classes/Controllers/Table/TableSearchController.php b/libraries/classes/Controllers/Table/TableSearchController.php index c0036cb5f0..2174cb3a3f 100644 --- a/libraries/classes/Controllers/Table/TableSearchController.php +++ b/libraries/classes/Controllers/Table/TableSearchController.php @@ -532,7 +532,7 @@ class TableSearchController extends TableController 'data_label' => $dataLabel, 'criteria_column_names' => isset($_POST['criteriaColumnNames']) ? $_POST['criteriaColumnNames'] : null, 'criteria_column_types' => isset($_POST['criteriaColumnTypes']) ? $_POST['criteriaColumnTypes'] : null, - 'sql_types' => $GLOBALS['dbi']->types, + 'sql_types' => $this->dbi->types, 'max_rows' => intval($GLOBALS['cfg']['MaxRows']), 'max_plot_limit' => ((! empty($_POST['maxPlotLimit'])) ? intval($_POST['maxPlotLimit']) @@ -668,7 +668,7 @@ class TableSearchController extends TableController . " FROM " . Util::backquote($this->db) . "." . Util::backquote($this->table) . " WHERE " . Util::backquote($column) - . " RLIKE '" . $GLOBALS['dbi']->escapeString($find) . "' COLLATE " + . " RLIKE '" . $this->dbi->escapeString($find) . "' COLLATE " . $charSet . "_bin"; // here we // change the collation of the 2nd operand to a case sensitive // binary collation to make sure that the comparison is case sensitive @@ -726,13 +726,13 @@ class TableSearchController extends TableController if (is_array($toReplace)) { foreach ($toReplace as $row) { $sql_query .= "\n WHEN " . Util::backquote($column) - . " = '" . $GLOBALS['dbi']->escapeString($row[0]) - . "' THEN '" . $GLOBALS['dbi']->escapeString($row[1]) . "'"; + . " = '" . $this->dbi->escapeString($row[0]) + . "' THEN '" . $this->dbi->escapeString($row[1]) . "'"; } } $sql_query .= " END" . " WHERE " . Util::backquote($column) - . " RLIKE '" . $GLOBALS['dbi']->escapeString($find) . "' COLLATE " + . " RLIKE '" . $this->dbi->escapeString($find) . "' COLLATE " . $charSet . "_bin"; // here we // change the collation of the 2nd operand to a case sensitive // binary collation to make sure that the comparison @@ -871,7 +871,7 @@ class TableSearchController extends TableController $type = $this->_columnTypes[$column_index]; $collation = $this->_columnCollations[$column_index]; //Gets column's comparison operators depending on column type - $typeOperators = $GLOBALS['dbi']->types->getTypeOperatorsHtml( + $typeOperators = $this->dbi->types->getTypeOperatorsHtml( preg_replace('@\(.*@s', '', $this->_columnTypes[$column_index]), $this->_columnNullFlags[$column_index], $selected_operator ); @@ -937,7 +937,7 @@ class TableSearchController extends TableController // else continue to form the where clause from column criteria values $fullWhereClause = array(); foreach ($_POST['criteriaColumnOperators'] as $column_index => $operator) { - $unaryFlag = $GLOBALS['dbi']->types->isUnaryOperator($operator); + $unaryFlag = $this->dbi->types->isUnaryOperator($operator); $tmp_geom_func = isset($_POST['geom_func'][$column_index]) ? $_POST['geom_func'][$column_index] : null; @@ -990,10 +990,10 @@ class TableSearchController extends TableController $parens_close = ''; } $enum_where = '\'' - . $GLOBALS['dbi']->escapeString($criteriaValues[0]) . '\''; + . $this->dbi->escapeString($criteriaValues[0]) . '\''; for ($e = 1; $e < $enum_selected_count; $e++) { $enum_where .= ', \'' - . $GLOBALS['dbi']->escapeString($criteriaValues[$e]) . '\''; + . $this->dbi->escapeString($criteriaValues[$e]) . '\''; } return ' ' . $func_type . ' ' . $parens_open @@ -1122,7 +1122,7 @@ class TableSearchController extends TableController && 'NOT BETWEEN' != $func_type ) { return $backquoted_name . ' ' . $func_type . ' ' . $quot - . $GLOBALS['dbi']->escapeString($criteriaValues) . $quot; + . $this->dbi->escapeString($criteriaValues) . $quot; } $func_type = str_replace(' (...)', '', $func_type); @@ -1141,7 +1141,7 @@ class TableSearchController extends TableController $value = 'NULL'; continue; } - $value = $quot . $GLOBALS['dbi']->escapeString(trim($value)) + $value = $quot . $this->dbi->escapeString(trim($value)) . $quot; } diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 59374cc9fe..bf9832bd8e 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -1218,7 +1218,7 @@ class TableStructureController extends TableController $mime_map = $this->transformations->getMime($this->db, $this->table, true); } } - $centralColumns = new CentralColumns($GLOBALS['dbi']); + $centralColumns = new CentralColumns($this->dbi); $central_list = $centralColumns->getFromTable( $this->db, $this->table @@ -1253,8 +1253,8 @@ class TableStructureController extends TableController FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='%s';", - $GLOBALS['dbi']->escapeString($this->db), - $GLOBALS['dbi']->escapeString($this->table) + $this->dbi->escapeString($this->db), + $this->dbi->escapeString($this->table) ) ); @@ -1334,7 +1334,7 @@ class TableStructureController extends TableController 'relation_commwork' => $GLOBALS['cfgRelation']['commwork'], 'relation_mimework' => $GLOBALS['cfgRelation']['mimework'], 'central_columns_work' => $GLOBALS['cfgRelation']['centralcolumnswork'], - 'mysql_int_version' => $GLOBALS['dbi']->getVersion(), + 'mysql_int_version' => $this->dbi->getVersion(), 'pma_theme_image' => $GLOBALS['pmaThemeImage'], 'text_dir' => $GLOBALS['text_dir'], 'is_active' => Tracker::isActive(), @@ -1478,7 +1478,7 @@ class TableStructureController extends TableController */ protected function getDataForSubmitMult($submit_mult, $selected, $action) { - $centralColumns = new CentralColumns($GLOBALS['dbi']); + $centralColumns = new CentralColumns($this->dbi); $what = null; $query_type = null; $is_unset_submit_mult = false;