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:
-rw-r--r--libraries/classes/Database/Events.php15
-rw-r--r--libraries/classes/Database/Routines.php44
-rw-r--r--libraries/classes/DatabaseInterface.php30
-rw-r--r--libraries/classes/Dbal/DbalInterface.php17
-rw-r--r--libraries/classes/Operations.php8
-rw-r--r--libraries/classes/Plugins/Export/ExportSql.php8
-rw-r--r--libraries/classes/Plugins/Export/ExportXml.php8
-rw-r--r--phpstan-baseline.neon5
-rw-r--r--psalm-baseline.xml7
-rw-r--r--test/classes/Plugins/Export/ExportSqlTest.php26
-rw-r--r--test/classes/Plugins/Export/ExportXmlTest.php2
11 files changed, 81 insertions, 89 deletions
diff --git a/libraries/classes/Database/Events.php b/libraries/classes/Database/Events.php
index 1a2196d8f6..496024b4d0 100644
--- a/libraries/classes/Database/Events.php
+++ b/libraries/classes/Database/Events.php
@@ -20,6 +20,7 @@ use function explode;
use function htmlspecialchars;
use function in_array;
use function intval;
+use function is_string;
use function mb_strtoupper;
use function sprintf;
use function str_contains;
@@ -100,7 +101,7 @@ class Events
// Execute the created query
if (! empty($_POST['editor_process_edit'])) {
// Backup the old trigger, in case something goes wrong
- $create_item = $this->dbi->getDefinition($GLOBALS['db'], 'EVENT', $_POST['item_original_name']);
+ $create_item = self::getDefinition($this->dbi, $GLOBALS['db'], $_POST['item_original_name']);
$drop_item = 'DROP EVENT IF EXISTS '
. Util::backquote($_POST['item_original_name'])
. ";\n";
@@ -556,7 +557,7 @@ class Events
}
$itemName = $_GET['item_name'];
- $exportData = $this->dbi->getDefinition($GLOBALS['db'], 'EVENT', $itemName);
+ $exportData = self::getDefinition($this->dbi, $GLOBALS['db'], $itemName);
if (! $exportData) {
$exportData = false;
@@ -642,4 +643,14 @@ class Events
return $result;
}
+
+ public static function getDefinition(DatabaseInterface $dbi, string $db, string $name): ?string
+ {
+ $result = $dbi->fetchValue(
+ 'SHOW CREATE EVENT ' . Util::backquote($db) . '.' . Util::backquote($name),
+ 'Create Event'
+ );
+
+ return is_string($result) ? $result : null;
+ }
}
diff --git a/libraries/classes/Database/Routines.php b/libraries/classes/Database/Routines.php
index 2f471d73cd..a8e9a0860a 100644
--- a/libraries/classes/Database/Routines.php
+++ b/libraries/classes/Database/Routines.php
@@ -204,9 +204,9 @@ class Routines
} else {
// Backup the old routine, in case something goes wrong
if ($_POST['item_original_type'] === 'FUNCTION') {
- $create_routine = $this->dbi->getDefinition($db, 'FUNCTION', $_POST['item_original_name']);
+ $create_routine = self::getFunctionDefinition($this->dbi, $db, $_POST['item_original_name']);
} else {
- $create_routine = $this->dbi->getDefinition($db, 'PROCEDURE', $_POST['item_original_name']);
+ $create_routine = self::getProcedureDefinition($this->dbi, $db, $_POST['item_original_name']);
}
$privilegesBackup = $this->backupPrivileges();
@@ -575,7 +575,11 @@ class Routines
$retval['item_name'] = $routine['SPECIFIC_NAME'];
$retval['item_type'] = $routine['ROUTINE_TYPE'];
- $definition = $this->dbi->getDefinition($GLOBALS['db'], $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME']);
+ if ($routine['ROUTINE_TYPE'] === 'FUNCTION') {
+ $definition = self::getFunctionDefinition($this->dbi, $GLOBALS['db'], $routine['SPECIFIC_NAME']);
+ } else {
+ $definition = self::getProcedureDefinition($this->dbi, $GLOBALS['db'], $routine['SPECIFIC_NAME']);
+ }
if ($definition === null) {
return null;
@@ -1474,7 +1478,12 @@ class Routines
// we will show a dialog to get values for these parameters,
// otherwise we can execute it directly.
- $definition = $this->dbi->getDefinition($GLOBALS['db'], $routine['type'], $routine['name']);
+ if ($routine['type'] === 'FUNCTION') {
+ $definition = self::getFunctionDefinition($this->dbi, $GLOBALS['db'], $routine['name']);
+ } else {
+ $definition = self::getProcedureDefinition($this->dbi, $GLOBALS['db'], $routine['name']);
+ }
+
$executeAction = '';
if ($definition !== null) {
@@ -1540,11 +1549,14 @@ class Routines
return;
}
- if ($_GET['item_type'] !== 'FUNCTION' && $_GET['item_type'] !== 'PROCEDURE') {
+ if ($_GET['item_type'] === 'FUNCTION') {
+ $routineDefinition = self::getFunctionDefinition($this->dbi, $GLOBALS['db'], $_GET['item_name']);
+ } elseif ($_GET['item_type'] === 'PROCEDURE') {
+ $routineDefinition = self::getProcedureDefinition($this->dbi, $GLOBALS['db'], $_GET['item_name']);
+ } else {
return;
}
- $routineDefinition = $this->dbi->getDefinition($GLOBALS['db'], $_GET['item_type'], $_GET['item_name']);
$exportData = false;
if ($routineDefinition !== null) {
@@ -1660,4 +1672,24 @@ class Routines
return $ret;
}
+
+ public static function getFunctionDefinition(DatabaseInterface $dbi, string $db, string $name): ?string
+ {
+ $result = $dbi->fetchValue(
+ 'SHOW CREATE FUNCTION ' . Util::backquote($db) . '.' . Util::backquote($name),
+ 'Create Function'
+ );
+
+ return is_string($result) ? $result : null;
+ }
+
+ public static function getProcedureDefinition(DatabaseInterface $dbi, string $db, string $name): ?string
+ {
+ $result = $dbi->fetchValue(
+ 'SHOW CREATE PROCEDURE ' . Util::backquote($db) . '.' . Util::backquote($name),
+ 'Create Procedure'
+ );
+
+ return is_string($result) ? $result : null;
+ }
}
diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php
index f2bccb3eb4..1f7454513d 100644
--- a/libraries/classes/DatabaseInterface.php
+++ b/libraries/classes/DatabaseInterface.php
@@ -1493,36 +1493,6 @@ class DatabaseInterface implements DbalInterface
}
/**
- * returns the definition of a specific PROCEDURE, FUNCTION, EVENT or VIEW
- *
- * @param string $db db name
- * @param string $which PROCEDURE | FUNCTION | EVENT | VIEW
- * @param string $name the procedure|function|event|view name
- * @param int $link link type
- *
- * @return string|null the definition
- */
- public function getDefinition(
- string $db,
- string $which,
- string $name,
- $link = self::CONNECT_USER
- ): ?string {
- $returnedField = [
- 'PROCEDURE' => 'Create Procedure',
- 'FUNCTION' => 'Create Function',
- 'EVENT' => 'Create Event',
- 'VIEW' => 'Create View',
- ];
- $query = 'SHOW CREATE ' . $which . ' '
- . Util::backquote($db) . '.'
- . Util::backquote($name);
- $result = $this->fetchValue($query, $returnedField[$which], $link);
-
- return is_string($result) ? $result : null;
- }
-
- /**
* gets the current user with host
*
* @return string the current user i.e. user@host
diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php
index 8b54935871..bf073afe9a 100644
--- a/libraries/classes/Dbal/DbalInterface.php
+++ b/libraries/classes/Dbal/DbalInterface.php
@@ -445,23 +445,6 @@ interface DbalInterface
): array;
/**
- * returns the definition of a specific PROCEDURE, FUNCTION, EVENT or VIEW
- *
- * @param string $db db name
- * @param string $which PROCEDURE | FUNCTION | EVENT | VIEW
- * @param string $name the procedure|function|event|view name
- * @param int $link link type
- *
- * @return string|null the definition
- */
- public function getDefinition(
- string $db,
- string $which,
- string $name,
- $link = DatabaseInterface::CONNECT_USER
- ): ?string;
-
- /**
* gets the current user with host
*
* @return string the current user i.e. user@host
diff --git a/libraries/classes/Operations.php b/libraries/classes/Operations.php
index a437aaf17a..3e88d03c7d 100644
--- a/libraries/classes/Operations.php
+++ b/libraries/classes/Operations.php
@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\ConfigStorage\Relation;
+use PhpMyAdmin\Database\Events;
+use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\Engines\Innodb;
use PhpMyAdmin\Partitioning\Partition;
@@ -59,7 +61,7 @@ class Operations
if ($procedure_names) {
foreach ($procedure_names as $procedure_name) {
$this->dbi->selectDb($db);
- $tmp_query = $this->dbi->getDefinition($db, 'PROCEDURE', $procedure_name);
+ $tmp_query = Routines::getProcedureDefinition($this->dbi, $db, $procedure_name);
if ($tmp_query === null) {
continue;
}
@@ -78,7 +80,7 @@ class Operations
foreach ($function_names as $function_name) {
$this->dbi->selectDb($db);
- $tmp_query = $this->dbi->getDefinition($db, 'FUNCTION', $function_name);
+ $tmp_query = Routines::getFunctionDefinition($this->dbi, $db, $function_name);
if ($tmp_query === null) {
continue;
}
@@ -266,7 +268,7 @@ class Operations
foreach ($event_names as $event_name) {
$this->dbi->selectDb($db);
- $tmp_query = $this->dbi->getDefinition($db, 'EVENT', $event_name);
+ $tmp_query = Events::getDefinition($this->dbi, $db, $event_name);
// collect for later display
$GLOBALS['sql_query'] .= "\n" . $tmp_query;
$this->dbi->selectDb($_POST['newname']);
diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php
index ca4e9413c2..0a48ed46d0 100644
--- a/libraries/classes/Plugins/Export/ExportSql.php
+++ b/libraries/classes/Plugins/Export/ExportSql.php
@@ -8,6 +8,8 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
use PhpMyAdmin\Charsets;
+use PhpMyAdmin\Database\Events;
+use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\FieldMetadata;
@@ -556,9 +558,9 @@ class ExportSql extends ExportPlugin
}
if ($type === 'FUNCTION') {
- $definition = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $routine);
+ $definition = Routines::getFunctionDefinition($GLOBALS['dbi'], $db, $routine);
} else {
- $definition = $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $routine);
+ $definition = Routines::getProcedureDefinition($GLOBALS['dbi'], $db, $routine);
}
$createQuery = $this->replaceWithAliases($definition, $aliases, $db, '', $flag);
@@ -1012,7 +1014,7 @@ class ExportSql extends ExportPlugin
. $delimiter . $GLOBALS['crlf'];
}
- $eventDef = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $eventName);
+ $eventDef = Events::getDefinition($GLOBALS['dbi'], $db, $eventName);
if (! empty($eventDef) && $GLOBALS['cfg']['Export']['remove_definer_from_definitions']) {
// remove definer clause from the event definition
$parser = new Parser($eventDef);
diff --git a/libraries/classes/Plugins/Export/ExportXml.php b/libraries/classes/Plugins/Export/ExportXml.php
index 349fe0abc2..f31ecd496b 100644
--- a/libraries/classes/Plugins/Export/ExportXml.php
+++ b/libraries/classes/Plugins/Export/ExportXml.php
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins\Export;
+use PhpMyAdmin\Database\Events;
+use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\Database\Triggers;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Plugins\ExportPlugin;
@@ -167,11 +169,11 @@ class ExportXml extends ExportPlugin
$head .= ' <pma:' . $type . ' name="' . htmlspecialchars($name) . '">' . $GLOBALS['crlf'];
if ($type === 'function') {
- $definition = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $name);
+ $definition = Routines::getFunctionDefinition($GLOBALS['dbi'], $db, $name);
} elseif ($type === 'procedure') {
- $definition = $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $name);
+ $definition = Routines::getProcedureDefinition($GLOBALS['dbi'], $db, $name);
} else {
- $definition = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $name);
+ $definition = Events::getDefinition($GLOBALS['dbi'], $db, $name);
}
// Do some formatting
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index aae588b43b..2ce6efc17c 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -5421,6 +5421,11 @@ parameters:
path: libraries/classes/Plugins/Export/ExportSql.php
-
+ message: "#^Parameter \\#1 \\$sqlQuery of method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:replaceWithAliases\\(\\) expects string, string\\|null given\\.$#"
+ count: 1
+ path: libraries/classes/Plugins/Export/ExportSql.php
+
+ -
message: "#^Parameter \\#1 \\$str of function strtoupper expects string, mixed given\\.$#"
count: 1
path: libraries/classes/Plugins/Export/ExportSql.php
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 0c12ad7c34..d6182431d5 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -5175,7 +5175,7 @@
</RedundantPropertyInitializationCheck>
</file>
<file src="libraries/classes/Database/Routines.php">
- <MixedArgument occurrences="70">
+ <MixedArgument occurrences="71">
<code>$GLOBALS['errors']</code>
<code>$_GET['item_name']</code>
<code>$_GET['item_name']</code>
@@ -5183,6 +5183,7 @@
<code>$_GET['item_name']</code>
<code>$_GET['item_name']</code>
<code>$_GET['item_name']</code>
+ <code>$_GET['item_name']</code>
<code>$_GET['item_type']</code>
<code>$_GET['item_type']</code>
<code>$_POST['item_comment']</code>
@@ -5217,7 +5218,7 @@
<code>$itemType</code>
<code>$newErrors</code>
<code>$routine</code>
- <code>$routine['ROUTINE_TYPE']</code>
+ <code>$routine['SPECIFIC_NAME']</code>
<code>$routine['SPECIFIC_NAME']</code>
<code>$routine['item_name']</code>
<code>$routine['item_name']</code>
@@ -5237,7 +5238,7 @@
<code>$routine['name']</code>
<code>$routine['name']</code>
<code>$routine['name']</code>
- <code>$routine['type']</code>
+ <code>$routine['name']</code>
<code>$routine['type']</code>
<code>$routine['type']</code>
<code>$value</code>
diff --git a/test/classes/Plugins/Export/ExportSqlTest.php b/test/classes/Plugins/Export/ExportSqlTest.php
index c907de040b..eec8ac7e9f 100644
--- a/test/classes/Plugins/Export/ExportSqlTest.php
+++ b/test/classes/Plugins/Export/ExportSqlTest.php
@@ -581,27 +581,11 @@ class ExportSqlTest extends AbstractTestCase
->will($this->returnValue(['f1', 'f2']));
$dbi->expects($this->exactly(2))
- ->method('getDefinition')
- ->will(
- $this->returnValueMap(
- [
- [
- 'db',
- 'EVENT',
- 'f1',
- DatabaseInterface::CONNECT_USER,
- 'f1event',
- ],
- [
- 'db',
- 'EVENT',
- 'f2',
- DatabaseInterface::CONNECT_USER,
- 'f2event',
- ],
- ]
- )
- );
+ ->method('fetchValue')
+ ->will($this->returnValueMap([
+ ['SHOW CREATE EVENT `db`.`f1`', 'Create Event', DatabaseInterface::CONNECT_USER, 'f1event'],
+ ['SHOW CREATE EVENT `db`.`f2`', 'Create Event', DatabaseInterface::CONNECT_USER, 'f2event'],
+ ]));
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
diff --git a/test/classes/Plugins/Export/ExportXmlTest.php b/test/classes/Plugins/Export/ExportXmlTest.php
index 1920c9d32e..a2bff35a19 100644
--- a/test/classes/Plugins/Export/ExportXmlTest.php
+++ b/test/classes/Plugins/Export/ExportXmlTest.php
@@ -228,7 +228,7 @@ class ExportXmlTest extends AbstractTestCase
);
$dbi->expects($this->exactly(2))
- ->method('getDefinition')
+ ->method('fetchValue')
->willReturnOnConsecutiveCalls('fndef', 'prdef');
$dbi->expects($this->once())