Merge pull request #17855 from kamil-tekiela/globals-DBI
Reduce usage of $GLOBALS['dbi']
This commit is contained in:
commit
efbd8d835a
@ -166,7 +166,7 @@ class Designer
|
||||
. Util::backquote($databaseDesignerSettingsFeature->database) . '.'
|
||||
. Util::backquote($databaseDesignerSettingsFeature->designerSettings)
|
||||
. ' WHERE ' . Util::backquote('username') . ' = "'
|
||||
. $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user'])
|
||||
. $this->dbi->escapeString($GLOBALS['cfg']['Server']['user'])
|
||||
. '";';
|
||||
|
||||
$result = $this->dbi->fetchSingleRow($query);
|
||||
|
||||
@ -871,7 +871,7 @@ class Routines
|
||||
}
|
||||
|
||||
if (! empty($itemParamOpsText[$i])) {
|
||||
if ($GLOBALS['dbi']->types->getTypeClass($itemParamType[$i]) === 'CHAR') {
|
||||
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === 'CHAR') {
|
||||
if (! in_array($itemParamType[$i], ['VARBINARY', 'BINARY'])) {
|
||||
$params .= ' CHARSET '
|
||||
. mb_strtolower($itemParamOpsText[$i]);
|
||||
@ -880,7 +880,7 @@ class Routines
|
||||
}
|
||||
|
||||
if (! empty($itemParamOpsNum[$i])) {
|
||||
if ($GLOBALS['dbi']->types->getTypeClass($itemParamType[$i]) === 'NUMBER') {
|
||||
if ($this->dbi->types->getTypeClass($itemParamType[$i]) === 'NUMBER') {
|
||||
$params .= ' '
|
||||
. mb_strtoupper($itemParamOpsNum[$i]);
|
||||
}
|
||||
@ -937,14 +937,14 @@ class Routines
|
||||
}
|
||||
|
||||
if (! empty($_POST['item_returnopts_text'])) {
|
||||
if ($GLOBALS['dbi']->types->getTypeClass($itemReturnType) === 'CHAR') {
|
||||
if ($this->dbi->types->getTypeClass($itemReturnType) === 'CHAR') {
|
||||
$query .= ' CHARSET '
|
||||
. mb_strtolower($_POST['item_returnopts_text']);
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($_POST['item_returnopts_num'])) {
|
||||
if ($GLOBALS['dbi']->types->getTypeClass($itemReturnType) === 'NUMBER') {
|
||||
if ($this->dbi->types->getTypeClass($itemReturnType) === 'NUMBER') {
|
||||
$query .= ' '
|
||||
. mb_strtoupper($_POST['item_returnopts_num']);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ class Privileges
|
||||
*/
|
||||
public function __construct(
|
||||
Template $template,
|
||||
$dbi,
|
||||
DatabaseInterface $dbi,
|
||||
Relation $relation,
|
||||
RelationCleanup $relationCleanup,
|
||||
Plugins $plugins
|
||||
@ -870,9 +870,9 @@ class Privileges
|
||||
if (isset($username, $hostname) && $mode === 'change') {
|
||||
$row = $this->dbi->fetchSingleRow(
|
||||
'SELECT `plugin` FROM `mysql`.`user` WHERE `User` = "'
|
||||
. $GLOBALS['dbi']->escapeString($username)
|
||||
. $this->dbi->escapeString($username)
|
||||
. '" AND `Host` = "'
|
||||
. $GLOBALS['dbi']->escapeString($hostname)
|
||||
. $this->dbi->escapeString($hostname)
|
||||
. '" LIMIT 1'
|
||||
);
|
||||
// Table 'mysql'.'user' may not exist for some previous
|
||||
@ -885,9 +885,9 @@ class Privileges
|
||||
|
||||
$row = $this->dbi->fetchSingleRow(
|
||||
'SELECT `plugin` FROM `mysql`.`user` WHERE `User` = "'
|
||||
. $GLOBALS['dbi']->escapeString($username)
|
||||
. $this->dbi->escapeString($username)
|
||||
. '" AND `Host` = "'
|
||||
. $GLOBALS['dbi']->escapeString($hostname)
|
||||
. $this->dbi->escapeString($hostname)
|
||||
. '"'
|
||||
);
|
||||
if (is_array($row) && isset($row['plugin'])) {
|
||||
@ -1014,8 +1014,8 @@ class Privileges
|
||||
. " `authentication_string` = '" . $hashedPassword
|
||||
. "', `Password` = '', "
|
||||
. " `plugin` = '" . $authenticationPlugin . "'"
|
||||
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username)
|
||||
. "' AND Host = '" . $GLOBALS['dbi']->escapeString($hostname) . "';";
|
||||
. " WHERE `User` = '" . $this->dbi->escapeString($username)
|
||||
. "' AND Host = '" . $this->dbi->escapeString($hostname) . "';";
|
||||
} else {
|
||||
// USE 'SET PASSWORD ...' syntax for rest of the versions
|
||||
// Backup the old value, to be reset later
|
||||
@ -1023,8 +1023,8 @@ class Privileges
|
||||
$origValue = $row['@@old_passwords'];
|
||||
$updatePluginQuery = 'UPDATE `mysql`.`user` SET'
|
||||
. " `plugin` = '" . $authenticationPlugin . "'"
|
||||
. " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username)
|
||||
. "' AND Host = '" . $GLOBALS['dbi']->escapeString($hostname) . "';";
|
||||
. " WHERE `User` = '" . $this->dbi->escapeString($username)
|
||||
. "' AND Host = '" . $this->dbi->escapeString($hostname) . "';";
|
||||
|
||||
// Update the plugin for the user
|
||||
if (! $this->dbi->tryQuery($updatePluginQuery)) {
|
||||
|
||||
@ -8,6 +8,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\Status;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\ReplicationInfo;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
@ -63,6 +64,9 @@ class Data
|
||||
/** @var ReplicationInfo */
|
||||
private $replicationInfo;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
public function getReplicationInfo(): ReplicationInfo
|
||||
{
|
||||
return $this->replicationInfo;
|
||||
@ -350,15 +354,17 @@ class Data
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
public function __construct(DatabaseInterface $dbi)
|
||||
{
|
||||
$this->replicationInfo = new ReplicationInfo($GLOBALS['dbi']);
|
||||
$this->dbi = $dbi;
|
||||
|
||||
$this->replicationInfo = new ReplicationInfo($this->dbi);
|
||||
$this->replicationInfo->load($_POST['primary_connection'] ?? null);
|
||||
|
||||
$this->selfUrl = basename($GLOBALS['PMA_PHP_SELF']);
|
||||
|
||||
// get status from server
|
||||
$server_status_result = $GLOBALS['dbi']->tryQuery('SHOW GLOBAL STATUS');
|
||||
$server_status_result = $this->dbi->tryQuery('SHOW GLOBAL STATUS');
|
||||
if ($server_status_result === false) {
|
||||
$server_status = [];
|
||||
$this->dataLoaded = false;
|
||||
@ -369,7 +375,7 @@ class Data
|
||||
}
|
||||
|
||||
// for some calculations we require also some server settings
|
||||
$server_variables = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES', 0, 1);
|
||||
$server_variables = $this->dbi->fetchResult('SHOW GLOBAL VARIABLES', 0, 1);
|
||||
|
||||
// cleanup of some deprecated values
|
||||
$server_status = self::cleanDeprecated($server_status);
|
||||
|
||||
@ -31,12 +31,16 @@ class SqlQueryForm
|
||||
/** @var Template */
|
||||
private $template;
|
||||
|
||||
/** @var DatabaseInterface */
|
||||
private $dbi;
|
||||
|
||||
/**
|
||||
* @param Template $template Template object
|
||||
*/
|
||||
public function __construct(Template $template)
|
||||
public function __construct(Template $template, DatabaseInterface $dbi)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,14 +94,14 @@ class SqlQueryForm
|
||||
[$legend, $query, $columns_list] = $this->init($query);
|
||||
}
|
||||
|
||||
$relation = new Relation($GLOBALS['dbi']);
|
||||
$relation = new Relation($this->dbi);
|
||||
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
|
||||
|
||||
$bookmarks = [];
|
||||
if ($display_tab === 'full' && $bookmarkFeature !== null) {
|
||||
$bookmark_list = Bookmark::getList(
|
||||
$bookmarkFeature,
|
||||
$GLOBALS['dbi'],
|
||||
$this->dbi,
|
||||
$GLOBALS['cfg']['Server']['user'],
|
||||
$db
|
||||
);
|
||||
@ -173,7 +177,7 @@ class SqlQueryForm
|
||||
// Get the list and number of fields
|
||||
// we do a try_query here, because we could be in the query window,
|
||||
// trying to synchronize and the table has not yet been created
|
||||
$columns_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], true);
|
||||
$columns_list = $this->dbi->getColumns($db, $GLOBALS['table'], true);
|
||||
|
||||
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
|
||||
$tmp_tbl_link = '<a href="' . $scriptName . Url::getCommon(['db' => $db, 'table' => $table], '&') . '">';
|
||||
|
||||
@ -108,9 +108,7 @@ class SystemDatabase
|
||||
$dataRow['comment'],
|
||||
$dataRow['mimetype'],
|
||||
$dataRow['transformation'],
|
||||
$GLOBALS['dbi']->escapeString(
|
||||
$dataRow['transformation_options']
|
||||
)
|
||||
$this->dbi->escapeString($dataRow['transformation_options'])
|
||||
);
|
||||
|
||||
$addComma = true;
|
||||
|
||||
@ -197,10 +197,11 @@ return [
|
||||
],
|
||||
'sql_query_form' => [
|
||||
'class' => PhpMyAdmin\SqlQueryForm::class,
|
||||
'arguments' => ['$template' => '@template'],
|
||||
'arguments' => ['$template' => '@template', '$dbi' => '@dbi'],
|
||||
],
|
||||
'status_data' => [
|
||||
'class' => PhpMyAdmin\Server\Status\Data::class,
|
||||
'arguments' => ['@dbi'],
|
||||
],
|
||||
'status_monitor' => [
|
||||
'class' => PhpMyAdmin\Server\Status\Monitor::class,
|
||||
|
||||
@ -8005,6 +8005,11 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/SystemDatabase.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:escapeString\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/SystemDatabase.php
|
||||
|
||||
-
|
||||
message: "#^Cannot cast mixed to string\\.$#"
|
||||
count: 1
|
||||
|
||||
@ -42,7 +42,7 @@ class AdvisorControllerTest extends AbstractTestCase
|
||||
|
||||
$this->response = new ResponseRenderer();
|
||||
$this->template = new Template();
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($GLOBALS['dbi']);
|
||||
}
|
||||
|
||||
public function testIndexWithoutData(): void
|
||||
|
||||
@ -45,7 +45,7 @@ class GeneralLogControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testGeneralLog(): void
|
||||
|
||||
@ -45,7 +45,7 @@ class LogVarsControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testLogVars(): void
|
||||
|
||||
@ -44,7 +44,7 @@ class QueryAnalyzerControllerTest extends AbstractTestCase
|
||||
$dummyDbi = new DbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
|
||||
$controller = new QueryAnalyzerController($response, new Template(), new Data(), new Monitor($dbi), $dbi);
|
||||
$controller = new QueryAnalyzerController($response, new Template(), new Data($dbi), new Monitor($dbi), $dbi);
|
||||
|
||||
$_POST['database'] = 'database';
|
||||
$_POST['query'] = 'query';
|
||||
|
||||
@ -45,7 +45,7 @@ class SlowLogControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testSlowLog(): void
|
||||
|
||||
@ -46,7 +46,7 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
|
||||
@ -39,7 +39,7 @@ class RefreshControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($GLOBALS['dbi']);
|
||||
}
|
||||
|
||||
public function testRefresh(): void
|
||||
|
||||
@ -45,7 +45,7 @@ class ProcessesControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
|
||||
@ -49,7 +49,7 @@ class QueriesControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
$this->data->status['Uptime'] = 36000;
|
||||
$this->data->usedQueries = [
|
||||
'Com_change_db' => '15',
|
||||
|
||||
@ -46,7 +46,7 @@ class StatusControllerTest extends AbstractTestCase
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$data = new Data();
|
||||
$data = new Data($GLOBALS['dbi']);
|
||||
|
||||
$bytesReceived = 100;
|
||||
$bytesSent = 200;
|
||||
|
||||
@ -44,7 +44,7 @@ class VariablesControllerTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
$GLOBALS['cfg']['Server']['host'] = 'localhost';
|
||||
|
||||
$this->data = new Data();
|
||||
$this->data = new Data($this->dbi);
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
|
||||
@ -81,7 +81,9 @@ class SqlControllerTest extends AbstractTestCase
|
||||
]);
|
||||
|
||||
$response = new ResponseRenderer();
|
||||
(new SqlController($response, $template, new SqlQueryForm($template)))($this->createStub(ServerRequest::class));
|
||||
(
|
||||
new SqlController($response, $template, new SqlQueryForm($template, $this->dbi))
|
||||
)($this->createStub(ServerRequest::class));
|
||||
$this->assertSame($expected, $response->getHTMLResult());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ class TrackingControllerTest extends AbstractTestCase
|
||||
(new TrackingController(
|
||||
$response,
|
||||
$template,
|
||||
new Tracking(new SqlQueryForm($template), $template, new Relation($this->dbi), $this->dbi)
|
||||
new Tracking(new SqlQueryForm($template, $this->dbi), $template, new Relation($this->dbi), $this->dbi)
|
||||
))($this->createStub(ServerRequest::class));
|
||||
|
||||
$main = $template->render('table/tracking/main', [
|
||||
|
||||
@ -39,9 +39,28 @@ class SqlQueryFormTest extends AbstractTestCase
|
||||
parent::setUp();
|
||||
parent::setLanguage();
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW FULL COLUMNS FROM `PMA_db`.`PMA_table`',
|
||||
[
|
||||
[
|
||||
'field1',
|
||||
'Comment1',
|
||||
],
|
||||
],
|
||||
[
|
||||
'Field',
|
||||
'Comment',
|
||||
]
|
||||
);
|
||||
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW INDEXES FROM `PMA_db`.`PMA_table`',
|
||||
[]
|
||||
);
|
||||
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
|
||||
$GLOBALS['dbi'] = $this->dbi;
|
||||
$this->sqlQueryForm = new SqlQueryForm(new Template());
|
||||
$this->sqlQueryForm = new SqlQueryForm(new Template(), $this->dbi);
|
||||
|
||||
//$GLOBALS
|
||||
$GLOBALS['PMA_PHP_SELF'] = Core::getenv('PHP_SELF');
|
||||
@ -77,28 +96,6 @@ class SqlQueryFormTest extends AbstractTestCase
|
||||
$GLOBALS['cfg']['Server']['user'] = 'user';
|
||||
$GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
|
||||
$GLOBALS['cfg']['Server']['bookmarktable'] = 'bookmarktable';
|
||||
|
||||
$this->dummyDbi = $this->createDbiDummy();
|
||||
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
|
||||
$GLOBALS['dbi'] = $this->dbi;
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW FULL COLUMNS FROM `PMA_db`.`PMA_table`',
|
||||
[
|
||||
[
|
||||
'field1',
|
||||
'Comment1',
|
||||
],
|
||||
],
|
||||
[
|
||||
'Field',
|
||||
'Comment',
|
||||
]
|
||||
);
|
||||
|
||||
$this->dummyDbi->addResult(
|
||||
'SHOW INDEXES FROM `PMA_db`.`PMA_table`',
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,7 +27,6 @@ class SystemDatabaseTest extends AbstractTestCase
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$GLOBALS['dbi'] = $this->createDatabaseInterface();
|
||||
/**
|
||||
* SET these to avoid undefine d index error
|
||||
*/
|
||||
@ -44,6 +43,10 @@ class SystemDatabaseTest extends AbstractTestCase
|
||||
->method('tryQuery')
|
||||
->will($this->returnValue($resultStub));
|
||||
|
||||
$dbi->expects($this->any())
|
||||
->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$_SESSION['relation'] = [];
|
||||
$_SESSION['relation'][$GLOBALS['server']] = RelationParameters::fromArray([
|
||||
'table_coords' => 'table_name',
|
||||
|
||||
@ -51,7 +51,7 @@ class TrackingTest extends AbstractTestCase
|
||||
|
||||
$template = new Template();
|
||||
$this->tracking = new Tracking(
|
||||
new SqlQueryForm($template),
|
||||
new SqlQueryForm($template, $GLOBALS['dbi']),
|
||||
$template,
|
||||
new Relation($GLOBALS['dbi']),
|
||||
$GLOBALS['dbi']
|
||||
|
||||
Loading…
Reference in New Issue
Block a user