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:
authorMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-10 05:29:26 +0300
committerMaurício Meneghini Fauth <mauricio@fauth.dev>2022-09-10 05:29:26 +0300
commit81192a142bbfde4f0795a6496c62ffc58dec5700 (patch)
tree254f1d5cbd6d7f90efb9d09aeeff930e0c8e84af /libraries
parent746d1696b703b626bddb1e33c76992078f8454da (diff)
Move DBI getRoutines method to the Routines class
DatabaseInterface::getRoutines -> Database\Routines::getDetails Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/classes/Controllers/Database/RoutinesController.php2
-rw-r--r--libraries/classes/Database/Routines.php73
-rw-r--r--libraries/classes/DatabaseInterface.php68
-rw-r--r--libraries/classes/Dbal/DbalInterface.php12
-rw-r--r--libraries/classes/Server/Privileges.php5
5 files changed, 76 insertions, 84 deletions
diff --git a/libraries/classes/Controllers/Database/RoutinesController.php b/libraries/classes/Controllers/Database/RoutinesController.php
index b75b6ace84..e827e5a6f1 100644
--- a/libraries/classes/Controllers/Database/RoutinesController.php
+++ b/libraries/classes/Controllers/Database/RoutinesController.php
@@ -113,7 +113,7 @@ class RoutinesController extends AbstractController
$type = null;
}
- $items = $this->dbi->getRoutines($GLOBALS['db'], $type);
+ $items = Routines::getDetails($this->dbi, $GLOBALS['db'], $type);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
$rows = '';
diff --git a/libraries/classes/Database/Routines.php b/libraries/classes/Database/Routines.php
index 31a116d7c0..729bcc1492 100644
--- a/libraries/classes/Database/Routines.php
+++ b/libraries/classes/Database/Routines.php
@@ -8,6 +8,7 @@ use PhpMyAdmin\Charsets;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
+use PhpMyAdmin\Query\Generator as QueryGenerator;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
@@ -18,7 +19,9 @@ use PhpMyAdmin\Util;
use function __;
use function _ngettext;
+use function array_column;
use function array_merge;
+use function array_multisort;
use function count;
use function explode;
use function htmlentities;
@@ -38,6 +41,7 @@ use function substr;
use function trim;
use const ENT_QUOTES;
+use const SORT_ASC;
/**
* Functions for routine management.
@@ -289,7 +293,7 @@ class Routines
exit;
}
- $routines = $this->dbi->getRoutines($db, $_POST['item_type'], $_POST['item_name']);
+ $routines = self::getDetails($this->dbi, $db, $_POST['item_type'], $_POST['item_name']);
$routine = $routines[0];
$this->response->addJSON(
'name',
@@ -1597,4 +1601,71 @@ class Routines
$this->response->addHTML($message->getDisplay());
}
+
+ /**
+ * returns details about the PROCEDUREs or FUNCTIONs for a specific database
+ * or details about a specific routine
+ *
+ * @param string $db db name
+ * @param string|null $which PROCEDURE | FUNCTION or null for both
+ * @param string $name name of the routine (to fetch a specific routine)
+ *
+ * @return array information about PROCEDUREs or FUNCTIONs
+ */
+ public static function getDetails(
+ DatabaseInterface $dbi,
+ string $db,
+ ?string $which = null,
+ string $name = ''
+ ): array {
+ if (! $GLOBALS['cfg']['Server']['DisableIS']) {
+ $query = QueryGenerator::getInformationSchemaRoutinesRequest(
+ $dbi->escapeString($db),
+ isset($which) && in_array($which, ['FUNCTION', 'PROCEDURE']) ? $which : null,
+ empty($name) ? null : $dbi->escapeString($name)
+ );
+ $routines = $dbi->fetchResult($query);
+ } else {
+ $routines = [];
+
+ if ($which === 'FUNCTION' || $which == null) {
+ $query = 'SHOW FUNCTION STATUS'
+ . " WHERE `Db` = '" . $dbi->escapeString($db) . "'";
+ if ($name) {
+ $query .= " AND `Name` = '"
+ . $dbi->escapeString($name) . "'";
+ }
+
+ $routines = $dbi->fetchResult($query);
+ }
+
+ if ($which === 'PROCEDURE' || $which == null) {
+ $query = 'SHOW PROCEDURE STATUS'
+ . " WHERE `Db` = '" . $dbi->escapeString($db) . "'";
+ if ($name) {
+ $query .= " AND `Name` = '"
+ . $dbi->escapeString($name) . "'";
+ }
+
+ $routines = array_merge($routines, $dbi->fetchResult($query));
+ }
+ }
+
+ $ret = [];
+ foreach ($routines as $routine) {
+ $ret[] = [
+ 'db' => $routine['Db'],
+ 'name' => $routine['Name'],
+ 'type' => $routine['Type'],
+ 'definer' => $routine['Definer'],
+ 'returns' => $routine['DTD_IDENTIFIER'] ?? '',
+ ];
+ }
+
+ // Sort results by name
+ $name = array_column($ret, 'name');
+ array_multisort($name, SORT_ASC, $ret);
+
+ return $ret;
+ }
}
diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php
index 9b40bb5040..a38e976a63 100644
--- a/libraries/classes/DatabaseInterface.php
+++ b/libraries/classes/DatabaseInterface.php
@@ -30,7 +30,6 @@ use function array_column;
use function array_diff;
use function array_keys;
use function array_map;
-use function array_merge;
use function array_multisort;
use function array_reverse;
use function array_shift;
@@ -41,7 +40,6 @@ use function count;
use function defined;
use function explode;
use function implode;
-use function in_array;
use function is_array;
use function is_int;
use function is_string;
@@ -1526,72 +1524,6 @@ class DatabaseInterface implements DbalInterface
}
/**
- * returns details about the PROCEDUREs or FUNCTIONs for a specific database
- * or details about a specific routine
- *
- * @param string $db db name
- * @param string|null $which PROCEDURE | FUNCTION or null for both
- * @param string $name name of the routine (to fetch a specific routine)
- *
- * @return array information about PROCEDUREs or FUNCTIONs
- */
- public function getRoutines(
- string $db,
- ?string $which = null,
- string $name = ''
- ): array {
- if (! $GLOBALS['cfg']['Server']['DisableIS']) {
- $query = QueryGenerator::getInformationSchemaRoutinesRequest(
- $this->escapeString($db),
- isset($which) && in_array($which, ['FUNCTION', 'PROCEDURE']) ? $which : null,
- empty($name) ? null : $this->escapeString($name)
- );
- $routines = $this->fetchResult($query);
- } else {
- $routines = [];
-
- if ($which === 'FUNCTION' || $which == null) {
- $query = 'SHOW FUNCTION STATUS'
- . " WHERE `Db` = '" . $this->escapeString($db) . "'";
- if ($name) {
- $query .= " AND `Name` = '"
- . $this->escapeString($name) . "'";
- }
-
- $routines = $this->fetchResult($query);
- }
-
- if ($which === 'PROCEDURE' || $which == null) {
- $query = 'SHOW PROCEDURE STATUS'
- . " WHERE `Db` = '" . $this->escapeString($db) . "'";
- if ($name) {
- $query .= " AND `Name` = '"
- . $this->escapeString($name) . "'";
- }
-
- $routines = array_merge($routines, $this->fetchResult($query));
- }
- }
-
- $ret = [];
- foreach ($routines as $routine) {
- $ret[] = [
- 'db' => $routine['Db'],
- 'name' => $routine['Name'],
- 'type' => $routine['Type'],
- 'definer' => $routine['Definer'],
- 'returns' => $routine['DTD_IDENTIFIER'] ?? '',
- ];
- }
-
- // Sort results by name
- $name = array_column($ret, 'name');
- array_multisort($name, SORT_ASC, $ret);
-
- return $ret;
- }
-
- /**
* returns details about the EVENTs for a specific database
*
* @param string $db db name
diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php
index d5722162c5..999f973c3d 100644
--- a/libraries/classes/Dbal/DbalInterface.php
+++ b/libraries/classes/Dbal/DbalInterface.php
@@ -462,18 +462,6 @@ interface DbalInterface
): ?string;
/**
- * returns details about the PROCEDUREs or FUNCTIONs for a specific database
- * or details about a specific routine
- *
- * @param string $db db name
- * @param string|null $which PROCEDURE | FUNCTION or null for both
- * @param string $name name of the routine (to fetch a specific routine)
- *
- * @return array information about ROCEDUREs or FUNCTIONs
- */
- public function getRoutines(string $db, ?string $which = null, string $name = ''): array;
-
- /**
* returns details about the EVENTs for a specific database
*
* @param string $db db name
diff --git a/libraries/classes/Server/Privileges.php b/libraries/classes/Server/Privileges.php
index 27198284f6..5bec85a267 100644
--- a/libraries/classes/Server/Privileges.php
+++ b/libraries/classes/Server/Privileges.php
@@ -11,6 +11,7 @@ use mysqli_stmt;
use PhpMyAdmin\ConfigStorage\Features\ConfigurableMenusFeature;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
+use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\MysqliResult;
use PhpMyAdmin\Dbal\ResultInterface;
@@ -1966,7 +1967,7 @@ class Privileges
$data['tables'] = $tables;
} else { // routine
- $routineData = $this->dbi->getRoutines($dbname);
+ $routineData = Routines::getDetails($this->dbi, $dbname);
$routines = [];
foreach ($routineData as $routine) {
@@ -3660,7 +3661,7 @@ class Privileges
*/
public function getRoutineType(string $dbname, string $routineName)
{
- $routineData = $this->dbi->getRoutines($dbname);
+ $routineData = Routines::getDetails($this->dbi, $dbname);
$routineName = mb_strtolower($routineName);
foreach ($routineData as $routine) {