diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-10 18:48:44 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-10 18:48:44 +0300 |
commit | d760df02ddbafa85ebba4149969aed5f2d6af02f (patch) | |
tree | 9e86997094a5c657415c59eefa0667d994954450 | |
parent | 81192a142bbfde4f0795a6496c62ffc58dec5700 (diff) |
Move DBI getEvents method into the Events class
DatabaseInterface::getEvents -> Database\Events::getDetails
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | libraries/classes/Controllers/Database/EventsController.php | 2 | ||||
-rw-r--r-- | libraries/classes/Database/Events.php | 48 | ||||
-rw-r--r-- | libraries/classes/DatabaseInterface.php | 41 | ||||
-rw-r--r-- | libraries/classes/Dbal/DbalInterface.php | 10 | ||||
-rw-r--r-- | phpstan-baseline.neon | 15 | ||||
-rw-r--r-- | psalm-baseline.xml | 16 |
6 files changed, 61 insertions, 71 deletions
diff --git a/libraries/classes/Controllers/Database/EventsController.php b/libraries/classes/Controllers/Database/EventsController.php index a72b034a46..b0d6c70632 100644 --- a/libraries/classes/Controllers/Database/EventsController.php +++ b/libraries/classes/Controllers/Database/EventsController.php @@ -81,7 +81,7 @@ final class EventsController extends AbstractController $this->events->handleEditor(); $this->events->export(); - $items = $this->dbi->getEvents($GLOBALS['db']); + $items = $this->events->getDetails($GLOBALS['db']); $this->render('database/events/index', [ 'db' => $GLOBALS['db'], diff --git a/libraries/classes/Database/Events.php b/libraries/classes/Database/Events.php index 2a2f532845..1a2196d8f6 100644 --- a/libraries/classes/Database/Events.php +++ b/libraries/classes/Database/Events.php @@ -7,11 +7,14 @@ namespace PhpMyAdmin\Database; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Message; +use PhpMyAdmin\Query\Generator as QueryGenerator; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; use PhpMyAdmin\Util; use function __; +use function array_column; +use function array_multisort; use function count; use function explode; use function htmlspecialchars; @@ -23,6 +26,8 @@ use function str_contains; use function strtoupper; use function trim; +use const SORT_ASC; + /** * Functions for event management. */ @@ -174,7 +179,7 @@ class Events if ($this->response->isAjax()) { if ($GLOBALS['message']->isSuccess()) { - $events = $this->dbi->getEvents($GLOBALS['db'], $_POST['item_name']); + $events = $this->getDetails($GLOBALS['db'], $_POST['item_name']); $event = $events[0]; $this->response->addJSON( 'name', @@ -596,4 +601,45 @@ class Events $this->response->addHTML($message->getDisplay()); } + + /** + * Returns details about the EVENTs for a specific database. + * + * @param string $db db name + * @param string $name event name + * + * @return array information about EVENTs + */ + public function getDetails(string $db, string $name = ''): array + { + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + $query = QueryGenerator::getInformationSchemaEventsRequest( + $this->dbi->escapeString($db), + empty($name) ? null : $this->dbi->escapeString($name) + ); + } else { + $query = 'SHOW EVENTS FROM ' . Util::backquote($db); + if ($name) { + $query .= " WHERE `Name` = '" + . $this->dbi->escapeString($name) . "'"; + } + } + + $result = []; + $events = $this->dbi->fetchResult($query); + + foreach ($events as $event) { + $result[] = [ + 'name' => $event['Name'], + 'type' => $event['Type'], + 'status' => $event['Status'], + ]; + } + + // Sort results by name + $name = array_column($result, 'name'); + array_multisort($name, SORT_ASC, $result); + + return $result; + } } diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index a38e976a63..01ee453f23 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -1524,47 +1524,6 @@ class DatabaseInterface implements DbalInterface } /** - * returns details about the EVENTs for a specific database - * - * @param string $db db name - * @param string $name event name - * - * @return array information about EVENTs - */ - public function getEvents(string $db, string $name = ''): array - { - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - $query = QueryGenerator::getInformationSchemaEventsRequest( - $this->escapeString($db), - empty($name) ? null : $this->escapeString($name) - ); - } else { - $query = 'SHOW EVENTS FROM ' . Util::backquote($db); - if ($name) { - $query .= " WHERE `Name` = '" - . $this->escapeString($name) . "'"; - } - } - - $result = []; - $events = $this->fetchResult($query); - - foreach ($events as $event) { - $result[] = [ - 'name' => $event['Name'], - 'type' => $event['Type'], - 'status' => $event['Status'], - ]; - } - - // Sort results by name - $name = array_column($result, 'name'); - array_multisort($name, SORT_ASC, $result); - - return $result; - } - - /** * returns details about the TRIGGERs for a specific table or database * * @param string $db db name diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index 999f973c3d..0d8ff5c266 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -462,16 +462,6 @@ interface DbalInterface ): ?string; /** - * returns details about the EVENTs for a specific database - * - * @param string $db db name - * @param string $name event name - * - * @return array information about EVENTs - */ - public function getEvents(string $db, string $name = ''): array; - - /** * returns details about the TRIGGERs for a specific table or database * * @param string $db db name diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a0ccaabc90..316db55f15 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1966,6 +1966,11 @@ parameters: path: libraries/classes/Database/Events.php - + message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getDetails\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: libraries/classes/Database/Events.php + + - message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:getEditorForm\\(\\) has parameter \\$item with no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Database/Events.php @@ -2536,11 +2541,6 @@ parameters: path: libraries/classes/DatabaseInterface.php - - message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/DatabaseInterface.php - - - message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/DatabaseInterface.php @@ -2681,11 +2681,6 @@ parameters: path: libraries/classes/Dbal/DbalInterface.php - - message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getEvents\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: libraries/classes/Dbal/DbalInterface.php - - - message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getProceduresOrFunctions\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: libraries/classes/Dbal/DbalInterface.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 15db3f42fc..10d7af7486 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4908,7 +4908,10 @@ <code>$event['name']</code> <code>$itemName</code> </MixedArgument> - <MixedArrayAccess occurrences="1"> + <MixedArrayAccess occurrences="4"> + <code>$event['Name']</code> + <code>$event['Status']</code> + <code>$event['Type']</code> <code>$event['name']</code> </MixedArrayAccess> <MixedArrayAssignment occurrences="9"> @@ -4922,10 +4925,11 @@ <code>$GLOBALS['errors'][]</code> <code>$GLOBALS['errors'][]</code> </MixedArrayAssignment> - <MixedAssignment occurrences="18"> + <MixedAssignment occurrences="19"> <code>$GLOBALS['errors']</code> <code>$GLOBALS['errors']</code> <code>$event</code> + <code>$event</code> <code>$itemName</code> <code>$item['item_original_name']</code> <code>$retval[$index]</code> @@ -5630,10 +5634,7 @@ <code>uksort($eachTables, 'strnatcasecmp')</code> <code>usort($tables, 'strnatcasecmp')</code> </MixedArgumentTypeCoercion> - <MixedArrayAccess occurrences="28"> - <code>$event['Name']</code> - <code>$event['Status']</code> - <code>$event['Type']</code> + <MixedArrayAccess occurrences="25"> <code>$link</code> <code>$oneShow['Db']</code> <code>$oneShow['Name']</code> @@ -5680,13 +5681,12 @@ <code>$this->links[$link]</code> <code>$this->links[$link]</code> </MixedArrayOffset> - <MixedAssignment occurrences="35"> + <MixedAssignment occurrences="34"> <code>$aLength</code> <code>$bLength</code> <code>$database</code> <code>$databaseName</code> <code>$databases[$databaseName]['SCHEMA_NAME']</code> - <code>$event</code> <code>$grant</code> <code>$grant</code> <code>$keyIndex</code> |