Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Okunuga <soloistic1@gmail.com>2022-10-01 01:33:36 +0300
committerGitHub <noreply@github.com>2022-10-01 01:33:36 +0300
commit0f9c79ebed13cef1430c32fb886e0681fcd270be (patch)
treed491a11a7e243af5e112e0ac85ed1487d2fd591e /libraries/classes
parentaac8f054f2a43d22974ab8808582e2fc4a476e4c (diff)
Issue #17727 Started refactoring uses of $db and $table (#17729)
* Issue #17727 Started refactoring uses of $db and $table to use the Objects - DatabaseName and TableName Changed uses related to Privileges Signed-off-by: Solomon Okunuga <soloistic1@gmail.com> * Apply suggestions from code review Co-authored-by: MaurĂ­cio Meneghini Fauth <mauricio@fauth.dev> Signed-off-by: Solomon Okunuga <soloistic1@gmail.com> Co-authored-by: MaurĂ­cio Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries/classes')
-rw-r--r--libraries/classes/Controllers/Database/PrivilegesController.php7
-rw-r--r--libraries/classes/Controllers/Table/PrivilegesController.php14
-rw-r--r--libraries/classes/Server/Privileges.php27
3 files changed, 22 insertions, 26 deletions
diff --git a/libraries/classes/Controllers/Database/PrivilegesController.php b/libraries/classes/Controllers/Database/PrivilegesController.php
index ae0ff11d0a..1c660b8123 100644
--- a/libraries/classes/Controllers/Database/PrivilegesController.php
+++ b/libraries/classes/Controllers/Database/PrivilegesController.php
@@ -10,6 +10,7 @@ namespace PhpMyAdmin\Controllers\Database;
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
@@ -97,9 +98,9 @@ class PrivilegesController extends AbstractController
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
- $db = $GLOBALS['db'];
+ $db = DatabaseName::fromValue($GLOBALS['db']);
if ($this->dbi->getLowerCaseNames() === '1') {
- $db = mb_strtolower($GLOBALS['db']);
+ $db = DatabaseName::fromValue(mb_strtolower($GLOBALS['db']));
}
$privileges = [];
@@ -109,7 +110,7 @@ class PrivilegesController extends AbstractController
$this->render('database/privileges/index', [
'is_superuser' => $this->dbi->isSuperUser(),
- 'db' => $db,
+ 'db' => $db->getName(),
'database_url' => $scriptName,
'text_dir' => $GLOBALS['text_dir'],
'is_createuser' => $this->dbi->isCreateUser(),
diff --git a/libraries/classes/Controllers/Table/PrivilegesController.php b/libraries/classes/Controllers/Table/PrivilegesController.php
index d3682a8445..abb82a78ba 100644
--- a/libraries/classes/Controllers/Table/PrivilegesController.php
+++ b/libraries/classes/Controllers/Table/PrivilegesController.php
@@ -10,6 +10,8 @@ namespace PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Dbal\DatabaseName;
+use PhpMyAdmin\Dbal\TableName;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
@@ -78,11 +80,11 @@ class PrivilegesController extends AbstractController
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
- $db = $GLOBALS['db'];
- $table = $GLOBALS['table'];
+ $db = DatabaseName::fromValue($GLOBALS['db']);
+ $table = TableName::fromValue($GLOBALS['table']);
if ($this->dbi->getLowerCaseNames() === '1') {
- $db = mb_strtolower($GLOBALS['db']);
- $table = mb_strtolower($GLOBALS['table']);
+ $db = DatabaseName::fromValue(mb_strtolower($GLOBALS['db']));
+ $table = TableName::fromValue(mb_strtolower($GLOBALS['table']));
}
$privileges = [];
@@ -91,8 +93,8 @@ class PrivilegesController extends AbstractController
}
$this->render('table/privileges/index', [
- 'db' => $db,
- 'table' => $table,
+ 'db' => $db->getName(),
+ 'table' => $table->getName(),
'is_superuser' => $this->dbi->isSuperUser(),
'table_url' => $scriptName,
'text_dir' => $GLOBALS['text_dir'],
diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php
index 5bec85a267..90b2442bc6 100644
--- a/libraries/classes/Server/Privileges.php
+++ b/libraries/classes/Server/Privileges.php
@@ -13,8 +13,10 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\DatabaseInterface;
+use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Dbal\MysqliResult;
use PhpMyAdmin\Dbal\ResultInterface;
+use PhpMyAdmin\Dbal\TableName;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Message;
@@ -1251,16 +1253,13 @@ class Privileges
}
/**
- * @param string $db database name
- * @param string $table table name
- *
* @return array
*/
- public function getAllPrivileges(string $db, string $table = ''): array
+ public function getAllPrivileges(DatabaseName $db, ?TableName $table = null): array
{
$databasePrivileges = $this->getGlobalAndDatabasePrivileges($db);
$tablePrivileges = [];
- if ($table !== '') {
+ if ($table !== null) {
$tablePrivileges = $this->getTablePrivileges($db, $table);
}
@@ -1322,11 +1321,9 @@ class Privileges
}
/**
- * @param string $db database name
- *
* @return array
*/
- private function getGlobalAndDatabasePrivileges(string $db): array
+ private function getGlobalAndDatabasePrivileges(DatabaseName $db): array
{
$listOfPrivileges = '`Select_priv`,
`Insert_priv`,
@@ -1376,7 +1373,8 @@ class Privileges
(
SELECT `User`, `Host`, ' . $listOfPrivileges . ' `Db`, \'d\' AS `Type`
FROM `mysql`.`db`
- WHERE \'' . $this->dbi->escapeString($db) . '\' LIKE `Db` AND NOT (' . $listOfComparedPrivileges . ')
+ WHERE \'' . $this->dbi->escapeString($db->getName()) . '\' LIKE `Db` AND NOT ('
+ . $listOfComparedPrivileges . ')
)
ORDER BY `User` ASC, `Host` ASC, `Db` ASC;
';
@@ -1386,12 +1384,9 @@ class Privileges
}
/**
- * @param string $db database name
- * @param string $table table name
- *
* @return array
*/
- private function getTablePrivileges(string $db, string $table): array
+ private function getTablePrivileges(DatabaseName $db, TableName $table): array
{
$query = '
SELECT `User`, `Host`, `Db`, \'t\' AS `Type`, `Table_name`, `Table_priv`
@@ -1414,16 +1409,14 @@ class Privileges
}
/**
- * @param string $db database name
- *
* @return array
*/
- private function getRoutinesPrivileges(string $db): array
+ private function getRoutinesPrivileges(DatabaseName $db): array
{
$query = '
SELECT *, \'r\' AS `Type`
FROM `mysql`.`procs_priv`
- WHERE Db = \'' . $this->dbi->escapeString($db) . '\';
+ WHERE Db = \'' . $this->dbi->escapeString($db->getName()) . '\';
';
$result = $this->dbi->query($query);