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 /libraries/classes | |
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>
Diffstat (limited to 'libraries/classes')
-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 |
4 files changed, 48 insertions, 53 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 |