Skip to content

Commit

Permalink
Merge pull request #17894 from MauricioFauth/dblist-global-removal
Browse files Browse the repository at this point in the history
Remove the `dblist` global variable
  • Loading branch information
MauricioFauth committed Nov 14, 2022
2 parents c08b4a7 + d0d9055 commit 40e44c0
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 266 deletions.
Expand Up @@ -13,8 +13,6 @@ final class CopyFormController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
$GLOBALS['dblist'] = $GLOBALS['dblist'] ?? null;

$selected = $_POST['selected_tbl'] ?? [];

if (empty($selected)) {
Expand All @@ -29,7 +27,7 @@ public function __invoke(ServerRequest $request): void
$urlParams['selected'][] = $selectedValue;
}

$databasesList = $GLOBALS['dblist']->databases;
$databasesList = $GLOBALS['dbi']->getDatabaseList();
foreach ($databasesList as $key => $databaseName) {
if ($databaseName == $GLOBALS['db']) {
$databasesList->offsetUnset($key);
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Controllers/DatabaseController.php
Expand Up @@ -10,7 +10,6 @@ final class DatabaseController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
$GLOBALS['dblist'] = $GLOBALS['dblist'] ?? null;
$this->response->addJSON(['databases' => $GLOBALS['dblist']->databases]);
$this->response->addJSON(['databases' => $GLOBALS['dbi']->getDatabaseList()]);
}
}
Expand Up @@ -48,7 +48,6 @@ public function __invoke(ServerRequest $request): void
{
$GLOBALS['selected'] = $GLOBALS['selected'] ?? null;
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
$GLOBALS['dblist'] = $GLOBALS['dblist'] ?? null;
$GLOBALS['reload'] = $GLOBALS['reload'] ?? null;

$selected_dbs = $_POST['selected_dbs'] ?? null;
Expand Down Expand Up @@ -90,7 +89,7 @@ public function __invoke(ServerRequest $request): void
$this->transformations->clear($database);
}

$GLOBALS['dblist']->databases->build();
$this->dbi->getDatabaseList()->build();

$message = Message::success(
_ngettext(
Expand Down
3 changes: 1 addition & 2 deletions libraries/classes/Controllers/Server/DatabasesController.php
Expand Up @@ -78,7 +78,6 @@ public function __construct(
public function __invoke(ServerRequest $request): void
{
$GLOBALS['server'] = $GLOBALS['server'] ?? null;
$GLOBALS['dblist'] = $GLOBALS['dblist'] ?? null;
$GLOBALS['is_create_db_priv'] = $GLOBALS['is_create_db_priv'] ?? null;
$GLOBALS['db_to_create'] = $GLOBALS['db_to_create'] ?? null;
$GLOBALS['text_dir'] = $GLOBALS['text_dir'] ?? null;
Expand Down Expand Up @@ -121,7 +120,7 @@ public function __invoke(ServerRequest $request): void
$this->position,
true
);
$this->databaseCount = count($GLOBALS['dblist']->databases);
$this->databaseCount = count($this->dbi->getDatabaseList());
}

$urlParams = [
Expand Down
5 changes: 3 additions & 2 deletions libraries/classes/Controllers/Table/OperationsController.php
Expand Up @@ -489,8 +489,9 @@ public function __invoke(ServerRequest $request): void
$possibleRowFormats = $this->operations->getPossibleRowFormat();

$databaseList = [];
if (count($GLOBALS['dblist']->databases) <= $GLOBALS['cfg']['MaxDbList']) {
$databaseList = $GLOBALS['dblist']->databases->getList();
$listDatabase = $this->dbi->getDatabaseList();
if (count($listDatabase) <= $GLOBALS['cfg']['MaxDbList']) {
$databaseList = $listDatabase->getList();
}

$hasForeignKeys = ! empty($this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign'));
Expand Down
6 changes: 3 additions & 3 deletions libraries/classes/Controllers/Table/RelationController.php
Expand Up @@ -179,7 +179,7 @@ public function __invoke(ServerRequest $request): void
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'url_params' => $GLOBALS['urlParams'],
'databases' => $GLOBALS['dblist']->databases,
'databases' => $this->dbi->getDatabaseList(),
'foreign_db' => $foreignDb,
'foreign_table' => $foreignTable,
'unique_columns' => $uniqueColumns,
Expand All @@ -198,7 +198,7 @@ public function __invoke(ServerRequest $request): void
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'url_params' => $GLOBALS['urlParams'],
'databases' => $GLOBALS['dblist']->databases,
'databases' => $this->dbi->getDatabaseList(),
'foreign_db' => false,
'foreign_table' => false,
'unique_columns' => [],
Expand All @@ -220,7 +220,7 @@ public function __invoke(ServerRequest $request): void
'column_hash_array' => $column_hash_array,
'save_row' => array_values($columns),
'url_params' => $GLOBALS['urlParams'],
'databases' => $GLOBALS['dblist']->databases,
'databases' => $this->dbi->getDatabaseList(),
'dbi' => $this->dbi,
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
'route' => $request->getRoute(),
Expand Down
48 changes: 0 additions & 48 deletions libraries/classes/Database/DatabaseList.php

This file was deleted.

31 changes: 18 additions & 13 deletions libraries/classes/DatabaseInterface.php
Expand Up @@ -9,7 +9,6 @@

use PhpMyAdmin\Config\Settings\Server;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Database\DatabaseList;
use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Dbal\DbalInterface;
use PhpMyAdmin\Dbal\DbiExtension;
Expand Down Expand Up @@ -141,6 +140,9 @@ class DatabaseInterface implements DbalInterface
/** @var float */
public $lastQueryExecutionTime = 0;

/** @var ListDatabase|null */
private $databaseList = null;

/**
* @param DbiExtension $ext Object to be used for database queries
*/
Expand Down Expand Up @@ -701,14 +703,14 @@ public function getDatabasesFull(
// f.e. to apply hide_db and only_db
$drops = array_diff(
array_keys($databases),
(array) $GLOBALS['dblist']->databases
(array) $this->getDatabaseList()
);
foreach ($drops as $drop) {
unset($databases[$drop]);
}
} else {
$databases = [];
foreach ($GLOBALS['dblist']->databases as $databaseName) {
foreach ($this->getDatabaseList() as $databaseName) {
// Compatibility with INFORMATION_SCHEMA output
$databases[$databaseName]['SCHEMA_NAME'] = $databaseName;

Expand Down Expand Up @@ -843,7 +845,7 @@ public function getColumnsFull(

$columns = [];
if ($database === null) {
foreach ($GLOBALS['dblist']->databases as $database) {
foreach ($this->getDatabaseList() as $database) {
$columns[$database] = $this->getColumnsFull($database, null, null, $link);
}

Expand Down Expand Up @@ -1145,10 +1147,7 @@ public function postConnect(): void
/* Loads closest context to this version. */
Context::loadClosest(($this->isMariaDb ? 'MariaDb' : 'MySql') . $this->versionInt);

/**
* the DatabaseList class as a stub for the ListDatabase class
*/
$GLOBALS['dblist'] = new DatabaseList();
$this->databaseList = null;
}

/**
Expand Down Expand Up @@ -1190,14 +1189,11 @@ public function setCollation(string $collation): void
public function postConnectControl(Relation $relation): void
{
// If Zero configuration mode enabled, check PMA tables in current db.
if ($GLOBALS['cfg']['ZeroConf'] != true) {
if (! $GLOBALS['cfg']['ZeroConf']) {
return;
}

/**
* the DatabaseList class as a stub for the ListDatabase class
*/
$GLOBALS['dblist'] = new DatabaseList();
$this->databaseList = null;

$relation->initRelationParamsCache();
}
Expand Down Expand Up @@ -2108,4 +2104,13 @@ public function prepare(string $query, $link = self::CONNECT_USER)
{
return $this->extension->prepare($this->links[$link], $query);
}

public function getDatabaseList(): ListDatabase
{
if ($this->databaseList === null) {
$this->databaseList = new ListDatabase();
}

return $this->databaseList;
}
}
2 changes: 1 addition & 1 deletion libraries/classes/Export.php
Expand Up @@ -594,7 +594,7 @@ public function exportServer(
}

// Walk over databases
foreach ($GLOBALS['dblist']->databases as $currentDb) {
foreach ($this->dbi->getDatabaseList() as $currentDb) {
if (! isset($tmpSelect) || ! mb_strpos(' ' . $tmpSelect, '|' . $currentDb . '|')) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Export/Options.php
Expand Up @@ -67,7 +67,7 @@ public function getDatabasesForSelectOptions($tmpSelect = '')
}

$databases = [];
foreach ($GLOBALS['dblist']->databases as $currentDb) {
foreach ($GLOBALS['dbi']->getDatabaseList() as $currentDb) {
if (Utilities::isSystemSchema($currentDb, true)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Operations.php
Expand Up @@ -122,7 +122,7 @@ public function createDbBeforeCopy(DatabaseName $newDatabaseName): void

// rebuild the database list because Table::moveCopy
// checks in this list if the target db exists
$GLOBALS['dblist']->databases->build();
$this->dbi->getDatabaseList()->build();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/ReplicationGui.php
Expand Up @@ -212,7 +212,7 @@ public function getHtmlForReplicaConfiguration(
public function getHtmlForReplicationDbMultibox(): string
{
$databases = [];
foreach ($GLOBALS['dblist']->databases as $database) {
foreach ($GLOBALS['dbi']->getDatabaseList() as $database) {
if (Utilities::isSystemSchema($database)) {
continue;
}
Expand Down
32 changes: 15 additions & 17 deletions libraries/classes/Server/Privileges.php
Expand Up @@ -1914,32 +1914,30 @@ public function getHtmlForAllTableSpecificRights(
$data['type'] = $type;

if ($type === 'database') {
$predDbArray = $GLOBALS['dblist']->databases;
$predDbArray = $this->dbi->getDatabaseList();
$databasesToSkip = [
'information_schema',
'performance_schema',
];

$databases = [];
$escapedDatabases = [];
if (! empty($predDbArray)) {
foreach ($predDbArray as $currentDb) {
if (in_array($currentDb, $databasesToSkip)) {
continue;
}

$currentDbEscaped = Util::escapeMysqlWildcards($currentDb);
// cannot use array_diff() once, outside of the loop,
// because the list of databases has special characters
// already escaped in $foundRows,
// contrary to the output of SHOW DATABASES
if (in_array($currentDbEscaped, $foundRows)) {
continue;
}
foreach ($predDbArray as $currentDb) {
if (in_array($currentDb, $databasesToSkip)) {
continue;
}

$databases[] = $currentDb;
$escapedDatabases[] = $currentDbEscaped;
$currentDbEscaped = Util::escapeMysqlWildcards($currentDb);
// cannot use array_diff() once, outside of the loop,
// because the list of databases has special characters
// already escaped in $foundRows,
// contrary to the output of SHOW DATABASES
if (in_array($currentDbEscaped, $foundRows)) {
continue;
}

$databases[] = $currentDb;
$escapedDatabases[] = $currentDbEscaped;
}

$data['databases'] = $databases;
Expand Down
9 changes: 5 additions & 4 deletions libraries/classes/Table.php
Expand Up @@ -984,8 +984,9 @@ public static function moveCopy(
$GLOBALS['asfile'] = 1;

// Ensuring the target database is valid.
if (! $GLOBALS['dblist']->databases->exists($sourceDb, $targetDb)) {
if (! $GLOBALS['dblist']->databases->exists($sourceDb)) {
$databaseList = $GLOBALS['dbi']->getDatabaseList();
if (! $databaseList->exists($sourceDb, $targetDb)) {
if (! $databaseList->exists($sourceDb)) {
$GLOBALS['message'] = Message::rawError(
sprintf(
__('Source database `%s` was not found!'),
Expand All @@ -994,7 +995,7 @@ public static function moveCopy(
);
}

if (! $GLOBALS['dblist']->databases->exists($targetDb)) {
if (! $databaseList->exists($targetDb)) {
$GLOBALS['message'] = Message::rawError(
sprintf(
__('Target database `%s` was not found!'),
Expand Down Expand Up @@ -1461,7 +1462,7 @@ public function rename($newName, $newDb = null): bool

if ($newDb !== null && $newDb !== $this->getDbName()) {
// Ensure the target is valid
if (! $GLOBALS['dblist']->databases->exists($newDb)) {
if (! $this->dbi->getDatabaseList()->exists($newDb)) {
$this->errors[] = __('Invalid database:') . ' ' . $newDb;

return false;
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -11165,11 +11165,6 @@ parameters:
count: 1
path: test/classes/TableTest.php

-
message: "#^Strict comparison using \\=\\=\\= between mixed and mixed will always evaluate to true\\.$#"
count: 1
path: test/classes/TableTest.php

-
message: "#^Method PhpMyAdmin\\\\Tests\\\\TemplateTest\\:\\:providerTestDynamicRender\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down

0 comments on commit 40e44c0

Please sign in to comment.